Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import pandas as pd
|
4 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
5 |
import requests
|
|
|
6 |
|
7 |
leaderboard_url = os.getenv("LEADERBOARD_URL", "https://leaderboard.nexa4ai.com")
|
8 |
|
@@ -11,6 +12,12 @@ get_models_url = f"{leaderboard_url}/model/get-models-by-category"
|
|
11 |
vote_url = f"{leaderboard_url}/model/vote"
|
12 |
submit_models_url = f"{leaderboard_url}/model/submit-models"
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def update_table(category):
|
15 |
url_with_params = f"{get_ranking_url}?category={category}"
|
16 |
|
@@ -21,13 +28,15 @@ def update_table(category):
|
|
21 |
api_model_data = {
|
22 |
"Model": [item["model_id"] for item in ranking_data],
|
23 |
"Votes": [item["votes"] for item in ranking_data],
|
24 |
-
"Categories": [category] * len(ranking_data)
|
25 |
}
|
26 |
api_df = pd.DataFrame(api_model_data)
|
|
|
|
|
27 |
else:
|
28 |
print(f"Failed to submit request: {response.text}")
|
29 |
api_df = pd.DataFrame()
|
30 |
-
|
31 |
|
32 |
|
33 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
@@ -74,13 +83,17 @@ def submit_vote(username, category, models):
|
|
74 |
return f"Failed to vote: {response.text}"
|
75 |
|
76 |
|
77 |
-
def submit_model(category, model_id):
|
78 |
-
if not
|
79 |
return "All fields are required!"
|
|
|
|
|
80 |
|
|
|
|
|
81 |
data = {
|
82 |
"model_id": model_id,
|
83 |
-
"categories": [
|
84 |
}
|
85 |
|
86 |
response = requests.post(submit_models_url, json=data)
|
@@ -90,6 +103,10 @@ def submit_model(category, model_id):
|
|
90 |
else:
|
91 |
return f"Failed to submit request: {response.text}"
|
92 |
|
|
|
|
|
|
|
|
|
93 |
|
94 |
theme = gr.themes.Soft()
|
95 |
|
@@ -132,13 +149,11 @@ with gr.Blocks(theme=theme) as app:
|
|
132 |
|
133 |
with gr.TabItem("Submit Model"):
|
134 |
category = gr.Dropdown(choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"], label="Select Category")
|
135 |
-
|
136 |
-
label="Hub Model ID",
|
137 |
-
placeholder="Search for model id on Huggingface",
|
138 |
-
search_type="model",
|
139 |
-
)
|
140 |
submit_model_button = gr.Button("Submit Model")
|
141 |
submit_model_result = gr.Markdown()
|
142 |
-
|
|
|
143 |
|
144 |
app.launch(share=True)
|
|
|
3 |
import pandas as pd
|
4 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
5 |
import requests
|
6 |
+
from huggingface_hub import HfApi
|
7 |
|
8 |
leaderboard_url = os.getenv("LEADERBOARD_URL", "https://leaderboard.nexa4ai.com")
|
9 |
|
|
|
12 |
vote_url = f"{leaderboard_url}/model/vote"
|
13 |
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 |
url_with_params = f"{get_ranking_url}?category={category}"
|
23 |
|
|
|
28 |
api_model_data = {
|
29 |
"Model": [item["model_id"] for item in ranking_data],
|
30 |
"Votes": [item["votes"] for item in ranking_data],
|
31 |
+
"Categories": [item["categories"] for item in ranking_data] if category == "all" else [category] * len(ranking_data)
|
32 |
}
|
33 |
api_df = pd.DataFrame(api_model_data)
|
34 |
+
api_df['Model'] = api_df['Model'].apply(make_clickable_model)
|
35 |
+
return api_df
|
36 |
else:
|
37 |
print(f"Failed to submit request: {response.text}")
|
38 |
api_df = pd.DataFrame()
|
39 |
+
return api_df
|
40 |
|
41 |
|
42 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
|
|
83 |
return f"Failed to vote: {response.text}"
|
84 |
|
85 |
|
86 |
+
def submit_model(category, customize_category, model_id):
|
87 |
+
if not model_id:
|
88 |
return "All fields are required!"
|
89 |
+
if not category or not customize_category:
|
90 |
+
return "Please choose a cateogry or customize your own category!"
|
91 |
|
92 |
+
selected_category = customize_category if customize_category else category
|
93 |
+
|
94 |
data = {
|
95 |
"model_id": model_id,
|
96 |
+
"categories": [selected_category]
|
97 |
}
|
98 |
|
99 |
response = requests.post(submit_models_url, json=data)
|
|
|
103 |
else:
|
104 |
return f"Failed to submit request: {response.text}"
|
105 |
|
106 |
+
def update_dropdown(customize_category, category):
|
107 |
+
if customize_category:
|
108 |
+
return "", gr.update(value="")
|
109 |
+
return category, gr.update()
|
110 |
|
111 |
theme = gr.themes.Soft()
|
112 |
|
|
|
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")
|
155 |
submit_model_result = gr.Markdown()
|
156 |
+
customize_category.change(fn=update_dropdown, inputs=[customize_category, category], outputs=[category])
|
157 |
+
submit_model_button.click(fn=submit_model, inputs=[category, customize_category, model_id], outputs=submit_model_result)
|
158 |
|
159 |
app.launch(share=True)
|