Abhishek Thakur
commited on
Commit
·
f5d4c87
1
Parent(s):
90724cf
requirements.txt
Browse files- .dockerignore +2 -0
- .gitignore +2 -0
- competitions/app.py +19 -0
- competitions/evaluate.py +16 -1
- competitions/utils.py +58 -0
- install.txt +2 -0
- uninstall.txt +2 -0
.dockerignore
CHANGED
|
@@ -5,6 +5,8 @@
|
|
| 5 |
flagged/
|
| 6 |
*.csv
|
| 7 |
*.db
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Byte-compiled / optimized / DLL files
|
| 10 |
__pycache__/
|
|
|
|
| 5 |
flagged/
|
| 6 |
*.csv
|
| 7 |
*.db
|
| 8 |
+
install.txt
|
| 9 |
+
uninstall.txt
|
| 10 |
|
| 11 |
# Byte-compiled / optimized / DLL files
|
| 12 |
__pycache__/
|
.gitignore
CHANGED
|
@@ -5,6 +5,8 @@
|
|
| 5 |
flagged/
|
| 6 |
*.csv
|
| 7 |
*.db
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Byte-compiled / optimized / DLL files
|
| 10 |
__pycache__/
|
|
|
|
| 5 |
flagged/
|
| 6 |
*.csv
|
| 7 |
*.db
|
| 8 |
+
install.txt
|
| 9 |
+
uninstall.txt
|
| 10 |
|
| 11 |
# Byte-compiled / optimized / DLL files
|
| 12 |
__pycache__/
|
competitions/app.py
CHANGED
|
@@ -7,10 +7,13 @@ from fastapi import FastAPI, File, Form, Request, UploadFile
|
|
| 7 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 8 |
from fastapi.staticfiles import StaticFiles
|
| 9 |
from fastapi.templating import Jinja2Templates
|
|
|
|
| 10 |
from huggingface_hub.utils import disable_progress_bars
|
|
|
|
| 11 |
from loguru import logger
|
| 12 |
from pydantic import BaseModel
|
| 13 |
|
|
|
|
| 14 |
from competitions.errors import AuthenticationError
|
| 15 |
from competitions.info import CompetitionInfo
|
| 16 |
from competitions.leaderboard import Leaderboard
|
|
@@ -29,6 +32,22 @@ disable_progress_bars()
|
|
| 29 |
COMP_INFO = CompetitionInfo(competition_id=COMPETITION_ID, autotrain_token=HF_TOKEN)
|
| 30 |
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
class User(BaseModel):
|
| 33 |
user_token: str
|
| 34 |
|
|
|
|
| 7 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 8 |
from fastapi.staticfiles import StaticFiles
|
| 9 |
from fastapi.templating import Jinja2Templates
|
| 10 |
+
from huggingface_hub import hf_hub_download
|
| 11 |
from huggingface_hub.utils import disable_progress_bars
|
| 12 |
+
from huggingface_hub.utils._errors import EntryNotFoundError
|
| 13 |
from loguru import logger
|
| 14 |
from pydantic import BaseModel
|
| 15 |
|
| 16 |
+
from competitions import utils
|
| 17 |
from competitions.errors import AuthenticationError
|
| 18 |
from competitions.info import CompetitionInfo
|
| 19 |
from competitions.leaderboard import Leaderboard
|
|
|
|
| 32 |
COMP_INFO = CompetitionInfo(competition_id=COMPETITION_ID, autotrain_token=HF_TOKEN)
|
| 33 |
|
| 34 |
|
| 35 |
+
try:
|
| 36 |
+
REQUIREMENTS_FNAME = hf_hub_download(
|
| 37 |
+
repo_id=COMPETITION_ID,
|
| 38 |
+
filename="requirements.txt",
|
| 39 |
+
token=HF_TOKEN,
|
| 40 |
+
repo_type="dataset",
|
| 41 |
+
)
|
| 42 |
+
except EntryNotFoundError:
|
| 43 |
+
REQUIREMENTS_FNAME = None
|
| 44 |
+
|
| 45 |
+
if REQUIREMENTS_FNAME:
|
| 46 |
+
logger.info("Uninstalling and installing requirements")
|
| 47 |
+
utils.uninstall_requirements(REQUIREMENTS_FNAME)
|
| 48 |
+
utils.install_requirements(REQUIREMENTS_FNAME)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
class User(BaseModel):
|
| 52 |
user_token: str
|
| 53 |
|
competitions/evaluate.py
CHANGED
|
@@ -4,7 +4,8 @@ import os
|
|
| 4 |
import shutil
|
| 5 |
import subprocess
|
| 6 |
|
| 7 |
-
from huggingface_hub import HfApi, Repository, snapshot_download
|
|
|
|
| 8 |
from loguru import logger
|
| 9 |
|
| 10 |
from competitions import utils
|
|
@@ -81,6 +82,20 @@ def run(params):
|
|
| 81 |
utils.update_submission_status(params, "processing")
|
| 82 |
|
| 83 |
if params.competition_type == "script":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
_ = Repository(local_dir="/tmp/data", clone_from=params.dataset, token=params.token)
|
| 85 |
generate_submission_file(params)
|
| 86 |
|
|
|
|
| 4 |
import shutil
|
| 5 |
import subprocess
|
| 6 |
|
| 7 |
+
from huggingface_hub import HfApi, Repository, hf_hub_download, snapshot_download
|
| 8 |
+
from huggingface_hub.utils._errors import EntryNotFoundError
|
| 9 |
from loguru import logger
|
| 10 |
|
| 11 |
from competitions import utils
|
|
|
|
| 82 |
utils.update_submission_status(params, "processing")
|
| 83 |
|
| 84 |
if params.competition_type == "script":
|
| 85 |
+
try:
|
| 86 |
+
requirements_fname = hf_hub_download(
|
| 87 |
+
repo_id=params.competition_id,
|
| 88 |
+
filename="requirements.txt",
|
| 89 |
+
token=params.token,
|
| 90 |
+
repo_type="dataset",
|
| 91 |
+
)
|
| 92 |
+
except EntryNotFoundError:
|
| 93 |
+
requirements_fname = None
|
| 94 |
+
|
| 95 |
+
if requirements_fname:
|
| 96 |
+
logger.info("Installing requirements")
|
| 97 |
+
utils.uninstall_requirements(requirements_fname)
|
| 98 |
+
utils.install_requirements(requirements_fname)
|
| 99 |
_ = Repository(local_dir="/tmp/data", clone_from=params.dataset, token=params.token)
|
| 100 |
generate_submission_file(params)
|
| 101 |
|
competitions/utils.py
CHANGED
|
@@ -133,3 +133,61 @@ def monitor(func):
|
|
| 133 |
pause_space(params)
|
| 134 |
|
| 135 |
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
pause_space(params)
|
| 134 |
|
| 135 |
return wrapper
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def uninstall_requirements(requirements_fname):
|
| 139 |
+
if os.path.exists(requirements_fname):
|
| 140 |
+
# read the requirements.txt
|
| 141 |
+
uninstall_list = []
|
| 142 |
+
with open(requirements_fname, "r", encoding="utf-8") as f:
|
| 143 |
+
for line in f:
|
| 144 |
+
if line.startswith("-"):
|
| 145 |
+
uninstall_list.append(line[1:])
|
| 146 |
+
|
| 147 |
+
# create an uninstall.txt
|
| 148 |
+
with open("uninstall.txt", "w", encoding="utf-8") as f:
|
| 149 |
+
for line in uninstall_list:
|
| 150 |
+
f.write(line)
|
| 151 |
+
|
| 152 |
+
pipe = subprocess.Popen(
|
| 153 |
+
[
|
| 154 |
+
"pip",
|
| 155 |
+
"uninstall",
|
| 156 |
+
"-r",
|
| 157 |
+
"uninstall.txt",
|
| 158 |
+
"-y",
|
| 159 |
+
],
|
| 160 |
+
)
|
| 161 |
+
pipe.wait()
|
| 162 |
+
logger.info("Requirements uninstalled.")
|
| 163 |
+
return
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def install_requirements(requirements_fname):
|
| 167 |
+
# check if params.project_name has a requirements.txt
|
| 168 |
+
if os.path.exists(requirements_fname):
|
| 169 |
+
# install the requirements using subprocess, wait for it to finish
|
| 170 |
+
install_list = []
|
| 171 |
+
|
| 172 |
+
with open(requirements_fname, "r", encoding="utf-8") as f:
|
| 173 |
+
for line in f:
|
| 174 |
+
if not line.startswith("-"):
|
| 175 |
+
install_list.append(line)
|
| 176 |
+
|
| 177 |
+
with open("install.txt", "w", encoding="utf-8") as f:
|
| 178 |
+
for line in install_list:
|
| 179 |
+
f.write(line)
|
| 180 |
+
|
| 181 |
+
pipe = subprocess.Popen(
|
| 182 |
+
[
|
| 183 |
+
"pip",
|
| 184 |
+
"install",
|
| 185 |
+
"-r",
|
| 186 |
+
"install.txt",
|
| 187 |
+
],
|
| 188 |
+
)
|
| 189 |
+
pipe.wait()
|
| 190 |
+
logger.info("Requirements installed.")
|
| 191 |
+
return
|
| 192 |
+
logger.info("No requirements.txt found. Skipping requirements installation.")
|
| 193 |
+
return
|
install.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
xgboost
|
| 2 |
+
git+https://github.com/abhishekkrthakur/autoxgb
|
uninstall.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
xgboost
|
| 2 |
+
pandas
|