hmacdope commited on
Commit
732f90d
·
1 Parent(s): be49025

add throttle

Browse files
Files changed (2) hide show
  1. about.py +1 -0
  2. evaluate.py +12 -1
about.py CHANGED
@@ -31,6 +31,7 @@ multiplier_dict = {"LogD": 1,
31
 
32
  TOKEN = os.environ.get("HF_TOKEN")
33
  CACHE_PATH=os.getenv("HF_HOME", ".")
 
34
  API = HfApi(token=TOKEN)
35
  organization="OpenADMET"
36
  submissions_repo = f'{organization}/openadmet-expansionrx-challenge-submissions' # private
 
31
 
32
  TOKEN = os.environ.get("HF_TOKEN")
33
  CACHE_PATH=os.getenv("HF_HOME", ".")
34
+ THROTTLE_MINUTES = 480 # minutes between submissions
35
  API = HfApi(token=TOKEN)
36
  organization="OpenADMET"
37
  submissions_repo = f'{organization}/openadmet-expansionrx-challenge-submissions' # private
evaluate.py CHANGED
@@ -8,8 +8,9 @@ from about import (
8
  results_repo,
9
  test_repo,
10
  multiplier_dict,
 
11
  )
12
- from utils import bootstrap_metrics, convert_to_log
13
  from huggingface_hub import hf_hub_download
14
  import datetime
15
  import io
@@ -107,6 +108,16 @@ def submit_data(predictions_file: str,
107
  if user_state is None:
108
  raise gr.Error("Username or alias is required for submission.")
109
 
 
 
 
 
 
 
 
 
 
 
110
  file_path = Path(predictions_file).resolve()
111
  if not file_path.exists():
112
  raise gr.Error("Uploaded file object does not have a valid file path.")
 
8
  results_repo,
9
  test_repo,
10
  multiplier_dict,
11
+ THROTTLE_MINUTES
12
  )
13
+ from utils import bootstrap_metrics, convert_to_log, fetch_dataset_df
14
  from huggingface_hub import hf_hub_download
15
  import datetime
16
  import io
 
108
  if user_state is None:
109
  raise gr.Error("Username or alias is required for submission.")
110
 
111
+
112
+ # check the last time the user submitted
113
+ data = fetch_dataset_df()
114
+ if not data[data['user'] == user_state].empty:
115
+ last_time = data[data['user'] == user_state]['submission time'].max()
116
+ delta = datetime.datetime.now(datetime.timezone.utc) - last_time.to_pydatetime()
117
+ if delta < datetime.timedelta(minutes=THROTTLE_MINUTES):
118
+ raise gr.Error(f"You have submitted within the last {THROTTLE_MINUTES} minutes. Please wait {THROTTLE_MINUTES - int(delta.total_seconds() // 60)} minutes before submitting again.")
119
+
120
+
121
  file_path = Path(predictions_file).resolve()
122
  if not file_path.exists():
123
  raise gr.Error("Uploaded file object does not have a valid file path.")