Upload folder using huggingface_hub
Browse files- __pycache__/request_api.cpython-38.pyc +0 -0
- gradio_app.py +19 -10
- request_api.py +32 -4
__pycache__/request_api.cpython-38.pyc
CHANGED
Binary files a/__pycache__/request_api.cpython-38.pyc and b/__pycache__/request_api.cpython-38.pyc differ
|
|
gradio_app.py
CHANGED
@@ -7,6 +7,8 @@ from datetime import datetime, timezone
|
|
7 |
from pathlib import Path
|
8 |
from request_api import make_get_request, make_post_request
|
9 |
from io import BytesIO, StringIO
|
|
|
|
|
10 |
LEADERBOARD_PATH = "/home/Bhattacharya/ism_leaderboard/files/leaderboard"
|
11 |
# Directory where request by models are stored
|
12 |
DIR_OUTPUT_REQUESTS = Path("requested_models")
|
@@ -55,16 +57,17 @@ def create_html_page(title, content):
|
|
55 |
|
56 |
return html_page
|
57 |
|
58 |
-
def fetch_leaderboard(phase=1):
|
59 |
|
60 |
"""
|
61 |
Fetch the leaderboard from the local disk
|
62 |
"""
|
63 |
params = {"phase": phase}
|
64 |
|
65 |
-
leaderboard_df = make_get_request("fetch-leaderboard", params)
|
|
|
66 |
csv_data = leaderboard_df.content.decode('utf-8')
|
67 |
-
|
68 |
#print(csv_data)
|
69 |
|
70 |
# create dataframe from csv data
|
@@ -142,6 +145,10 @@ def formatter(x):
|
|
142 |
def format_leaderboard(df,sort_by="F1 Score"):
|
143 |
# Formats the columns
|
144 |
|
|
|
|
|
|
|
|
|
145 |
for col in df.columns:
|
146 |
if col == "Team Name":
|
147 |
# do nothing
|
@@ -157,11 +164,13 @@ def format_leaderboard(df,sort_by="F1 Score"):
|
|
157 |
df.sort_values(by=sort_by, inplace=True, ascending=False)
|
158 |
return df
|
159 |
|
|
|
160 |
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
165 |
#leaderboard_df_1 = None
|
166 |
#leaderboard_df_2 = None
|
167 |
|
@@ -173,8 +182,8 @@ with gr.Blocks() as demo:
|
|
173 |
leaderboard_table_2 = None
|
174 |
|
175 |
def button_clicked_phase_1(inputs):
|
176 |
-
|
177 |
-
leaderboard_df_1 = format_leaderboard(
|
178 |
|
179 |
|
180 |
leaderboard_table_1 = gr.components.Dataframe(
|
@@ -191,8 +200,8 @@ with gr.Blocks() as demo:
|
|
191 |
|
192 |
|
193 |
def button_clicked_phase_2():
|
194 |
-
|
195 |
-
leaderboard_df_2 = format_leaderboard(
|
196 |
|
197 |
|
198 |
leaderboard_table_2 = gr.components.Dataframe(
|
|
|
7 |
from pathlib import Path
|
8 |
from request_api import make_get_request, make_post_request
|
9 |
from io import BytesIO, StringIO
|
10 |
+
import asyncio
|
11 |
+
|
12 |
LEADERBOARD_PATH = "/home/Bhattacharya/ism_leaderboard/files/leaderboard"
|
13 |
# Directory where request by models are stored
|
14 |
DIR_OUTPUT_REQUESTS = Path("requested_models")
|
|
|
57 |
|
58 |
return html_page
|
59 |
|
60 |
+
async def fetch_leaderboard(phase=1):
|
61 |
|
62 |
"""
|
63 |
Fetch the leaderboard from the local disk
|
64 |
"""
|
65 |
params = {"phase": phase}
|
66 |
|
67 |
+
leaderboard_df = await make_get_request("fetch-leaderboard", params)
|
68 |
+
|
69 |
csv_data = leaderboard_df.content.decode('utf-8')
|
70 |
+
print(csv_data)
|
71 |
#print(csv_data)
|
72 |
|
73 |
# create dataframe from csv data
|
|
|
145 |
def format_leaderboard(df,sort_by="F1 Score"):
|
146 |
# Formats the columns
|
147 |
|
148 |
+
if df is None:
|
149 |
+
return None
|
150 |
+
print(df)
|
151 |
+
|
152 |
for col in df.columns:
|
153 |
if col == "Team Name":
|
154 |
# do nothing
|
|
|
164 |
df.sort_values(by=sort_by, inplace=True, ascending=False)
|
165 |
return df
|
166 |
|
167 |
+
# Run the async function in an event loop
|
168 |
|
169 |
|
170 |
+
lb_1 = asyncio.run(fetch_leaderboard(phase=1))
|
171 |
+
lb_2 = asyncio.run(fetch_leaderboard(phase=2))
|
172 |
+
leaderboard_df_1 = format_leaderboard(lb_1)
|
173 |
+
leaderboard_df_2 = format_leaderboard(lb_2)
|
174 |
#leaderboard_df_1 = None
|
175 |
#leaderboard_df_2 = None
|
176 |
|
|
|
182 |
leaderboard_table_2 = None
|
183 |
|
184 |
def button_clicked_phase_1(inputs):
|
185 |
+
lb_1 = asyncio.run(fetch_leaderboard(phase=1))
|
186 |
+
leaderboard_df_1 = format_leaderboard(lb_1)
|
187 |
|
188 |
|
189 |
leaderboard_table_1 = gr.components.Dataframe(
|
|
|
200 |
|
201 |
|
202 |
def button_clicked_phase_2():
|
203 |
+
lb_2 = asyncio.run(fetch_leaderboard(phase=2))
|
204 |
+
leaderboard_df_2 = format_leaderboard(lb_2)
|
205 |
|
206 |
|
207 |
leaderboard_table_2 = gr.components.Dataframe(
|
request_api.py
CHANGED
@@ -4,15 +4,43 @@
|
|
4 |
|
5 |
import requests
|
6 |
|
7 |
-
from urllib.parse import urljoin, urlencode
|
8 |
-
|
9 |
|
10 |
# Define the base URL
|
11 |
-
BASE_URL = 'https://d9c5-134-28-45-21.ngrok-free.app/'
|
12 |
#BASE_URL = 'http://127.0.0.1:5000/'
|
|
|
|
|
|
|
13 |
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def make_get_request(endpoint,params):
|
17 |
|
18 |
try:
|
@@ -50,5 +78,5 @@ def make_post_request(endpoint,params,data=None):
|
|
50 |
# Return the error
|
51 |
return response
|
52 |
|
53 |
-
|
54 |
|
|
|
4 |
|
5 |
import requests
|
6 |
|
7 |
+
from urllib.parse import urljoin, urlencode
|
|
|
8 |
|
9 |
# Define the base URL
|
|
|
10 |
#BASE_URL = 'http://127.0.0.1:5000/'
|
11 |
+
import httpx
|
12 |
+
|
13 |
+
BASE_URL = 'https://d9c5-134-28-45-21.ngrok-free.app/'
|
14 |
|
15 |
+
async def make_get_request(endpoint, params):
|
16 |
|
17 |
+
async with httpx.AsyncClient() as client:
|
18 |
+
try:
|
19 |
+
response = await client.get(urljoin(BASE_URL, endpoint), params=params)
|
20 |
+
print(response.url)
|
21 |
+
response.raise_for_status() # Check if the response is successful
|
22 |
+
except httpx.HTTPError as e:
|
23 |
+
print(f"Request failed: {e}")
|
24 |
+
return None
|
25 |
|
26 |
+
print(response)
|
27 |
+
return response
|
28 |
+
|
29 |
+
async def make_post_request(endpoint, params, data=None):
|
30 |
+
if data is None:
|
31 |
+
return None
|
32 |
+
|
33 |
+
async with httpx.AsyncClient() as client:
|
34 |
+
try:
|
35 |
+
response = await client.post(urljoin(BASE_URL, endpoint), params=params, data=data)
|
36 |
+
response.raise_for_status() # Check if the response is successful
|
37 |
+
except httpx.HTTPError as e:
|
38 |
+
print(f"Request failed: {e}")
|
39 |
+
return None
|
40 |
+
return response
|
41 |
+
|
42 |
+
|
43 |
+
"""
|
44 |
def make_get_request(endpoint,params):
|
45 |
|
46 |
try:
|
|
|
78 |
# Return the error
|
79 |
return response
|
80 |
|
81 |
+
"""
|
82 |
|