Abhishek Thakur
commited on
Commit
·
683946e
1
Parent(s):
846ca30
add submit cli
Browse files- Dockerfile +1 -0
- competitions/cli/competitions.py +2 -0
- competitions/cli/submit.py +49 -0
- competitions/utils.py +14 -0
- requirements.txt +13 -30
- requirements_docker.txt +17 -0
Dockerfile
CHANGED
|
@@ -73,3 +73,4 @@ RUN make socket-kit.so
|
|
| 73 |
ENV PATH="/app:${PATH}"
|
| 74 |
|
| 75 |
RUN pip install -e .
|
|
|
|
|
|
| 73 |
ENV PATH="/app:${PATH}"
|
| 74 |
|
| 75 |
RUN pip install -e .
|
| 76 |
+
RUN pip install -r requirements_docker.txt
|
competitions/cli/competitions.py
CHANGED
|
@@ -3,6 +3,7 @@ import argparse
|
|
| 3 |
from .. import __version__
|
| 4 |
from .create import CreateCompetitionAppCommand
|
| 5 |
from .run import RunCompetitionsAppCommand
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def main():
|
|
@@ -17,6 +18,7 @@ def main():
|
|
| 17 |
# Register commands
|
| 18 |
RunCompetitionsAppCommand.register_subcommand(commands_parser)
|
| 19 |
CreateCompetitionAppCommand.register_subcommand(commands_parser)
|
|
|
|
| 20 |
|
| 21 |
args = parser.parse_args()
|
| 22 |
|
|
|
|
| 3 |
from .. import __version__
|
| 4 |
from .create import CreateCompetitionAppCommand
|
| 5 |
from .run import RunCompetitionsAppCommand
|
| 6 |
+
from .submit import SubmitCompetitionAppCommand
|
| 7 |
|
| 8 |
|
| 9 |
def main():
|
|
|
|
| 18 |
# Register commands
|
| 19 |
RunCompetitionsAppCommand.register_subcommand(commands_parser)
|
| 20 |
CreateCompetitionAppCommand.register_subcommand(commands_parser)
|
| 21 |
+
SubmitCompetitionAppCommand.register_subcommand(commands_parser)
|
| 22 |
|
| 23 |
args = parser.parse_args()
|
| 24 |
|
competitions/cli/submit.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from argparse import ArgumentParser
|
| 3 |
+
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
from . import BaseCompetitionsCommand
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def submit_commands_factory(args):
|
| 10 |
+
return SubmitCompetitionAppCommand(args)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class SubmitCompetitionAppCommand(BaseCompetitionsCommand):
|
| 14 |
+
def __init__(self, args):
|
| 15 |
+
self.args = args
|
| 16 |
+
|
| 17 |
+
@staticmethod
|
| 18 |
+
def register_subcommand(parser: ArgumentParser):
|
| 19 |
+
submit_competition_parser = parser.add_parser("submit", description="Submit to a competition")
|
| 20 |
+
submit_competition_parser.add_argument(
|
| 21 |
+
"--competition_id", type=str, help="ID of the competition, e.g. huggingface/cool-competition"
|
| 22 |
+
)
|
| 23 |
+
submit_competition_parser.add_argument(
|
| 24 |
+
"--submission", type=str, help="Path to submission file or HuggingFace hub repo"
|
| 25 |
+
)
|
| 26 |
+
submit_competition_parser.add_argument("--comment", type=str, help="Submission comment", default="")
|
| 27 |
+
submit_competition_parser.add_argument("--token", type=str, help="User token, read-only", default="")
|
| 28 |
+
submit_competition_parser.set_defaults(func=submit_commands_factory)
|
| 29 |
+
|
| 30 |
+
def run(self):
|
| 31 |
+
if os.path.isfile(self.args.submission):
|
| 32 |
+
files = {"submission_file": open(self.args.submission, "rb")}
|
| 33 |
+
data = {
|
| 34 |
+
"hub_model": "",
|
| 35 |
+
"submission_comment": self.args.comment,
|
| 36 |
+
}
|
| 37 |
+
else:
|
| 38 |
+
files = {"submission_file": None}
|
| 39 |
+
data = {
|
| 40 |
+
"hub_model": self.args.submission,
|
| 41 |
+
"submission_comment": self.args.comment,
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
headers = {"Authorization": f"Bearer {self.args.token}"}
|
| 45 |
+
|
| 46 |
+
api_url = "https://" + self.args.competition_id.replace("/", "-") + ".hf.space/new_submission"
|
| 47 |
+
|
| 48 |
+
response = requests.post(api_url, data=data, files=files, headers=headers)
|
| 49 |
+
print(response.json())
|
competitions/utils.py
CHANGED
|
@@ -60,6 +60,20 @@ def token_information(token):
|
|
| 60 |
|
| 61 |
|
| 62 |
def user_authentication(request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
if USER_TOKEN is not None:
|
| 64 |
try:
|
| 65 |
_ = token_information(token=USER_TOKEN)
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
def user_authentication(request: Request):
|
| 63 |
+
auth_header = request.headers.get("Authorization")
|
| 64 |
+
bearer_token = None
|
| 65 |
+
|
| 66 |
+
if auth_header and auth_header.startswith("Bearer "):
|
| 67 |
+
bearer_token = auth_header.split(" ")[1]
|
| 68 |
+
|
| 69 |
+
if bearer_token:
|
| 70 |
+
try:
|
| 71 |
+
_ = token_information(token=bearer_token)
|
| 72 |
+
return bearer_token
|
| 73 |
+
except Exception as e:
|
| 74 |
+
logger.error(f"Failed to verify token: {e}")
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
if USER_TOKEN is not None:
|
| 78 |
try:
|
| 79 |
_ = token_information(token=USER_TOKEN)
|
requirements.txt
CHANGED
|
@@ -1,34 +1,17 @@
|
|
| 1 |
# essentials
|
| 2 |
-
fastapi==0.
|
| 3 |
-
joblib==1.
|
| 4 |
loguru==0.7.2
|
| 5 |
-
pandas==2.
|
| 6 |
-
huggingface_hub==0.
|
| 7 |
tabulate==0.9.0
|
| 8 |
-
markdown==3.
|
| 9 |
-
psutil==
|
| 10 |
-
python-multipart==0.0.
|
| 11 |
-
uvicorn==0.
|
| 12 |
-
py7zr==0.
|
| 13 |
-
pydantic==2.
|
| 14 |
-
gradio==4.
|
| 15 |
-
authlib==1.3.
|
| 16 |
-
itsdangerous==2.
|
| 17 |
hf-transfer
|
| 18 |
-
# machine learning libs
|
| 19 |
-
scikit-learn==1.3.2
|
| 20 |
-
jiwer==3.0.2
|
| 21 |
-
sacremoses==0.0.53
|
| 22 |
-
sentencepiece==0.1.99
|
| 23 |
-
xgboost==1.7.6
|
| 24 |
-
nltk==3.8.1
|
| 25 |
-
optuna==3.3.0
|
| 26 |
-
einops==0.6.1
|
| 27 |
-
peft==0.7.1
|
| 28 |
-
trl==0.7.4
|
| 29 |
-
tiktoken==0.5.1
|
| 30 |
-
transformers==4.37.0
|
| 31 |
-
accelerate==0.25.0
|
| 32 |
-
diffusers==0.21.4
|
| 33 |
-
bitsandbytes==0.41.0
|
| 34 |
-
tqdm==4.65.0
|
|
|
|
| 1 |
# essentials
|
| 2 |
+
fastapi==0.111.0
|
| 3 |
+
joblib==1.4.2
|
| 4 |
loguru==0.7.2
|
| 5 |
+
pandas==2.2.2
|
| 6 |
+
huggingface_hub==0.23.4
|
| 7 |
tabulate==0.9.0
|
| 8 |
+
markdown==3.6
|
| 9 |
+
psutil==6.0.0
|
| 10 |
+
python-multipart==0.0.9
|
| 11 |
+
uvicorn==0.30.1
|
| 12 |
+
py7zr==0.21.1
|
| 13 |
+
pydantic==2.8.2
|
| 14 |
+
gradio==4.37.2
|
| 15 |
+
authlib==1.3.1
|
| 16 |
+
itsdangerous==2.2.0
|
| 17 |
hf-transfer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements_docker.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# machine learning libs
|
| 2 |
+
scikit-learn==1.5.1
|
| 3 |
+
jiwer==3.0.4
|
| 4 |
+
sacremoses==0.1.1
|
| 5 |
+
sentencepiece==0.2.0
|
| 6 |
+
xgboost==2.1.0
|
| 7 |
+
nltk==3.8.1
|
| 8 |
+
optuna==3.6.1
|
| 9 |
+
einops==0.8.0
|
| 10 |
+
peft==0.11.1
|
| 11 |
+
trl==0.9.6
|
| 12 |
+
tiktoken==0.7.0
|
| 13 |
+
transformers==4.42.3
|
| 14 |
+
accelerate==0.32.1
|
| 15 |
+
diffusers==0.29.2
|
| 16 |
+
bitsandbytes==0.43.1
|
| 17 |
+
tqdm==4.66.4
|