Abhishek Thakur commited on
Commit
4cb6f1b
·
1 Parent(s): be1d7ca

fixes to creator

Browse files
competitions/create.py CHANGED
@@ -4,7 +4,6 @@ import json
4
  import gradio as gr
5
  from huggingface_hub import HfApi
6
  from loguru import logger
7
- from sklearn.metrics import get_scorer_names
8
 
9
  from competitions.utils import user_authentication
10
 
@@ -12,6 +11,7 @@ from competitions.utils import user_authentication
12
  COMPETITION_DESC = """Sample competition description"""
13
  DATASET_DESC = """Sample dataset description"""
14
  SUBMISSION_DESC = """Sample submission description"""
 
15
  SOLUTION_CSV = """
16
  id,pred,split
17
  0,1,public
@@ -66,7 +66,18 @@ HARDWARE_CHOICES = [
66
  "a10g-largex4",
67
  "a100-large",
68
  ]
69
- METRIC_CHOICES = get_scorer_names() + ["custom"]
 
 
 
 
 
 
 
 
 
 
 
70
 
71
 
72
  def check_if_user_can_create_competition(user_token):
@@ -75,7 +86,7 @@ def check_if_user_can_create_competition(user_token):
75
  :param user_token: the user's token
76
  :return: True if the user can create a competition, False otherwise
77
  """
78
- user_info = user_authentication(user_token)
79
  return_msg = None
80
  if "error" in user_info:
81
  return_msg = "Invalid token. You can find your HF token here: https://huggingface.co/settings/tokens"
@@ -118,7 +129,8 @@ def _create_readme(competition_name):
118
  _readme += "colorTo: indigo\n"
119
  _readme += "sdk: docker\n"
120
  _readme += "pinned: false\n"
121
- _readme += "duplicated_from: autotrain-projects/autotrain-advanced\n"
 
122
  _readme += "hf_oauth: true\n"
123
  _readme += "hf_oauth_scopes:\n"
124
  _readme += " - read-repos\n"
@@ -244,6 +256,14 @@ def _create(
244
  repo_type="dataset",
245
  )
246
 
 
 
 
 
 
 
 
 
247
  # create competition space
248
  api.create_repo(
249
  repo_id=f"{organization}/{competition_name}",
 
4
  import gradio as gr
5
  from huggingface_hub import HfApi
6
  from loguru import logger
 
7
 
8
  from competitions.utils import user_authentication
9
 
 
11
  COMPETITION_DESC = """Sample competition description"""
12
  DATASET_DESC = """Sample dataset description"""
13
  SUBMISSION_DESC = """Sample submission description"""
14
+ RULES = """Sample rules"""
15
  SOLUTION_CSV = """
16
  id,pred,split
17
  0,1,public
 
66
  "a10g-largex4",
67
  "a100-large",
68
  ]
69
+ METRIC_CHOICES = [
70
+ "accuracy_score",
71
+ "f1_score",
72
+ "hamming_loss",
73
+ "jaccard_score",
74
+ "log_loss",
75
+ "roc_auc_score",
76
+ "mean_squared_error",
77
+ "mean_absolute_error",
78
+ "r2_score",
79
+ "custom",
80
+ ]
81
 
82
 
83
  def check_if_user_can_create_competition(user_token):
 
86
  :param user_token: the user's token
87
  :return: True if the user can create a competition, False otherwise
88
  """
89
+ user_info = user_authentication(user_token, return_raw=True)
90
  return_msg = None
91
  if "error" in user_info:
92
  return_msg = "Invalid token. You can find your HF token here: https://huggingface.co/settings/tokens"
 
129
  _readme += "colorTo: indigo\n"
130
  _readme += "sdk: docker\n"
131
  _readme += "pinned: false\n"
132
+ _readme += "tags:\n"
133
+ _readme += " - competition\n"
134
  _readme += "hf_oauth: true\n"
135
  _readme += "hf_oauth_scopes:\n"
136
  _readme += " - read-repos\n"
 
256
  repo_type="dataset",
257
  )
258
 
259
+ rules = io.BytesIO(RULES.encode())
260
+ api.upload_file(
261
+ path_or_fileobj=rules,
262
+ path_in_repo="RULES.md",
263
+ repo_id=f"{organization}/{competition_name}",
264
+ repo_type="dataset",
265
+ )
266
+
267
  # create competition space
268
  api.create_repo(
269
  repo_id=f"{organization}/{competition_name}",
competitions/text.py CHANGED
@@ -3,7 +3,6 @@ The test data has been divided into public and private splits.
3
  Your score on the public split will be shown on the leaderboard.
4
  Your final score will be based on your private split performance.
5
  The final rankings will be based on the private split performance.
6
- You can find your Hugging Face token [here](https://huggingface.co/settings/token)
7
  """
8
 
9
  SUBMISSION_ERROR = """Submission is not in a proper format.
 
3
  Your score on the public split will be shown on the leaderboard.
4
  Your final score will be based on your private split performance.
5
  The final rankings will be based on the private split performance.
 
6
  """
7
 
8
  SUBMISSION_ERROR = """Submission is not in a proper format.
competitions/utils.py CHANGED
@@ -15,7 +15,7 @@ from competitions.params import EvalParams
15
  from . import HF_URL
16
 
17
 
18
- def user_authentication(token):
19
  if token.startswith("hf_oauth"):
20
  _api_url = HF_URL + "/oauth/userinfo"
21
  else:
@@ -36,7 +36,11 @@ def user_authentication(token):
36
  except (requests.Timeout, ConnectionError) as err:
37
  logger.error(f"Failed to request whoami-v2 - {repr(err)}")
38
  raise Exception("Hugging Face Hub is unreachable, please try again later.")
 
39
  resp = response.json()
 
 
 
40
  user_info = {}
41
  if "error" in resp:
42
  return resp
 
15
  from . import HF_URL
16
 
17
 
18
+ def user_authentication(token, return_raw=False):
19
  if token.startswith("hf_oauth"):
20
  _api_url = HF_URL + "/oauth/userinfo"
21
  else:
 
36
  except (requests.Timeout, ConnectionError) as err:
37
  logger.error(f"Failed to request whoami-v2 - {repr(err)}")
38
  raise Exception("Hugging Face Hub is unreachable, please try again later.")
39
+
40
  resp = response.json()
41
+ if return_raw:
42
+ return resp
43
+
44
  user_info = {}
45
  if "error" in resp:
46
  return resp