Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
import pandas as pd
|
4 |
# from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
5 |
import requests
|
6 |
-
from
|
7 |
|
8 |
leaderboard_url = os.getenv("LEADERBOARD_URL", "https://leaderboard.nexa4ai.com")
|
9 |
|
@@ -14,29 +14,32 @@ submit_models_url = f"{leaderboard_url}/model/submit-models"
|
|
14 |
|
15 |
def make_clickable_model(model_id):
|
16 |
model_name_show = ' '.join(model_id.split('/')[1:])
|
17 |
-
|
18 |
link = "https://huggingface.co/" + model_id
|
19 |
-
return f'<a target="_blank" href="{link}">{model_name_show}</a>'
|
20 |
-
|
21 |
-
def update_table(category):
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
@@ -112,9 +115,9 @@ theme = gr.themes.Soft()
|
|
112 |
|
113 |
with gr.Blocks(theme=theme) as app:
|
114 |
with gr.Tabs():
|
115 |
-
with gr.TabItem("Table"):
|
116 |
category = gr.Dropdown(
|
117 |
-
choices=["all", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
118 |
label="Select Category",
|
119 |
value="all"
|
120 |
)
|
@@ -122,19 +125,20 @@ with gr.Blocks(theme=theme) as app:
|
|
122 |
initial_data = update_table("all")
|
123 |
table = gr.Dataframe(
|
124 |
headers=["Model", "Votes", "Categories"],
|
125 |
-
datatype=["
|
126 |
value=initial_data,
|
127 |
col_count=(3, "fixed"),
|
128 |
)
|
|
|
129 |
category.change(update_table, inputs=category, outputs=table)
|
130 |
-
|
131 |
with gr.TabItem("Vote"):
|
132 |
username_text = gr.State(value="")
|
133 |
login_button = gr.LoginButton()
|
134 |
app.load(get_user, inputs=None, outputs=username_text)
|
135 |
|
136 |
category = gr.Dropdown(
|
137 |
-
choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
138 |
label="Select Category"
|
139 |
)
|
140 |
|
@@ -148,7 +152,7 @@ with gr.Blocks(theme=theme) as app:
|
|
148 |
|
149 |
|
150 |
# with gr.TabItem("Submit Model"):
|
151 |
-
# category = gr.Dropdown(choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"], label="Select Category")
|
152 |
# customize_category = gr.Textbox(label="Customize category", placeholder="Can't find your category? Enter your own.")
|
153 |
# model_id = HuggingfaceHubSearch(label="Hub Model ID", placeholder="Search for model id on Huggingface", search_type="model")
|
154 |
# submit_model_button = gr.Button("Submit Model")
|
|
|
3 |
import pandas as pd
|
4 |
# from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
5 |
import requests
|
6 |
+
from urllib.parse import quote
|
7 |
|
8 |
leaderboard_url = os.getenv("LEADERBOARD_URL", "https://leaderboard.nexa4ai.com")
|
9 |
|
|
|
14 |
|
15 |
def make_clickable_model(model_id):
|
16 |
model_name_show = ' '.join(model_id.split('/')[1:])
|
|
|
17 |
link = "https://huggingface.co/" + model_id
|
18 |
+
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name_show}</a>'
|
19 |
+
|
20 |
+
def update_table(category):
|
21 |
+
retries = 3
|
22 |
+
while retries > 0:
|
23 |
+
try:
|
24 |
+
encoded_category = quote(category)
|
25 |
+
url_with_params = f"{get_ranking_url}?category={encoded_category}"
|
26 |
+
response = requests.get(url_with_params)
|
27 |
+
if response.status_code == 200:
|
28 |
+
ranking_data = response.json()["ranking"]
|
29 |
+
api_model_data = {
|
30 |
+
"Model": [make_clickable_model(item["model_id"]) for item in ranking_data],
|
31 |
+
"Votes": [item["votes"] for item in ranking_data],
|
32 |
+
"Categories": [item["categories"] for item in ranking_data] if category == "all" else [category] * len(ranking_data)
|
33 |
+
}
|
34 |
+
api_df = pd.DataFrame(api_model_data)
|
35 |
+
return api_df
|
36 |
+
else:
|
37 |
+
print(f"Failed to submit request: {response.text}")
|
38 |
+
retries -= 1
|
39 |
+
except requests.exceptions.RequestException as e:
|
40 |
+
print(f"Error occurred while making request: {e}")
|
41 |
+
retries -= 1
|
42 |
+
return pd.DataFrame()
|
43 |
|
44 |
|
45 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
|
|
115 |
|
116 |
with gr.Blocks(theme=theme) as app:
|
117 |
with gr.Tabs():
|
118 |
+
with gr.TabItem("Table"):
|
119 |
category = gr.Dropdown(
|
120 |
+
choices=["all", "Art & Design", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Education", "Health", "Law", "Engineering", "Coding", "Science", "Other"],
|
121 |
label="Select Category",
|
122 |
value="all"
|
123 |
)
|
|
|
125 |
initial_data = update_table("all")
|
126 |
table = gr.Dataframe(
|
127 |
headers=["Model", "Votes", "Categories"],
|
128 |
+
datatype=["markdown", "number", "str"],
|
129 |
value=initial_data,
|
130 |
col_count=(3, "fixed"),
|
131 |
)
|
132 |
+
app.load(lambda: update_table("all"), outputs=table)
|
133 |
category.change(update_table, inputs=category, outputs=table)
|
134 |
+
|
135 |
with gr.TabItem("Vote"):
|
136 |
username_text = gr.State(value="")
|
137 |
login_button = gr.LoginButton()
|
138 |
app.load(get_user, inputs=None, outputs=username_text)
|
139 |
|
140 |
category = gr.Dropdown(
|
141 |
+
choices=["Art & Design", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Education", "Health", "Law", "Engineering", "Coding", "Science", "Other"],
|
142 |
label="Select Category"
|
143 |
)
|
144 |
|
|
|
152 |
|
153 |
|
154 |
# with gr.TabItem("Submit Model"):
|
155 |
+
# category = gr.Dropdown(choices=["Art & Design", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Education", "Health", "Law", "Engineering", "Coding", "Science", "Other"], label="Select Category")
|
156 |
# customize_category = gr.Textbox(label="Customize category", placeholder="Can't find your category? Enter your own.")
|
157 |
# model_id = HuggingfaceHubSearch(label="Hub Model ID", placeholder="Search for model id on Huggingface", search_type="model")
|
158 |
# submit_model_button = gr.Button("Submit Model")
|