File size: 6,006 Bytes
a33ace4
63d7feb
82fc346
a52b9c1
63d7feb
a33ace4
 
 
 
f9e1958
 
 
 
 
a33ace4
 
 
 
 
 
 
 
 
 
 
 
 
 
a52b9c1
 
 
 
a33ace4
a52b9c1
 
 
 
 
 
 
 
 
 
 
a33ace4
a52b9c1
 
 
 
 
a33ace4
a52b9c1
 
 
 
 
 
 
 
 
 
 
 
a33ace4
a52b9c1
 
 
 
 
a33ace4
a52b9c1
a33ace4
 
 
 
 
 
 
 
 
 
 
a52b9c1
a33ace4
 
 
a52b9c1
 
a33ace4
a52b9c1
a33ace4
 
 
 
 
 
 
 
 
a52b9c1
a33ace4
 
a52b9c1
 
 
 
 
 
 
 
 
 
 
 
a33ace4
a52b9c1
 
 
 
 
 
a33ace4
82fc346
 
 
 
 
 
a33ace4
a52b9c1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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 get_user(profile: gr.OAuthProfile | None) -> str:
    if profile is None:
        return ""
    return f"Hello {profile.username}"

def update_vote_ui(profile: gr.OAuthProfile | None):
    username = get_user(profile)
    if username:
        username_widget = gr.Textbox(value=username, label="Username", interactive=False)
    else:
        username_widget = gr.LoginButton()
    return username_widget


def submit_vote(username, category, vote):
    if not category or not vote:
        return "All fields are required!"
    if not username:
        return "You need to log in to submit a vote."
    if username.startswith("Hello "):
        username = username[6:]

    url = "https://sdk.nexa4ai.com/task"   # Will have a new endpoint
    data = {
        "category": category,
        "model_id": vote,
        "username": username
    }
    
    response = requests.post(url, json=data)
    
    if response.status_code == 200:
        return f"Vote '{vote}' submitted successfully!"
    else:
        return f"Failed to vote: {response.text}"

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(auth=gr.HuggingfaceOAuth(optional=True)) as app:
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"):
            profile = None
            if profile:
                username = get_user(profile)
                username_text = gr.Textbox(value=username, label="Username", interactive=False)
            else:
                login_button = gr.LoginButton()

            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 options")
            submit_button = gr.Button("Submit Vote")
            submit_result = gr.Label()
            if profile:
                submit_button.click(fn=submit_vote, inputs=[username_text, category, vote], outputs=submit_result)
            else:
                submit_button.click(fn=lambda: "Please log in to submit your vote.", inputs=[], 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()