Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
-
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
| 5 |
import requests
|
| 6 |
from urllib.parse import quote
|
| 7 |
|
|
@@ -43,12 +42,6 @@ def update_table(category):
|
|
| 43 |
return pd.DataFrame()
|
| 44 |
|
| 45 |
|
| 46 |
-
def get_user(profile: gr.OAuthProfile | None) -> str:
|
| 47 |
-
if profile is None:
|
| 48 |
-
return ""
|
| 49 |
-
return profile.username
|
| 50 |
-
|
| 51 |
-
|
| 52 |
def get_vote_models(category):
|
| 53 |
if not category:
|
| 54 |
return []
|
|
@@ -65,17 +58,12 @@ def get_vote_models(category):
|
|
| 65 |
return []
|
| 66 |
|
| 67 |
|
| 68 |
-
def submit_vote(
|
| 69 |
if not category or not models:
|
| 70 |
return "All fields are required!"
|
| 71 |
-
|
| 72 |
-
return "You need to log in to submit a vote."
|
| 73 |
-
if username.startswith("Hello "):
|
| 74 |
-
username = username[6:]
|
| 75 |
-
|
| 76 |
data = {
|
| 77 |
"category": category,
|
| 78 |
-
"username": username,
|
| 79 |
"model_ids": models
|
| 80 |
}
|
| 81 |
|
|
@@ -108,6 +96,7 @@ def submit_model(category, customize_category, model_id):
|
|
| 108 |
"model_id": model_id,
|
| 109 |
"categories": [selected_category]
|
| 110 |
}
|
|
|
|
| 111 |
response = requests.post(submit_models_url, json=data)
|
| 112 |
if response.status_code == 200:
|
| 113 |
return "Your request has been submitted successfully. We will notify you by email once processing is complete."
|
|
@@ -136,15 +125,12 @@ with gr.Blocks(theme=theme) as app:
|
|
| 136 |
datatype=["markdown", "number", "str"],
|
| 137 |
value=initial_data,
|
| 138 |
col_count=(3, "fixed"),
|
|
|
|
| 139 |
)
|
| 140 |
app.load(lambda: update_table("all"), outputs=table)
|
| 141 |
category.change(update_table, inputs=category, outputs=table)
|
| 142 |
|
| 143 |
with gr.TabItem("Vote"):
|
| 144 |
-
username_text = gr.State(value="")
|
| 145 |
-
login_button = gr.LoginButton()
|
| 146 |
-
app.load(get_user, inputs=None, outputs=username_text)
|
| 147 |
-
|
| 148 |
category = gr.Dropdown(
|
| 149 |
choices=["Art & Design", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Education", "Health", "Law", "Engineering", "Coding", "Science", "Other"],
|
| 150 |
label="Select Category"
|
|
@@ -156,13 +142,13 @@ with gr.Blocks(theme=theme) as app:
|
|
| 156 |
|
| 157 |
category.change(get_vote_models, inputs=category, outputs=cbg)
|
| 158 |
|
| 159 |
-
submit_button.click(fn=submit_vote, inputs=[
|
| 160 |
|
| 161 |
|
| 162 |
with gr.TabItem("Submit Model"):
|
| 163 |
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")
|
| 164 |
customize_category = gr.Textbox(label="Customize category", placeholder="Can't find your category? Enter your own.")
|
| 165 |
-
model_id =
|
| 166 |
submit_model_button = gr.Button("Submit Model")
|
| 167 |
submit_model_result = gr.Markdown()
|
| 168 |
customize_category.change(fn=update_dropdown, inputs=[customize_category, category], outputs=[category])
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
import requests
|
| 5 |
from urllib.parse import quote
|
| 6 |
|
|
|
|
| 42 |
return pd.DataFrame()
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
def get_vote_models(category):
|
| 46 |
if not category:
|
| 47 |
return []
|
|
|
|
| 58 |
return []
|
| 59 |
|
| 60 |
|
| 61 |
+
def submit_vote(category, models):
|
| 62 |
if not category or not models:
|
| 63 |
return "All fields are required!"
|
| 64 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
data = {
|
| 66 |
"category": category,
|
|
|
|
| 67 |
"model_ids": models
|
| 68 |
}
|
| 69 |
|
|
|
|
| 96 |
"model_id": model_id,
|
| 97 |
"categories": [selected_category]
|
| 98 |
}
|
| 99 |
+
|
| 100 |
response = requests.post(submit_models_url, json=data)
|
| 101 |
if response.status_code == 200:
|
| 102 |
return "Your request has been submitted successfully. We will notify you by email once processing is complete."
|
|
|
|
| 125 |
datatype=["markdown", "number", "str"],
|
| 126 |
value=initial_data,
|
| 127 |
col_count=(3, "fixed"),
|
| 128 |
+
height=600
|
| 129 |
)
|
| 130 |
app.load(lambda: update_table("all"), outputs=table)
|
| 131 |
category.change(update_table, inputs=category, outputs=table)
|
| 132 |
|
| 133 |
with gr.TabItem("Vote"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
category = gr.Dropdown(
|
| 135 |
choices=["Art & Design", "Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Education", "Health", "Law", "Engineering", "Coding", "Science", "Other"],
|
| 136 |
label="Select Category"
|
|
|
|
| 142 |
|
| 143 |
category.change(get_vote_models, inputs=category, outputs=cbg)
|
| 144 |
|
| 145 |
+
submit_button.click(fn=submit_vote, inputs=[category, cbg], outputs=submit_result)
|
| 146 |
|
| 147 |
|
| 148 |
with gr.TabItem("Submit Model"):
|
| 149 |
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")
|
| 150 |
customize_category = gr.Textbox(label="Customize category", placeholder="Can't find your category? Enter your own.")
|
| 151 |
+
model_id = gr.Textbox(label="Hub Model ID", placeholder="Submit model id")
|
| 152 |
submit_model_button = gr.Button("Submit Model")
|
| 153 |
submit_model_result = gr.Markdown()
|
| 154 |
customize_category.change(fn=update_dropdown, inputs=[customize_category, category], outputs=[category])
|