Defalt-404 commited on
Commit
ee5d33c
1 Parent(s): 74c3332

Add application file

Browse files
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, abort, session
2
+ import csv
3
+ import io
4
+ import requests
5
+ import os
6
+ import tempfile
7
+
8
+ def get_secrets(file):
9
+ file_path = f'/run/secrets/{file}'
10
+
11
+ try:
12
+ with open(file_path, 'r') as file:
13
+ secret_example = file.read()
14
+ print('The content of SECRET_EXAMPLE is:', secret_example)
15
+ return secret_example
16
+ except FileNotFoundError:
17
+ print('File not found:', file_path)
18
+ except PermissionError:
19
+ print('Permission denied. Make sure you have the necessary permissions to read the file.')
20
+
21
+
22
+ app = Flask(__name__)
23
+ app.config['SESSION_COOKIE_SECURE'] = True # Requires HTTPS
24
+ app.config['SESSION_COOKIE_SAMESITE'] = 'None'
25
+ app.secret_key = get_secrets('secret_key')
26
+
27
+
28
+ # Function to apply transformation to specific columns
29
+ def apply_transformation(row):
30
+ transformed_row = []
31
+ for i, cell in enumerate(row):
32
+ if 1 <= i <= 8: # Columns 1 to 8 (0-based index) transformation
33
+ try:
34
+ transformed_value = "{:.3f}".format(float(cell))
35
+ except ValueError:
36
+ transformed_value = cell # Keep non-numeric values unchanged
37
+ transformed_row.append(transformed_value)
38
+ else:
39
+ transformed_row.append(cell) # Keep other columns unchanged
40
+ return transformed_row
41
+
42
+
43
+ @app.errorhandler(404)
44
+ def page_not_found(error):
45
+ return render_template('404.html'), 404
46
+
47
+
48
+
49
+ # Route to display transformed CSV as a table
50
+ @app.route('/')
51
+ def display_transformed_csv():
52
+ access_token = get_secrets('GH_token')
53
+ benchmark_file_texteval = 'Miner_Benchmark.csv'
54
+ benchmark_file_agieval = 'miner_benchmark_AGIEval.csv'
55
+ benchmark_file = ''
56
+ active_tab = request.args.get('tab', default='TextEval')
57
+
58
+ if active_tab == 'TextEval':
59
+ benchmark_file = benchmark_file_texteval
60
+ elif active_tab == 'AGIEval':
61
+ benchmark_file = benchmark_file_agieval
62
+ else:
63
+ abort(404)
64
+
65
+
66
+ print(session)
67
+ resp_404_flag = 1
68
+
69
+ if resp_404_flag:
70
+ GH_url = f"https://raw.githubusercontent.com/Kunj-2206/NIValidatorEndpoint/main/benchmark_files/{benchmark_file}?token=GHSAT0AAAAAACAPTSUR7YFNWFNDGFCFQRSCZIHVYMA"
71
+ response = requests.get(GH_url, headers={'Authorization': f'Bearer {access_token}'})
72
+ if response.status_code is [200, 201, 202, 204]:
73
+ resp_404_flag = 0
74
+
75
+ # Create a temporary file to store the CSV content
76
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
77
+ temp_file.write(response.content)
78
+ csv_path = temp_file.name
79
+
80
+ session[active_tab] = csv_path
81
+
82
+ # Retrieve the CSV content from the session
83
+ csv_path = session[active_tab]
84
+
85
+
86
+ #print(csv_content)
87
+ try:
88
+ with open(csv_path, 'r') as csv_file:
89
+ csv_reader = csv.reader(csv_file)
90
+ header_row = next(csv_reader)
91
+ #print(header_row)
92
+ data = [apply_transformation(row) for row in csv_reader]
93
+ return render_template('table.html', data=data, header_row=header_row, active_tab=active_tab)
94
+ except FileNotFoundError:
95
+ return "CSV file not found."
96
+
97
+ if __name__ == '__main__':
98
+
99
+ app.run(debug=True, host='0.0.0.0', port=7860)
100
+
gunicorn_config.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import multiprocessing
2
+
3
+ # Gunicorn config variables
4
+ bind = "0.0.0.0:7860" # Replace with your desired host and port
5
+ workers = multiprocessing.cpu_count() * 2 + 1
6
+ threads = 2 * multiprocessing.cpu_count()
7
+ timeout = 3600
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ blinker==1.6.2
2
+ certifi==2023.7.22
3
+ charset-normalizer==3.2.0
4
+ click==8.1.7
5
+ Flask==2.3.3
6
+ idna==3.4
7
+ itsdangerous==2.1.2
8
+ Jinja2==3.1.2
9
+ MarkupSafe==2.1.3
10
+ numpy==1.26.0
11
+ python-dateutil==2.8.2
12
+ pytz==2023.3.post1
13
+ requests==2.31.0
14
+ six==1.16.0
15
+ tzdata==2023.3
16
+ urllib3==2.0.4
17
+ Werkzeug==2.3.7
static/css/styles.css ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial, Helvetica, sans-serif;
3
+ background-color: #f2f2f2;
4
+ padding: 20px;
5
+ }
6
+
7
+ .container {
8
+ background-color: white;
9
+ padding: 20px;
10
+ border-radius: 10px;
11
+ box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
12
+ }
13
+
14
+ h2 {
15
+ margin-top: 0;
16
+ }
17
+
18
+ table {
19
+ width: 100%;
20
+ border-collapse: collapse;
21
+ max-height: 200px; /* Set a max height for vertical scrolling */
22
+ }
23
+
24
+ table.dataTable {
25
+ margin-top: 0;
26
+ margin-bottom: 0;
27
+ }
28
+
29
+ th, td {
30
+ padding: 10px;
31
+ text-align: left;
32
+ }
33
+
34
+ th {
35
+ background-color: #f2f2f2;
36
+ }
37
+
38
+ .title {
39
+ text-align: center;
40
+ font-size: 24px;
41
+ margin-bottom: 20px;
42
+ }
43
+
44
+ /* Style for the navigation bar */
45
+ .nav-tabs {
46
+ background-color: #f2f2f2;
47
+ border-radius: 10px 10px 0 0;
48
+ padding-left: 51px;
49
+ padding-bottom: 5px;
50
+ }
51
+
52
+ .nav-item {
53
+ margin-right: 5px;
54
+ }
55
+
56
+ .nav-link {
57
+ color: #333;
58
+ background-color: #f2f2f2;
59
+ border: none;
60
+ border-radius: 0;
61
+ }
62
+
63
+ .nav-link.active {
64
+ background-color: #fff;
65
+ border: 1px solid #ccc;
66
+ border-bottom-color: transparent;
67
+ border-radius: 10px 10px 0 0;
68
+ }
static/js/script.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ // script.js
2
+
3
+ $(document).ready(function() {
4
+ $('#csvDataTable').DataTable({order: [[9, 'desc']]});
5
+ });
templates/404.html ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>404 - Page Not Found</title>
7
+ <style>
8
+ body {
9
+ background-color: #f1f1f1;
10
+ font-family: Arial, sans-serif;
11
+ text-align: center;
12
+ padding: 20px;
13
+ }
14
+
15
+ .container {
16
+ background-color: #fff;
17
+ border-radius: 8px;
18
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
19
+ padding: 20px;
20
+ max-width: 600px;
21
+ margin: 0 auto;
22
+ }
23
+
24
+ h1 {
25
+ font-size: 48px;
26
+ color: #333;
27
+ }
28
+
29
+ p {
30
+ font-size: 18px;
31
+ color: #777;
32
+ }
33
+
34
+ a {
35
+ text-decoration: none;
36
+ color: #007bff;
37
+ font-weight: bold;
38
+ }
39
+
40
+ a:hover {
41
+ text-decoration: underline;
42
+ }
43
+ </style>
44
+ </head>
45
+ <body>
46
+ <div class="container">
47
+ <h1>404 - Page Not Found</h1>
48
+ <p>The requested page could not be found.</p>
49
+ <p>Return to <a href="/">Homepage</a></p>
50
+ </div>
51
+ </body>
52
+ </html>
templates/table.html ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>CSV Data Table</title>
5
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
6
+ <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.css" /> <!-- Updated DataTables CDN CSS -->
7
+ <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
8
+
9
+ </head>
10
+ <body>
11
+ <h2 class="title">Benchmark Data Table - {% if active_tab == 'TextEval' %}TextEval{% else %}AGIEval{% endif %}</h2>
12
+ <ul class="nav nav-tabs">
13
+ <li class="nav-item">
14
+ <a class="nav-link {% if active_tab == 'TextEval' %}active{% endif %}" data-toggle="tab" href="?tab=TextEval">TextEval</a>
15
+ </li>
16
+ <li class="nav-item">
17
+ <a class="nav-link {% if active_tab == 'AGIEval' %}active{% endif %}" data-toggle="tab" href="?tab=AGIEval">AGIEval</a>
18
+ </li>
19
+ </ul>
20
+
21
+ <div id="demo_info" class="container">
22
+ <table class="table table-bordered table-hover" id="csvDataTable">
23
+ <thead class="thead-dark">
24
+ <tr>
25
+ {% for header in header_row %}
26
+ <th>{{ header }}</th>
27
+ {% endfor %}
28
+ </tr>
29
+ </thead>
30
+ <tbody>
31
+ {% for row in data %}
32
+ <tr>
33
+ {% for cell in row %}
34
+ <td>{{ cell }}</td>
35
+ {% endfor %}
36
+ </tr>
37
+ {% endfor %}
38
+ </tbody>
39
+ </table>
40
+ </div>
41
+
42
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
43
+ <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.js"></script> <!-- Updated DataTables CDN JavaScript -->
44
+ <script src="{{ url_for('static', filename='js/script.js') }}"></script>
45
+ </body>
46
+ </html>