Zack Zhiyuan Li
add basic UI
0819278
raw
history blame
4.95 kB
import gradio as gr
import pandas as pd
from gradio_huggingfacehub_search import HuggingfaceHubSearch
import requests
def update_table(category):
data_dict = {
"Overall": {
"Rank": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],
"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"],
"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],
"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"],
"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"]
},
"Biology": {
"Rank": [1, 2],
"Model": ["GenePredict", "BioSeq"],
"Votes": [180, 160],
"Organization": ["BioTech", "Genomics Inc"],
"License": ["GPL", "MIT"]
}
}
data = data_dict.get(category, {"Rank": [], "Model": [], "Votes": [], "Organization": [], "License": []})
df = pd.DataFrame(data)
return df
def submit_vote(category, vote):
if not category or not vote:
return "All fields are required!"
# code
return f"Vote '{vote}' submitted successfully!"
def submit_model(category, model_id):
if not category or not model_id:
return "All fields are required!"
url = "https://sdk.nexa4ai.com/task" # Will have a new endpoint
data = {
"category": category,
"model_id": model_id
}
response = requests.post(url, json=data)
if response.status_code == 200:
return "Your request has been submitted successfully. We will notify you by email once processing is complete."
else:
return f"Failed to submit request: {response.text}"
with gr.Blocks() as app:
with gr.Tabs():
with gr.TabItem("Table"):
category = gr.Dropdown(
choices=[
"Overall", "Biology", "Physics", "Business", "Chemistry",
"Economics", "Philosophy", "History", "Culture", "Computer Science",
"Math", "Health", "Law", "Engineering", "Other"
],
label="Select Category",
value="Overall"
)
initial_data = update_table("Overall")
table = gr.Dataframe(
headers=["Rank", "Model", "Votes", "Organization", "License"],
datatype=["number", "str", "number", "str", "str"],
value=initial_data,
col_count=(5, "fixed"),
)
category.change(update_table, inputs=category, outputs=table)
with gr.TabItem("Vote"):
category = gr.Dropdown(
choices=[
"Biology", "Physics", "Business", "Chemistry",
"Economics", "Philosophy", "History", "Culture", "Computer Science",
"Math", "Health", "Law", "Engineering", "Other"
],
label="Select Category"
)
vote = gr.CheckboxGroup(choices=["Option 1", "Option 2", "Option 3"], label="Choose your option")
submit_button = gr.Button("Submit Vote")
submit_result = gr.Label()
submit_button.click(fn=submit_vote, inputs=[category, vote], outputs=submit_result)
with gr.TabItem("Submit Model"):
category = gr.Dropdown(
choices=[
"Biology", "Physics", "Business", "Chemistry",
"Economics", "Philosophy", "History", "Culture", "Computer Science",
"Math", "Health", "Law", "Engineering", "Other"
],
label="Select Category"
)
model_id = HuggingfaceHubSearch(
label="Hub Model ID",
placeholder="Search for model id on Huggingface",
search_type="model",
)
submit_model_button = gr.Button("Submit Model")
submit_model_result = gr.Label()
submit_model_button.click(fn=submit_model, inputs=[category, model_id], outputs=submit_model_result)
app.launch()