Yuta Nakamura
commited on
Make submission dialogue explain the error in detail (#46)
Browse files- competitions/app.py +10 -0
competitions/app.py
CHANGED
|
@@ -3,6 +3,8 @@ 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
|
| 8 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -302,8 +304,16 @@ async def new_submission(
|
|
| 302 |
if competition_info.competition_type == "script":
|
| 303 |
resp = sub.new_submission(user_token, hub_model, submission_comment)
|
| 304 |
return {"response": f"Success! You have {resp} submissions remaining today."}
|
|
|
|
|
|
|
| 305 |
except AuthenticationError:
|
| 306 |
return {"response": "Invalid token"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
return {"response": "Invalid competition type"}
|
| 308 |
|
| 309 |
|
|
|
|
| 3 |
import threading
|
| 4 |
import time
|
| 5 |
|
| 6 |
+
from requests.exceptions import RequestException
|
| 7 |
+
|
| 8 |
from fastapi import Depends, FastAPI, File, Form, HTTPException, Request, UploadFile
|
| 9 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 10 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 304 |
if competition_info.competition_type == "script":
|
| 305 |
resp = sub.new_submission(user_token, hub_model, submission_comment)
|
| 306 |
return {"response": f"Success! You have {resp} submissions remaining today."}
|
| 307 |
+
except RequestException:
|
| 308 |
+
return {"response": "Hugging Face Hub is unreachable, please try again later"}
|
| 309 |
except AuthenticationError:
|
| 310 |
return {"response": "Invalid token"}
|
| 311 |
+
except PastDeadlineError:
|
| 312 |
+
return {"response": "Competition has ended"}
|
| 313 |
+
except SubmissionError:
|
| 314 |
+
return {"response": "Invalid submission file"}
|
| 315 |
+
except SubmissionLimitError:
|
| 316 |
+
return {"response": "Submission limit reached"}
|
| 317 |
return {"response": "Invalid competition type"}
|
| 318 |
|
| 319 |
|