abhishek thakur commited on
Commit
ae02377
Β·
1 Parent(s): e65ebe2

some more fixes

Browse files
Overview.py CHANGED
@@ -1,29 +1,16 @@
1
  import streamlit as st
2
 
 
 
3
  st.set_page_config(
4
  page_title="Overview",
5
  page_icon="πŸ€—",
6
  )
7
 
8
- st.write("# Welcome to Cats vs Dogs! πŸ‘‹")
9
 
10
  st.markdown(
11
- """
12
- In this competition, you will be creating an image classifier that can distinguish between cats and dogs.
13
- You can use any model you want, but we recommend using a pretrained model from the
14
- [πŸ€— Hub](https://huggingface.co/models).
15
-
16
- Rules:
17
- - You can make upto 5 submissions per day.
18
- - The test data has been divided into public and private splits.
19
- - Your score on the public split will be shown on the leaderboard.
20
- - Your final score will be based on your private split performance.
21
- - The final rankings will be based on the private split performance.
22
- - No cheating! You can only use the test data for inference. You cannot use it to train your model.
23
- - No private sharing of code or data. You can discuss the competition on the forums, but please do not share any
24
- code or data.
25
- - Have fun! πŸ€—
26
-
27
- For detailed rules, please check the [rules page](https://huggingface.co/competitions/transformers-cats-vs-dogs).
28
  """
29
  )
 
1
  import streamlit as st
2
 
3
+ import config
4
+
5
  st.set_page_config(
6
  page_title="Overview",
7
  page_icon="πŸ€—",
8
  )
9
 
10
+ st.write(f"# Welcome to {config.competition_info.competition_name}! πŸ‘‹")
11
 
12
  st.markdown(
13
+ f"""
14
+ {config.competition_info.competition_description}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  """
16
  )
config.py CHANGED
@@ -1,8 +1,11 @@
 
1
  import os
2
  from datetime import datetime
3
  from pathlib import Path
4
 
5
  from dotenv import load_dotenv
 
 
6
 
7
  if Path(".env").is_file():
8
  load_dotenv(".env")
@@ -10,13 +13,66 @@ if Path(".env").is_file():
10
 
11
  MOONLANDING_URL = os.getenv("MOONLANDING_URL")
12
  COMPETITION_ID = os.getenv("COMPETITION_ID")
13
- DUMMY_DATA_PATH = os.getenv("DUMMY_DATA_PATH")
14
  AUTOTRAIN_USERNAME = os.getenv("AUTOTRAIN_USERNAME")
15
  AUTOTRAIN_TOKEN = os.getenv("AUTOTRAIN_TOKEN")
16
- HF_ACCESS_TOKEN = os.getenv("HF_ACCESS_TOKEN")
17
  AUTOTRAIN_BACKEND_API = os.getenv("AUTOTRAIN_BACKEND_API")
18
- SUBMISSION_LIMIT = int(os.getenv("SUBMISSION_LIMIT"))
19
- SELECTION_LIMIT = int(os.getenv("SELECTION_LIMIT"))
20
- END_DATE = os.getenv("END_DATE")
21
- END_DATE = datetime.strptime(END_DATE, "%Y-%m-%d")
22
- EVAL_HIGHER_IS_BETTER = True if int(os.getenv("EVAL_HIGHER_IS_BETTER")) == 1 else False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
  import os
3
  from datetime import datetime
4
  from pathlib import Path
5
 
6
  from dotenv import load_dotenv
7
+ from huggingface_hub import hf_hub_download
8
+ from huggingface_hub.utils._errors import EntryNotFoundError
9
 
10
  if Path(".env").is_file():
11
  load_dotenv(".env")
 
13
 
14
  MOONLANDING_URL = os.getenv("MOONLANDING_URL")
15
  COMPETITION_ID = os.getenv("COMPETITION_ID")
 
16
  AUTOTRAIN_USERNAME = os.getenv("AUTOTRAIN_USERNAME")
17
  AUTOTRAIN_TOKEN = os.getenv("AUTOTRAIN_TOKEN")
 
18
  AUTOTRAIN_BACKEND_API = os.getenv("AUTOTRAIN_BACKEND_API")
19
+
20
+
21
+ class CompetitionInfo:
22
+ def __init__(self):
23
+ try:
24
+ config_fname = hf_hub_download(
25
+ repo_id=COMPETITION_ID,
26
+ filename="config.json",
27
+ use_auth_token=AUTOTRAIN_TOKEN,
28
+ repo_type="dataset",
29
+ )
30
+ except EntryNotFoundError:
31
+ raise Exception("Competition config not found. Please check the competition id.")
32
+ except Exception as e:
33
+ print(e)
34
+ raise Exception("Hugging Face Hub is unreachable, please try again later.")
35
+
36
+ self.config = self.load_config(config_fname)
37
+
38
+ def load_config(self, config_path):
39
+ with open(config_path) as f:
40
+ config = json.load(f)
41
+ return config
42
+
43
+ @property
44
+ def submission_limit(self):
45
+ return self.config["SUBMISSION_LIMIT"]
46
+
47
+ @property
48
+ def selection_limit(self):
49
+ return self.config["SELECTION_LIMIT"]
50
+
51
+ @property
52
+ def end_date(self):
53
+ e_d = self.config["END_DATE"]
54
+ return datetime.strptime(e_d, "%Y-%m-%d")
55
+
56
+ @property
57
+ def eval_higher_is_better(self):
58
+ hb = self.config["EVAL_HIGHER_IS_BETTER"]
59
+ return True if int(hb) == 1 else False
60
+
61
+ @property
62
+ def competition_dataset(self):
63
+ return self.config["DATASET"]
64
+
65
+ @property
66
+ def competition_description(self):
67
+ return self.config["COMPETITION_DESCRIPTION"]
68
+
69
+ @property
70
+ def competition_name(self):
71
+ return self.config["COMPETITION_NAME"]
72
+
73
+ @property
74
+ def submission_columns(self):
75
+ return self.config["SUBMISSION_COLUMNS"].split(",")
76
+
77
+
78
+ competition_info = CompetitionInfo()
pages/2_πŸ”₯_New Submission.py CHANGED
@@ -6,7 +6,7 @@ from huggingface_hub import HfApi
6
  import config
7
  import utils
8
 
9
- SUBMISSION_TEXT = """You can make upto 5 submissions per day.
10
  The test data has been divided into public and private splits.
11
  Your score on the public split will be shown on the leaderboard.
12
  Your final score will be based on your private split performance.
@@ -23,7 +23,7 @@ def app():
23
  st.markdown(SUBMISSION_TEXT)
24
  uploaded_file = st.file_uploader("Choose a file")
25
  # user token
26
- user_token = st.text_input("Enter your token", value="", type="password")
27
  user_token = user_token.strip()
28
  if uploaded_file is not None and user_token != "":
29
  # verify token
@@ -49,7 +49,7 @@ def app():
49
  # write a horizontal html line
50
  st.markdown("<hr/>", unsafe_allow_html=True)
51
  else:
52
- with st.spinner("Uploading submission..."):
53
  user_id = user_info["id"]
54
  submission_id = str(uuid.uuid4())
55
  file_extension = uploaded_file.name.split(".")[-1]
@@ -62,18 +62,12 @@ def app():
62
  repo_type="dataset",
63
  token=config.AUTOTRAIN_TOKEN,
64
  )
65
- with st.spinner("Creating submission..."):
66
  # update submission limit
67
  submissions_made = utils.increment_submissions(
68
  user_id=user_id,
69
  submission_id=submission_id,
70
  submission_comment="",
71
  )
72
- st.success(
73
- f"Upload successful! You have {config.SUBMISSION_LIMIT - submissions_made} submissions left for today."
74
- )
75
-
76
- with st.spinner("Scheuling submission for evaluation..."):
77
  # schedule submission for evaluation
78
  utils.create_project(
79
  project_id=f"{submission_id}",
@@ -82,6 +76,7 @@ def app():
82
  model="generic_competition",
83
  )
84
  st.success("Submission scheduled for evaluation")
 
85
 
86
 
87
  if __name__ == "__main__":
 
6
  import config
7
  import utils
8
 
9
+ SUBMISSION_TEXT = f"""You can make upto {config.competition_info.submission_limit} submissions per day.
10
  The test data has been divided into public and private splits.
11
  Your score on the public split will be shown on the leaderboard.
12
  Your final score will be based on your private split performance.
 
23
  st.markdown(SUBMISSION_TEXT)
24
  uploaded_file = st.file_uploader("Choose a file")
25
  # user token
26
+ user_token = st.text_input("Enter your Hugging Face token", value="", type="password")
27
  user_token = user_token.strip()
28
  if uploaded_file is not None and user_token != "":
29
  # verify token
 
49
  # write a horizontal html line
50
  st.markdown("<hr/>", unsafe_allow_html=True)
51
  else:
52
+ with st.spinner("Creating submission... Please wait"):
53
  user_id = user_info["id"]
54
  submission_id = str(uuid.uuid4())
55
  file_extension = uploaded_file.name.split(".")[-1]
 
62
  repo_type="dataset",
63
  token=config.AUTOTRAIN_TOKEN,
64
  )
 
65
  # update submission limit
66
  submissions_made = utils.increment_submissions(
67
  user_id=user_id,
68
  submission_id=submission_id,
69
  submission_comment="",
70
  )
 
 
 
 
 
71
  # schedule submission for evaluation
72
  utils.create_project(
73
  project_id=f"{submission_id}",
 
76
  model="generic_competition",
77
  )
78
  st.success("Submission scheduled for evaluation")
79
+ st.success(f"You have {config.SUBMISSION_LIMIT - submissions_made} submissions left for today.")
80
 
81
 
82
  if __name__ == "__main__":
pages/3_⭐️_Submission History.py CHANGED
@@ -7,7 +7,8 @@ from huggingface_hub.utils._errors import EntryNotFoundError
7
  import config
8
  import utils
9
 
10
- SUBMISSION_TEXT = f"""You can select upto {config.SELECTION_LIMIT} submissions for private leaderboard."""
 
11
 
12
 
13
  def get_subs(user_info, private=False):
 
7
  import config
8
  import utils
9
 
10
+ SUBMISSION_TEXT = f"""You can select upto {config.competition_info.selection_limit}
11
+ submissions for private leaderboard."""
12
 
13
 
14
  def get_subs(user_info, private=False):