Abhishek Thakur
commited on
Commit
·
846ca30
1
Parent(s):
3b208c1
improvements
Browse files- competitions/app.py +14 -2
- competitions/submissions.py +3 -0
- competitions/templates/index.html +8 -6
competitions/app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import datetime
|
2 |
import os
|
3 |
import threading
|
|
|
4 |
|
5 |
from fastapi import Depends, FastAPI, File, Form, HTTPException, Request, UploadFile
|
6 |
from fastapi.responses import HTMLResponse, JSONResponse
|
@@ -75,7 +76,18 @@ def start_job_runner_thread():
|
|
75 |
return thread
|
76 |
|
77 |
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|
81 |
app = FastAPI()
|
@@ -192,7 +204,7 @@ async def fetch_leaderboard(
|
|
192 |
if lb == "private":
|
193 |
current_utc_time = datetime.datetime.now()
|
194 |
if current_utc_time < competition_info.end_date and not is_user_admin:
|
195 |
-
return {"response": "Private leaderboard will be available
|
196 |
df = leaderboard.fetch(private=lb == "private")
|
197 |
|
198 |
if len(df) == 0:
|
|
|
1 |
import datetime
|
2 |
import os
|
3 |
import threading
|
4 |
+
import time
|
5 |
|
6 |
from fastapi import Depends, FastAPI, File, Form, HTTPException, Request, UploadFile
|
7 |
from fastapi.responses import HTMLResponse, JSONResponse
|
|
|
76 |
return thread
|
77 |
|
78 |
|
79 |
+
def watchdog(job_runner_thread):
|
80 |
+
while True:
|
81 |
+
if not job_runner_thread.is_alive():
|
82 |
+
logger.warning("Job runner thread stopped. Restarting...")
|
83 |
+
job_runner_thread = start_job_runner_thread()
|
84 |
+
time.sleep(10)
|
85 |
+
|
86 |
+
|
87 |
+
job_runner_thread = start_job_runner_thread()
|
88 |
+
watchdog_thread = threading.Thread(target=watchdog, args=(job_runner_thread,))
|
89 |
+
watchdog_thread.daemon = True
|
90 |
+
watchdog_thread.start()
|
91 |
|
92 |
|
93 |
app = FastAPI()
|
|
|
204 |
if lb == "private":
|
205 |
current_utc_time = datetime.datetime.now()
|
206 |
if current_utc_time < competition_info.end_date and not is_user_admin:
|
207 |
+
return {"response": f"Private leaderboard will be available on {competition_info.end_date} UTC."}
|
208 |
df = leaderboard.fetch(private=lb == "private")
|
209 |
|
210 |
if len(df) == 0:
|
competitions/submissions.py
CHANGED
@@ -309,6 +309,9 @@ class Submissions:
|
|
309 |
# repo_type="model",
|
310 |
# )
|
311 |
# create barebones submission runner space
|
|
|
|
|
|
|
312 |
competition_organizer = self.competition_id.split("/")[0]
|
313 |
space_id = f"{competition_organizer}/comp-{submission_id}"
|
314 |
api = HfApi(token=self.token)
|
|
|
309 |
# repo_type="model",
|
310 |
# )
|
311 |
# create barebones submission runner space
|
312 |
+
user_api = HfApi(token=user_token)
|
313 |
+
# submission_id is the sha of the submitted model repo
|
314 |
+
submission_id = user_api.model_info(repo_id=uploaded_file).sha
|
315 |
competition_organizer = self.competition_id.split("/")[0]
|
316 |
space_id = f"{competition_organizer}/comp-{submission_id}"
|
317 |
api = HfApi(token=self.token)
|
competitions/templates/index.html
CHANGED
@@ -456,21 +456,23 @@
|
|
456 |
</li>
|
457 |
<li id="loginButton" style="display: none;">
|
458 |
<a href="/login/huggingface"
|
459 |
-
class="flex bg-blue-
|
460 |
-
with
|
461 |
-
|
462 |
-
Face</a>
|
463 |
</li>
|
464 |
<li id="logoutButton" style="display: none;">
|
465 |
<a href="/logout"
|
466 |
-
class="flex bg-red-
|
|
|
|
|
467 |
</li>
|
468 |
</ul>
|
469 |
|
470 |
<footer>
|
471 |
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-between">
|
472 |
<span class="text-sm text-gray-500 sm:text-center">Powered by <a
|
473 |
-
href="https://github.com/huggingface/competitions"
|
|
|
474 |
Competitions</a>
|
475 |
</span>
|
476 |
</div>
|
|
|
456 |
</li>
|
457 |
<li id="loginButton" style="display: none;">
|
458 |
<a href="/login/huggingface"
|
459 |
+
class="flex justify-center items-center bg-blue-400 hover:bg-blue-600 text-white text-center font-bold py-2 px-4 rounded transition duration-200 ease-in-out">
|
460 |
+
Login with Hugging Face
|
461 |
+
</a>
|
|
|
462 |
</li>
|
463 |
<li id="logoutButton" style="display: none;">
|
464 |
<a href="/logout"
|
465 |
+
class="flex justify-center items-center bg-red-400 hover:bg-red-600 text-white text-center font-bold py-2 px-4 rounded transition duration-200 ease-in-out">
|
466 |
+
Logout
|
467 |
+
</a>
|
468 |
</li>
|
469 |
</ul>
|
470 |
|
471 |
<footer>
|
472 |
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-between">
|
473 |
<span class="text-sm text-gray-500 sm:text-center">Powered by <a
|
474 |
+
href="https://github.com/huggingface/competitions" target="_blank"
|
475 |
+
class="hover:underline">Hugging Face
|
476 |
Competitions</a>
|
477 |
</span>
|
478 |
</div>
|