Abhishek Thakur
commited on
Commit
·
7624780
1
Parent(s):
cb7ab1b
public private
Browse files- competitions/create.py +39 -28
competitions/create.py
CHANGED
@@ -61,6 +61,7 @@ def create_competition(
|
|
61 |
end_date,
|
62 |
sample_submission_file,
|
63 |
solution_file,
|
|
|
64 |
):
|
65 |
|
66 |
# verify sample submission and solution
|
@@ -97,11 +98,14 @@ def create_competition(
|
|
97 |
visible=True,
|
98 |
)
|
99 |
|
100 |
-
|
101 |
suffix = str(uuid.uuid4())
|
102 |
private_dataset_name = f"{who_pays}/{competition_name}{suffix}"
|
103 |
public_dataset_name = f"{who_pays}/{competition_name}"
|
104 |
-
|
|
|
|
|
|
|
105 |
|
106 |
sample_submission_df = pd.read_csv(sample_submission_file.name)
|
107 |
submission_columns = ",".join(sample_submission_df.columns)
|
@@ -249,7 +253,7 @@ def create_competition(
|
|
249 |
repo_id=space_name,
|
250 |
repo_type="space",
|
251 |
private=False,
|
252 |
-
token=BOT_TOKEN,
|
253 |
space_sdk="docker",
|
254 |
exist_ok=False,
|
255 |
)
|
@@ -263,7 +267,7 @@ def create_competition(
|
|
263 |
path_in_repo="Dockerfile",
|
264 |
repo_id=space_name,
|
265 |
repo_type="space",
|
266 |
-
token=BOT_TOKEN,
|
267 |
)
|
268 |
|
269 |
space_readme = f"""
|
@@ -288,26 +292,26 @@ def create_competition(
|
|
288 |
path_in_repo="README.md",
|
289 |
repo_id=space_name,
|
290 |
repo_type="space",
|
291 |
-
token=BOT_TOKEN,
|
292 |
)
|
293 |
|
294 |
api.add_space_secret(
|
295 |
repo_id=space_name,
|
296 |
key="COMPETITION_ID",
|
297 |
value=private_dataset_name,
|
298 |
-
token=BOT_TOKEN,
|
299 |
)
|
300 |
api.add_space_secret(
|
301 |
repo_id=space_name,
|
302 |
key="AUTOTRAIN_USERNAME",
|
303 |
value=who_pays,
|
304 |
-
token=BOT_TOKEN,
|
305 |
)
|
306 |
api.add_space_secret(
|
307 |
repo_id=space_name,
|
308 |
key="AUTOTRAIN_TOKEN",
|
309 |
value=user_token,
|
310 |
-
token=BOT_TOKEN,
|
311 |
)
|
312 |
|
313 |
return gr.Markdown.update(
|
@@ -317,7 +321,8 @@ def create_competition(
|
|
317 |
<p>Private dataset: <a href="https://hf.co/datasets/{private_dataset_name}">{private_dataset_name}</a></p>
|
318 |
<p>Public dataset: <a href="https://hf.co/datasets/{public_dataset_name}">{public_dataset_name}</a></p>
|
319 |
<p>Competition space: <a href="https://hf.co/spaces/{space_name}">{space_name}</a></p>
|
320 |
-
<p>
|
|
|
321 |
</div>
|
322 |
""",
|
323 |
visible=True,
|
@@ -450,26 +455,31 @@ with gr.Blocks() as demo:
|
|
450 |
value="",
|
451 |
label="End Date (YYYY-MM-DD)",
|
452 |
)
|
453 |
-
with gr.
|
454 |
-
with gr.
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
|
|
|
|
|
|
|
|
463 |
"""
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
|
|
473 |
|
474 |
final_output = gr.Markdown(visible=True)
|
475 |
|
@@ -488,5 +498,6 @@ with gr.Blocks() as demo:
|
|
488 |
end_date,
|
489 |
sample_submission_file,
|
490 |
solution_file,
|
|
|
491 |
]
|
492 |
create_button.click(create_competition, inputs=create_inputs, outputs=[final_output])
|
|
|
61 |
end_date,
|
62 |
sample_submission_file,
|
63 |
solution_file,
|
64 |
+
is_public,
|
65 |
):
|
66 |
|
67 |
# verify sample submission and solution
|
|
|
98 |
visible=True,
|
99 |
)
|
100 |
|
101 |
+
is_public = is_public == "Public"
|
102 |
suffix = str(uuid.uuid4())
|
103 |
private_dataset_name = f"{who_pays}/{competition_name}{suffix}"
|
104 |
public_dataset_name = f"{who_pays}/{competition_name}"
|
105 |
+
if is_public:
|
106 |
+
space_name = f"competitions/{competition_name}"
|
107 |
+
else:
|
108 |
+
space_name = f"{who_pays}/{competition_name}"
|
109 |
|
110 |
sample_submission_df = pd.read_csv(sample_submission_file.name)
|
111 |
submission_columns = ",".join(sample_submission_df.columns)
|
|
|
253 |
repo_id=space_name,
|
254 |
repo_type="space",
|
255 |
private=False,
|
256 |
+
token=BOT_TOKEN if is_public else user_token,
|
257 |
space_sdk="docker",
|
258 |
exist_ok=False,
|
259 |
)
|
|
|
267 |
path_in_repo="Dockerfile",
|
268 |
repo_id=space_name,
|
269 |
repo_type="space",
|
270 |
+
token=BOT_TOKEN if is_public else user_token,
|
271 |
)
|
272 |
|
273 |
space_readme = f"""
|
|
|
292 |
path_in_repo="README.md",
|
293 |
repo_id=space_name,
|
294 |
repo_type="space",
|
295 |
+
token=BOT_TOKEN if is_public else user_token,
|
296 |
)
|
297 |
|
298 |
api.add_space_secret(
|
299 |
repo_id=space_name,
|
300 |
key="COMPETITION_ID",
|
301 |
value=private_dataset_name,
|
302 |
+
token=BOT_TOKEN if is_public else user_token,
|
303 |
)
|
304 |
api.add_space_secret(
|
305 |
repo_id=space_name,
|
306 |
key="AUTOTRAIN_USERNAME",
|
307 |
value=who_pays,
|
308 |
+
token=BOT_TOKEN if is_public else user_token,
|
309 |
)
|
310 |
api.add_space_secret(
|
311 |
repo_id=space_name,
|
312 |
key="AUTOTRAIN_TOKEN",
|
313 |
value=user_token,
|
314 |
+
token=BOT_TOKEN if is_public else user_token,
|
315 |
)
|
316 |
|
317 |
return gr.Markdown.update(
|
|
|
321 |
<p>Private dataset: <a href="https://hf.co/datasets/{private_dataset_name}">{private_dataset_name}</a></p>
|
322 |
<p>Public dataset: <a href="https://hf.co/datasets/{public_dataset_name}">{public_dataset_name}</a></p>
|
323 |
<p>Competition space: <a href="https://hf.co/spaces/{space_name}">{space_name}</a></p>
|
324 |
+
<p>NOTE: for private competitions, please add `autoevaluator` user to your org: {who_pays}.</p>
|
325 |
+
<p>NOTE: Do NOT share the private dataset or link with anyone else.</p>
|
326 |
</div>
|
327 |
""",
|
328 |
visible=True,
|
|
|
455 |
value="",
|
456 |
label="End Date (YYYY-MM-DD)",
|
457 |
)
|
458 |
+
with gr.Box():
|
459 |
+
with gr.Row():
|
460 |
+
with gr.Column():
|
461 |
+
sample_submission_file = gr.File(
|
462 |
+
label="sample_submission.csv",
|
463 |
+
)
|
464 |
+
with gr.Column():
|
465 |
+
solution_file = gr.File(
|
466 |
+
label="solution.csv",
|
467 |
+
)
|
468 |
+
gr.Markdown(
|
469 |
+
"""Please note that you will need to upload training and test
|
470 |
+
data separately to the public repository that will be created.
|
471 |
+
You can also change sample_submission and solution files later.
|
472 |
"""
|
473 |
+
)
|
474 |
+
with gr.Box():
|
475 |
+
with gr.Row():
|
476 |
+
is_public = gr.Dropdown(
|
477 |
+
["Public", "Private"],
|
478 |
+
label="Competition Visibility. Private competitions are only visible to you and your organization members and are created inside your organization. Public competitions are available at hf.co/competitions.",
|
479 |
+
value="Public",
|
480 |
+
)
|
481 |
+
with gr.Row():
|
482 |
+
create_button = gr.Button("Create Competition")
|
483 |
|
484 |
final_output = gr.Markdown(visible=True)
|
485 |
|
|
|
498 |
end_date,
|
499 |
sample_submission_file,
|
500 |
solution_file,
|
501 |
+
is_public,
|
502 |
]
|
503 |
create_button.click(create_competition, inputs=create_inputs, outputs=[final_output])
|