Abhishek Thakur
commited on
Commit
·
41baea7
1
Parent(s):
2ff74ac
update
Browse files- competitions/cli/competitions.py +2 -0
- competitions/cli/create.py +19 -0
- competitions/create.py +122 -0
competitions/cli/competitions.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import argparse
|
| 2 |
|
| 3 |
from .. import __version__
|
|
|
|
| 4 |
from .run import RunCompetitionsAppCommand
|
| 5 |
|
| 6 |
|
|
@@ -15,6 +16,7 @@ def main():
|
|
| 15 |
|
| 16 |
# Register commands
|
| 17 |
RunCompetitionsAppCommand.register_subcommand(commands_parser)
|
|
|
|
| 18 |
|
| 19 |
args = parser.parse_args()
|
| 20 |
|
|
|
|
| 1 |
import argparse
|
| 2 |
|
| 3 |
from .. import __version__
|
| 4 |
+
from .create import CreateCompetitionAppCommand
|
| 5 |
from .run import RunCompetitionsAppCommand
|
| 6 |
|
| 7 |
|
|
|
|
| 16 |
|
| 17 |
# Register commands
|
| 18 |
RunCompetitionsAppCommand.register_subcommand(commands_parser)
|
| 19 |
+
CreateCompetitionAppCommand.register_subcommand(commands_parser)
|
| 20 |
|
| 21 |
args = parser.parse_args()
|
| 22 |
|
competitions/cli/create.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from argparse import ArgumentParser
|
| 2 |
+
|
| 3 |
+
from . import BaseCompetitionsCommand
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def create_command_factory(args):
|
| 7 |
+
return CreateCompetitionAppCommand()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class CreateCompetitionAppCommand(BaseCompetitionsCommand):
|
| 11 |
+
@staticmethod
|
| 12 |
+
def register_subcommand(parser: ArgumentParser):
|
| 13 |
+
create_project_parser = parser.add_parser("create", description="✨ Create a new competition")
|
| 14 |
+
create_project_parser.set_defaults(func=create_command_factory)
|
| 15 |
+
|
| 16 |
+
def run(self):
|
| 17 |
+
from ..create import demo
|
| 18 |
+
|
| 19 |
+
demo.queue(concurrency_count=50).launch()
|
competitions/create.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from .utils import user_authentication
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
"""
|
| 7 |
+
To create a competition, follow these steps:
|
| 8 |
+
1. create a private dataset which has the following structure:
|
| 9 |
+
- conf.json
|
| 10 |
+
- solution.csv
|
| 11 |
+
- COMPETITION_DESC.md
|
| 12 |
+
- DATASET_DESC.md
|
| 13 |
+
2. create a public dataset which consists of the following files:
|
| 14 |
+
- sample_submission.csv
|
| 15 |
+
- test.csv
|
| 16 |
+
- train.csv
|
| 17 |
+
- anything else
|
| 18 |
+
3. create a competition space
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def check_if_user_can_create_competition(user_token):
|
| 23 |
+
"""
|
| 24 |
+
Check if the user can create a competition
|
| 25 |
+
:param user_token: the user's 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 |
+
raise Exception("Invalid token. You can find your HF token here: https://huggingface.co/settings/tokens")
|
| 32 |
+
|
| 33 |
+
if user_info["auth"]["accessToken"]["role"] != "write":
|
| 34 |
+
raise Exception("Please provide a token with write access")
|
| 35 |
+
|
| 36 |
+
if user_info["canPay"] is False:
|
| 37 |
+
raise Exception("Please add a valid payment method in order to create and manage a competition")
|
| 38 |
+
|
| 39 |
+
return [gr.Box.update(visible=True)]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
with gr.Blocks() as demo:
|
| 43 |
+
gr.Markdown(
|
| 44 |
+
"""
|
| 45 |
+
<div style="text-align: center">
|
| 46 |
+
<h1>Hugging Face Competition Creator</h1>
|
| 47 |
+
"""
|
| 48 |
+
)
|
| 49 |
+
user_token = gr.Textbox(
|
| 50 |
+
max_lines=1,
|
| 51 |
+
value="",
|
| 52 |
+
label="Please enter your Hugging Face token (write access needed)",
|
| 53 |
+
type="password",
|
| 54 |
+
)
|
| 55 |
+
org_name = gr.Textbox(
|
| 56 |
+
max_lines=1,
|
| 57 |
+
value="",
|
| 58 |
+
label="Please enter your username/organization name where the competition datasets will be hosted. Leave blank if you want to create a competition space in your personal account.",
|
| 59 |
+
)
|
| 60 |
+
with gr.Box():
|
| 61 |
+
gr.Markdown(
|
| 62 |
+
"""
|
| 63 |
+
Pricing:
|
| 64 |
+
- Generic: $0.50 per submission
|
| 65 |
+
- Hub Model: Coming Soon!
|
| 66 |
+
"""
|
| 67 |
+
)
|
| 68 |
+
competition_type = gr.Radio(
|
| 69 |
+
["Generic"],
|
| 70 |
+
label="Competition Type",
|
| 71 |
+
value="Generic",
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
with gr.Box():
|
| 75 |
+
competition_name = gr.Textbox(
|
| 76 |
+
max_lines=1,
|
| 77 |
+
value="",
|
| 78 |
+
label="Competition Name",
|
| 79 |
+
placeholder="my-awesome-competition",
|
| 80 |
+
)
|
| 81 |
+
eval_metric = gr.Dropdown(
|
| 82 |
+
["accuracy", "auc", "f1", "logloss", "precision", "recall"],
|
| 83 |
+
label="Evaluation Metric",
|
| 84 |
+
value="accuracy",
|
| 85 |
+
)
|
| 86 |
+
submission_limit = gr.Slider(
|
| 87 |
+
minimum=1,
|
| 88 |
+
maximum=100,
|
| 89 |
+
value=5,
|
| 90 |
+
step=1,
|
| 91 |
+
label="Submission Limit Per Day",
|
| 92 |
+
)
|
| 93 |
+
selection_limit = gr.Slider(
|
| 94 |
+
minimum=1,
|
| 95 |
+
maximum=100,
|
| 96 |
+
value=2,
|
| 97 |
+
step=1,
|
| 98 |
+
label="Selection Limit For Final Leaderboard",
|
| 99 |
+
)
|
| 100 |
+
end_date = gr.Textbox(
|
| 101 |
+
max_lines=1,
|
| 102 |
+
value="",
|
| 103 |
+
label="End Date (YYYY-MM-DD)",
|
| 104 |
+
)
|
| 105 |
+
with gr.Row():
|
| 106 |
+
with gr.Column():
|
| 107 |
+
sample_submission_file = gr.File(
|
| 108 |
+
label="sample_submission.csv",
|
| 109 |
+
)
|
| 110 |
+
with gr.Column():
|
| 111 |
+
solution_file = gr.File(
|
| 112 |
+
label="solution.csv",
|
| 113 |
+
)
|
| 114 |
+
gr.Markdown(
|
| 115 |
+
"""
|
| 116 |
+
Please note that you will need to upload training and test
|
| 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")
|