Abhishek Thakur commited on
Commit
a04edc8
·
1 Parent(s): 1f822b1

testing period for organizers

Browse files
Files changed (2) hide show
  1. competitions/app.py +9 -1
  2. competitions/utils.py +9 -0
competitions/app.py CHANGED
@@ -25,6 +25,7 @@ HF_TOKEN = os.environ.get("HF_TOKEN", None)
25
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
26
  COMPETITION_ID = os.getenv("COMPETITION_ID")
27
  OUTPUT_PATH = os.getenv("OUTPUT_PATH", "/tmp/model")
 
28
 
29
  disable_progress_bars()
30
 
@@ -184,6 +185,13 @@ async def new_submission(
184
  if submission_comment is None:
185
  submission_comment = ""
186
 
 
 
 
 
 
 
 
187
  sub = Submissions(
188
  end_date=COMP_INFO.end_date,
189
  submission_limit=COMP_INFO.submission_limit,
@@ -196,7 +204,7 @@ async def new_submission(
196
  if COMP_INFO.competition_type == "generic":
197
  resp = sub.new_submission(token, submission_file, submission_comment)
198
  return {"response": f"Success! You have {resp} submissions remaining today."}
199
- elif COMP_INFO.competition_type == "script":
200
  resp = sub.new_submission(token, hub_model, submission_comment)
201
  return {"response": f"Success! You have {resp} submissions remaining today."}
202
  except AuthenticationError:
 
25
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
26
  COMPETITION_ID = os.getenv("COMPETITION_ID")
27
  OUTPUT_PATH = os.getenv("OUTPUT_PATH", "/tmp/model")
28
+ START_DATE = os.getenv("START_DATE", "2000-12-1")
29
 
30
  disable_progress_bars()
31
 
 
185
  if submission_comment is None:
186
  submission_comment = ""
187
 
188
+ todays_date = datetime.datetime.now()
189
+ start_date = datetime.datetime.strptime(START_DATE, "%Y-%m-%d")
190
+ if todays_date < start_date:
191
+ comp_org = COMPETITION_ID.split("/")[0]
192
+ if not utils.can_user_submit_before_start(token, comp_org):
193
+ return {"response": "Competition has not started yet!"}
194
+
195
  sub = Submissions(
196
  end_date=COMP_INFO.end_date,
197
  submission_limit=COMP_INFO.submission_limit,
 
204
  if COMP_INFO.competition_type == "generic":
205
  resp = sub.new_submission(token, submission_file, submission_comment)
206
  return {"response": f"Success! You have {resp} submissions remaining today."}
207
+ if COMP_INFO.competition_type == "script":
208
  resp = sub.new_submission(token, hub_model, submission_comment)
209
  return {"response": f"Success! You have {resp} submissions remaining today."}
210
  except AuthenticationError:
competitions/utils.py CHANGED
@@ -202,3 +202,12 @@ def install_requirements(requirements_fname):
202
  return
203
  logger.info("No requirements.txt found. Skipping requirements installation.")
204
  return
 
 
 
 
 
 
 
 
 
 
202
  return
203
  logger.info("No requirements.txt found. Skipping requirements installation.")
204
  return
205
+
206
+
207
+ def can_user_submit_before_start(user_token, competition_organization):
208
+ user_info = user_authentication(token=user_token)
209
+ user_orgs = user_info.get("orgs", [])
210
+ for org in user_orgs:
211
+ if org["name"] == competition_organization:
212
+ return True
213
+ return False