Abhishek Thakur
commited on
Commit
·
d3e4a05
1
Parent(s):
41baea7
add some create stuff
Browse files- competitions/create.py +135 -53
competitions/create.py
CHANGED
@@ -1,4 +1,7 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
from .utils import user_authentication
|
4 |
|
@@ -19,6 +22,40 @@ To create a competition, follow these steps:
|
|
19 |
"""
|
20 |
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def check_if_user_can_create_competition(user_token):
|
23 |
"""
|
24 |
Check if the user can create a competition
|
@@ -26,17 +63,42 @@ def check_if_user_can_create_competition(user_token):
|
|
26 |
:return: True if the user can create a competition, False otherwise
|
27 |
"""
|
28 |
user_info = user_authentication(user_token)
|
29 |
-
|
|
|
30 |
if "error" in user_info:
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
if
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
with gr.Blocks() as demo:
|
@@ -52,18 +114,17 @@ with gr.Blocks() as demo:
|
|
52 |
label="Please enter your Hugging Face token (write access needed)",
|
53 |
type="password",
|
54 |
)
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
)
|
60 |
-
|
61 |
-
|
62 |
-
""
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
"""
|
67 |
)
|
68 |
competition_type = gr.Radio(
|
69 |
["Generic"],
|
@@ -71,37 +132,38 @@ with gr.Blocks() as demo:
|
|
71 |
value="Generic",
|
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 |
with gr.Row():
|
106 |
with gr.Column():
|
107 |
sample_submission_file = gr.File(
|
@@ -113,10 +175,30 @@ with gr.Blocks() as demo:
|
|
113 |
)
|
114 |
gr.Markdown(
|
115 |
"""
|
116 |
-
|
|
|
117 |
data separately to the public repository that will be created.
|
118 |
-
You can also change sample_submission and solution files later
|
|
|
119 |
"""
|
120 |
)
|
121 |
with gr.Row():
|
122 |
-
gr.Button("Create Competition")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import uuid
|
2 |
+
|
3 |
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
|
6 |
from .utils import user_authentication
|
7 |
|
|
|
22 |
"""
|
23 |
|
24 |
|
25 |
+
def create_competition(
|
26 |
+
user_token,
|
27 |
+
who_pays,
|
28 |
+
competition_type,
|
29 |
+
competition_name,
|
30 |
+
eval_metric,
|
31 |
+
submission_limit,
|
32 |
+
selection_limit,
|
33 |
+
end_date,
|
34 |
+
sample_submission_file,
|
35 |
+
solution_file,
|
36 |
+
):
|
37 |
+
# generate a random id
|
38 |
+
suffix = str(uuid.uuid4())
|
39 |
+
private_dataset_name = f"{competition_name}{suffix}"
|
40 |
+
public_dataset_name = f"{competition_name}"
|
41 |
+
space_name = f"{competition_name}"
|
42 |
+
|
43 |
+
sample_submission_df = pd.read_csv(sample_submission_file, nrows=10)
|
44 |
+
submission_columns = ",".join(sample_submission_df.columns)
|
45 |
+
|
46 |
+
conf = {
|
47 |
+
"SUBMISSION_LIMIT": submission_limit,
|
48 |
+
"SELECTION_LIMIT": selection_limit,
|
49 |
+
"END_DATE": end_date,
|
50 |
+
"EVAL_HIGHER_IS_BETTER": True,
|
51 |
+
"COMPETITION_NAME": competition_name,
|
52 |
+
"SUBMISSION_COLUMNS": submission_columns,
|
53 |
+
"EVAL_METRIC": eval_metric,
|
54 |
+
}
|
55 |
+
|
56 |
+
pass
|
57 |
+
|
58 |
+
|
59 |
def check_if_user_can_create_competition(user_token):
|
60 |
"""
|
61 |
Check if the user can create a competition
|
|
|
63 |
:return: True if the user can create a competition, False otherwise
|
64 |
"""
|
65 |
user_info = user_authentication(user_token)
|
66 |
+
print(user_info)
|
67 |
+
return_msg = None
|
68 |
if "error" in user_info:
|
69 |
+
return_msg = "Invalid token. You can find your HF token here: https://huggingface.co/settings/tokens"
|
70 |
+
|
71 |
+
elif user_info["auth"]["accessToken"]["role"] != "write":
|
72 |
+
return_msg = "Please provide a token with write access"
|
73 |
|
74 |
+
elif user_info["canPay"] is False:
|
75 |
+
return_msg = "Please add a valid payment method in order to create and manage a competition"
|
76 |
|
77 |
+
if return_msg is not None:
|
78 |
+
return [
|
79 |
+
gr.Box.update(visible=False),
|
80 |
+
gr.Markdown.update(value=return_msg, visible=True),
|
81 |
+
gr.Dropdown.update(visible=False),
|
82 |
+
]
|
83 |
|
84 |
+
username = user_info["name"]
|
85 |
+
user_id = user_info["id"]
|
86 |
+
|
87 |
+
orgs = user_info["orgs"]
|
88 |
+
valid_orgs = [org for org in orgs if org["canPay"] is True]
|
89 |
+
valid_orgs = [org for org in valid_orgs if org["roleInOrg"] in ("admin", "write")]
|
90 |
+
|
91 |
+
valid_entities = {org["id"]: org["name"] for org in valid_orgs}
|
92 |
+
valid_entities[user_id] = username
|
93 |
+
|
94 |
+
# reverse the dictionary
|
95 |
+
valid_entities = {v: k for k, v in valid_entities.items()}
|
96 |
+
|
97 |
+
return [
|
98 |
+
gr.Box.update(visible=True),
|
99 |
+
gr.Markdown.update(value="", visible=False),
|
100 |
+
gr.Dropdown.update(choices=list(valid_entities.keys()), visible=True, value=username),
|
101 |
+
]
|
102 |
|
103 |
|
104 |
with gr.Blocks() as demo:
|
|
|
114 |
label="Please enter your Hugging Face token (write access needed)",
|
115 |
type="password",
|
116 |
)
|
117 |
+
login_button = gr.Button("Login")
|
118 |
+
|
119 |
+
message_box = gr.Markdown(visible=False)
|
120 |
+
|
121 |
+
with gr.Box(visible=False) as create_box:
|
122 |
+
who_pays = gr.Dropdown(
|
123 |
+
["Me", "My Organization"],
|
124 |
+
label="Who Pays",
|
125 |
+
value="Me",
|
126 |
+
visible=False,
|
127 |
+
interactive=True,
|
|
|
128 |
)
|
129 |
competition_type = gr.Radio(
|
130 |
["Generic"],
|
|
|
132 |
value="Generic",
|
133 |
)
|
134 |
|
135 |
+
with gr.Row():
|
136 |
+
competition_name = gr.Textbox(
|
137 |
+
max_lines=1,
|
138 |
+
value="",
|
139 |
+
label="Competition Name",
|
140 |
+
placeholder="my-awesome-competition",
|
141 |
+
)
|
142 |
+
eval_metric = gr.Dropdown(
|
143 |
+
["accuracy", "auc", "f1", "logloss", "precision", "recall"],
|
144 |
+
label="Evaluation Metric",
|
145 |
+
value="accuracy",
|
146 |
+
)
|
147 |
+
with gr.Row():
|
148 |
+
submission_limit = gr.Slider(
|
149 |
+
minimum=1,
|
150 |
+
maximum=100,
|
151 |
+
value=5,
|
152 |
+
step=1,
|
153 |
+
label="Submission Limit Per Day",
|
154 |
+
)
|
155 |
+
selection_limit = gr.Slider(
|
156 |
+
minimum=1,
|
157 |
+
maximum=100,
|
158 |
+
value=2,
|
159 |
+
step=1,
|
160 |
+
label="Selection Limit For Final Leaderboard",
|
161 |
+
)
|
162 |
+
end_date = gr.Textbox(
|
163 |
+
max_lines=1,
|
164 |
+
value="",
|
165 |
+
label="End Date (YYYY-MM-DD)",
|
166 |
+
)
|
167 |
with gr.Row():
|
168 |
with gr.Column():
|
169 |
sample_submission_file = gr.File(
|
|
|
175 |
)
|
176 |
gr.Markdown(
|
177 |
"""
|
178 |
+
<p style="text-align: center">
|
179 |
+
<h4>Please note that you will need to upload training and test
|
180 |
data separately to the public repository that will be created.
|
181 |
+
You can also change sample_submission and solution files later.</h4>
|
182 |
+
</p>
|
183 |
"""
|
184 |
)
|
185 |
with gr.Row():
|
186 |
+
create_button = gr.Button("Create Competition")
|
187 |
+
|
188 |
+
login_button.click(
|
189 |
+
check_if_user_can_create_competition, inputs=[user_token], outputs=[create_box, message_box, who_pays]
|
190 |
+
)
|
191 |
+
|
192 |
+
create_inputs = [
|
193 |
+
user_token,
|
194 |
+
who_pays,
|
195 |
+
competition_type,
|
196 |
+
competition_name,
|
197 |
+
eval_metric,
|
198 |
+
submission_limit,
|
199 |
+
selection_limit,
|
200 |
+
end_date,
|
201 |
+
sample_submission_file,
|
202 |
+
solution_file,
|
203 |
+
]
|
204 |
+
create_button.click(create_competition, inputs=create_inputs, outputs=[message_box])
|