Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
# from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
3 |
import pandas as pd
|
|
|
|
|
4 |
|
5 |
|
6 |
def update_table(category):
|
@@ -25,17 +26,49 @@ def update_table(category):
|
|
25 |
df = pd.DataFrame(data)
|
26 |
return df
|
27 |
|
28 |
-
def
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
def
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return "All fields are required!"
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
url = "https://sdk.nexa4ai.com/task" # Will have a new endpoint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
data = {
|
|
|
39 |
"model_id": model_id
|
40 |
}
|
41 |
|
@@ -47,17 +80,14 @@ def submit_model(model_id):
|
|
47 |
return f"Failed to submit request: {response.text}"
|
48 |
|
49 |
|
|
|
50 |
with gr.Blocks() as app:
|
51 |
with gr.Tabs():
|
52 |
with gr.TabItem("Table"):
|
53 |
-
|
54 |
-
choices=[
|
55 |
-
"Overall", "Biology", "Physics", "Business", "Chemistry",
|
56 |
-
"Economics", "Philosophy", "History", "Culture", "Computer Science",
|
57 |
-
"Math", "Health", "Law", "Engineering", "Other"
|
58 |
-
],
|
59 |
label="Select Category",
|
60 |
-
value="Overall"
|
61 |
)
|
62 |
|
63 |
initial_data = update_table("Overall")
|
@@ -66,24 +96,35 @@ with gr.Blocks() as app:
|
|
66 |
datatype=["number", "str", "number", "str", "str"],
|
67 |
value=initial_data,
|
68 |
col_count=(5, "fixed"),
|
69 |
-
# height=600
|
70 |
)
|
71 |
-
|
72 |
|
73 |
with gr.TabItem("Vote"):
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
submit_button = gr.Button("Submit Vote")
|
76 |
-
submit_result = gr.Label()
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
# submit_model_button = gr.Button("Submit Model")
|
86 |
-
# submit_model_result = gr.Label()
|
87 |
-
# submit_model_button.click(fn=submit_model, inputs=[model_id], outputs=submit_model_result)
|
88 |
|
89 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import pandas as pd
|
3 |
+
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
4 |
+
import requests
|
5 |
|
6 |
|
7 |
def update_table(category):
|
|
|
26 |
df = pd.DataFrame(data)
|
27 |
return df
|
28 |
|
29 |
+
def get_user(profile: gr.OAuthProfile | None) -> str:
|
30 |
+
if profile is None:
|
31 |
+
return ""
|
32 |
+
return f"Hello {profile.username}"
|
33 |
|
34 |
+
def update_vote_ui(profile: gr.OAuthProfile | None):
|
35 |
+
username = get_user(profile)
|
36 |
+
if username:
|
37 |
+
username_widget = gr.Textbox(value=username, label="Username", interactive=False)
|
38 |
+
else:
|
39 |
+
username_widget = gr.LoginButton()
|
40 |
+
return username_widget
|
41 |
+
|
42 |
+
|
43 |
+
def submit_vote(username, category, vote):
|
44 |
+
if not category or not vote:
|
45 |
return "All fields are required!"
|
46 |
+
if not username:
|
47 |
+
return "You need to log in to submit a vote."
|
48 |
+
if username.startswith("Hello "):
|
49 |
+
username = username[6:]
|
50 |
+
|
51 |
url = "https://sdk.nexa4ai.com/task" # Will have a new endpoint
|
52 |
+
data = {
|
53 |
+
"category": category,
|
54 |
+
"model_id": vote,
|
55 |
+
"username": username
|
56 |
+
}
|
57 |
+
|
58 |
+
response = requests.post(url, json=data)
|
59 |
+
|
60 |
+
if response.status_code == 200:
|
61 |
+
return f"Vote '{vote}' submitted successfully!"
|
62 |
+
else:
|
63 |
+
return f"Failed to vote: {response.text}"
|
64 |
|
65 |
+
def submit_model(category, model_id):
|
66 |
+
if not category or not model_id:
|
67 |
+
return "All fields are required!"
|
68 |
+
|
69 |
+
url = "https://sdk.nexa4ai.com/task" # Will have a new endpoint
|
70 |
data = {
|
71 |
+
"category": category,
|
72 |
"model_id": model_id
|
73 |
}
|
74 |
|
|
|
80 |
return f"Failed to submit request: {response.text}"
|
81 |
|
82 |
|
83 |
+
# with gr.Blocks(auth=gr.HuggingfaceOAuth(optional=True)) as app:
|
84 |
with gr.Blocks() as app:
|
85 |
with gr.Tabs():
|
86 |
with gr.TabItem("Table"):
|
87 |
+
category = gr.Dropdown(
|
88 |
+
choices=["Overall", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
|
|
|
|
|
|
|
|
89 |
label="Select Category",
|
90 |
+
value="Overall"
|
91 |
)
|
92 |
|
93 |
initial_data = update_table("Overall")
|
|
|
96 |
datatype=["number", "str", "number", "str", "str"],
|
97 |
value=initial_data,
|
98 |
col_count=(5, "fixed"),
|
|
|
99 |
)
|
100 |
+
category.change(update_table, inputs=category, outputs=table)
|
101 |
|
102 |
with gr.TabItem("Vote"):
|
103 |
+
profile = None
|
104 |
+
if profile:
|
105 |
+
username = get_user(profile)
|
106 |
+
username_text = gr.Textbox(value=username, label="Username", interactive=False)
|
107 |
+
else:
|
108 |
+
login_button = gr.LoginButton()
|
109 |
+
|
110 |
+
category = gr.Dropdown(
|
111 |
+
choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
|
112 |
+
label="Select Category"
|
113 |
+
)
|
114 |
+
vote = gr.CheckboxGroup(choices=["Option 1", "Option 2", "Option 3"], label="Choose your options")
|
115 |
submit_button = gr.Button("Submit Vote")
|
116 |
+
submit_result = gr.Label()
|
117 |
+
if profile:
|
118 |
+
submit_button.click(fn=submit_vote, inputs=[username_text, category, vote], outputs=submit_result)
|
119 |
+
else:
|
120 |
+
submit_button.click(fn=lambda: "Please log in to submit your vote.", inputs=[], outputs=submit_result)
|
121 |
+
|
122 |
|
123 |
+
with gr.TabItem("Submit Model"):
|
124 |
+
category = gr.Dropdown(choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"], label="Select Category")
|
125 |
+
model_id = HuggingfaceHubSearch(label="Hub Model ID", placeholder="Search for model id on Huggingface", search_type="model")
|
126 |
+
submit_model_button = gr.Button("Submit Model")
|
127 |
+
submit_model_result = gr.Label()
|
128 |
+
submit_model_button.click(fn=submit_model, inputs=[category, model_id], outputs=submit_model_result)
|
|
|
|
|
|
|
129 |
|
130 |
+
app.launch()
|