Update app.py
Browse files
app.py
CHANGED
@@ -4,54 +4,77 @@ import pandas as pd
|
|
4 |
import requests
|
5 |
|
6 |
def update_table(category):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
"Model": ["Model A", "Model B", "Model C", "Model D", "Model E", "Model F", "Model G", "Model H", "Model I", "Model J", "Model K", "Model L", "Model M", "Model N", "Model O", "Model P", "Model Q", "Model R", "Model S", "Model T", "Model U", "Model V", "Model W", "Model X", "Model Y", "Model Z"],
|
11 |
-
"Votes": [1250, 200, 3150, 4250, 5200, 6150, 7250, 8200, 9150, 10250, 11200, 12150, 13250, 21250, 200, 3150, 4250, 5200, 6150, 7250, 8200, 9150, 10250, 11200, 12150, 13250],
|
12 |
-
"Organization": ["Org A", "Org B", "Org C", "Org D", "Org E", "Org F", "Org G", "Org H", "Org I", "Org J", "Org K", "Org L", "Org M", "Org N", "Org O", "Org P", "Org Q", "Model R", "Model S", "Model T", "Model U", "Model V", "Model W", "Model X", "Model Y", "Model Z"],
|
13 |
-
"License": ["1MIT", "2Apache 2.0", "3GPL", "4MIT", "5Apache 2.0", "6GPL", "7MIT", "8Apache 2.0", "9GPL", "10MIT", "11Apache 2.0", "12GPL", "13MIT", "1MIT", "2Apache 2.0", "3GPL", "4MIT", "5Apache 2.0", "6GPL", "7MIT", "8Apache 2.0", "9GPL", "10MIT", "11Apache 2.0", "12GPL", "13MIT"]
|
14 |
-
},
|
15 |
-
"Biology": {
|
16 |
-
"Rank": [1, 2],
|
17 |
-
"Model": ["GenePredict", "BioSeq"],
|
18 |
-
"Votes": [180, 160],
|
19 |
-
"Organization": ["BioTech", "Genomics Inc"],
|
20 |
-
"License": ["GPL", "MIT"]
|
21 |
-
}
|
22 |
-
}
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
return df
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
30 |
if profile is None:
|
31 |
return ""
|
32 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
-
def submit_vote(username, category,
|
36 |
-
if not category or not
|
37 |
return "All fields are required!"
|
38 |
if not username:
|
39 |
return "You need to log in to submit a vote."
|
40 |
if username.startswith("Hello "):
|
41 |
username = username[6:]
|
42 |
|
43 |
-
url = "https://
|
44 |
-
|
45 |
"category": category,
|
46 |
-
"model_id": vote,
|
47 |
"username": username
|
48 |
}
|
|
|
|
|
|
|
49 |
|
50 |
print("Submitting vote with payload:", data)
|
51 |
-
response = requests.post(url, json=data)
|
52 |
|
53 |
if response.status_code == 200:
|
54 |
-
return f"Vote '{
|
55 |
else:
|
56 |
return f"Failed to vote: {response.text}"
|
57 |
|
@@ -60,7 +83,7 @@ def submit_model(category, model_id):
|
|
60 |
if not category or not model_id:
|
61 |
return "All fields are required!"
|
62 |
|
63 |
-
url = "https://
|
64 |
data = {
|
65 |
"category": category,
|
66 |
"model_id": model_id
|
@@ -79,17 +102,17 @@ with gr.Blocks() as app:
|
|
79 |
with gr.Tabs():
|
80 |
with gr.TabItem("Table"):
|
81 |
category = gr.Dropdown(
|
82 |
-
choices=["
|
83 |
label="Select Category",
|
84 |
-
value="
|
85 |
)
|
86 |
|
87 |
-
initial_data = update_table("
|
88 |
table = gr.Dataframe(
|
89 |
-
headers=["
|
90 |
-
datatype=["
|
91 |
value=initial_data,
|
92 |
-
col_count=(
|
93 |
)
|
94 |
category.change(update_table, inputs=category, outputs=table)
|
95 |
|
@@ -102,11 +125,16 @@ with gr.Blocks() as app:
|
|
102 |
choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
103 |
label="Select Category"
|
104 |
)
|
105 |
-
|
|
|
106 |
submit_button = gr.Button("Submit Vote")
|
107 |
submit_result = gr.Label()
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
110 |
|
111 |
|
112 |
# with gr.TabItem("Submit Model"):
|
|
|
4 |
import requests
|
5 |
|
6 |
def update_table(category):
|
7 |
+
# TODO: url -> env
|
8 |
+
url = "https://leaderboard.nexa4ai.com/model/get-ranking-by-category"
|
9 |
+
url_with_params = f"{url}?category={category}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
print("Getting model table with URL:", url_with_params)
|
12 |
+
response = requests.get(url_with_params)
|
|
|
13 |
|
14 |
+
if response.status_code == 200:
|
15 |
+
ranking_data = response.json()["ranking"]
|
16 |
+
# Process the API data into a DataFrame
|
17 |
+
api_model_data = {
|
18 |
+
"Model": [item["model_id"] for item in ranking_data],
|
19 |
+
"Votes": [item["votes"] for item in ranking_data],
|
20 |
+
"Categories": [category] * len(ranking_data)
|
21 |
+
}
|
22 |
+
api_df = pd.DataFrame(api_model_data)
|
23 |
+
else:
|
24 |
+
print(f"Failed to submit request: {response.text}")
|
25 |
+
api_df = pd.DataFrame()
|
26 |
+
return api_df
|
27 |
|
28 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
29 |
if profile is None:
|
30 |
return ""
|
31 |
+
return profile.username
|
32 |
+
|
33 |
+
def get_vote_models(category):
|
34 |
+
print (category)
|
35 |
+
if not category:
|
36 |
+
return []
|
37 |
+
|
38 |
+
url = "https://leaderboard.nexa4ai.com/model/get-models-by-category"
|
39 |
+
url_with_params = f"{url}?category={category}"
|
40 |
+
|
41 |
+
print("Getting models with URL:", url_with_params)
|
42 |
+
response = requests.get(url_with_params)
|
43 |
+
|
44 |
+
if response.status_code == 200:
|
45 |
+
models_data = response.json()
|
46 |
+
models.choices = models_data # Set choices of models
|
47 |
+
print(f"models_data: {models_data}")
|
48 |
+
print(f"models.choices: {models.choices}")
|
49 |
+
return models_data
|
50 |
+
else:
|
51 |
+
print(f"Failed to get models: {response.text}")
|
52 |
+
return []
|
53 |
+
|
54 |
|
55 |
|
56 |
+
def submit_vote(username, category, model_ids):
|
57 |
+
if not category or not model_ids:
|
58 |
return "All fields are required!"
|
59 |
if not username:
|
60 |
return "You need to log in to submit a vote."
|
61 |
if username.startswith("Hello "):
|
62 |
username = username[6:]
|
63 |
|
64 |
+
url = "https://leaderboard.nexa4ai.com/model/vote"
|
65 |
+
params = {
|
66 |
"category": category,
|
|
|
67 |
"username": username
|
68 |
}
|
69 |
+
data = {
|
70 |
+
"model_ids": model_ids
|
71 |
+
}
|
72 |
|
73 |
print("Submitting vote with payload:", data)
|
74 |
+
response = requests.post(url, params=params, json=data)
|
75 |
|
76 |
if response.status_code == 200:
|
77 |
+
return f"Vote '{model_ids}' submitted successfully!"
|
78 |
else:
|
79 |
return f"Failed to vote: {response.text}"
|
80 |
|
|
|
83 |
if not category or not model_id:
|
84 |
return "All fields are required!"
|
85 |
|
86 |
+
url = "https://leaderboard.nexa4ai.com/" # Will have a new endpoint
|
87 |
data = {
|
88 |
"category": category,
|
89 |
"model_id": model_id
|
|
|
102 |
with gr.Tabs():
|
103 |
with gr.TabItem("Table"):
|
104 |
category = gr.Dropdown(
|
105 |
+
choices=["all", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
106 |
label="Select Category",
|
107 |
+
value="all"
|
108 |
)
|
109 |
|
110 |
+
initial_data = update_table("all")
|
111 |
table = gr.Dataframe(
|
112 |
+
headers=["Model", "Votes", "Categories"],
|
113 |
+
datatype=["str", "number", "str"],
|
114 |
value=initial_data,
|
115 |
+
col_count=(3, "fixed"),
|
116 |
)
|
117 |
category.change(update_table, inputs=category, outputs=table)
|
118 |
|
|
|
125 |
choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
126 |
label="Select Category"
|
127 |
)
|
128 |
+
|
129 |
+
models = gr.CheckboxGroup(choices=[], label="Choose your options")
|
130 |
submit_button = gr.Button("Submit Vote")
|
131 |
submit_result = gr.Label()
|
132 |
|
133 |
+
category.change(get_vote_models, inputs=[category], outputs=[models]) # Fix: Use models.choices to update choices
|
134 |
+
|
135 |
+
submit_button.click(fn=submit_vote, inputs=[username_text, category, models], outputs=submit_result)
|
136 |
+
|
137 |
+
|
138 |
|
139 |
|
140 |
# with gr.TabItem("Submit Model"):
|