hSterz commited on
Commit
78a1bcb
·
1 Parent(s): b977ee0
Files changed (2) hide show
  1. app.py +30 -6
  2. src/submission/submit.py +27 -56
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import gradio as gr
2
  from pathlib import Path
3
  from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
@@ -80,10 +82,13 @@ def init_leaderboard(dataframe):
80
  interactive=False,
81
  )
82
 
83
- def upload_file(filepath):
84
- name = Path(filepath).name
85
- return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
86
-
 
 
 
87
 
88
  demo = gr.Blocks(css=custom_css)
89
  with demo:
@@ -142,12 +147,31 @@ with demo:
142
  )
143
  with gr.Row():
144
  gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
 
 
 
 
 
145
 
146
  with gr.Row():
147
  u = gr.UploadButton("Upload a file", file_count="single")
148
- d = gr.DownloadButton("Download the file", visible=False)
149
 
150
- u.upload(upload_file, u, [u, d])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
 
153
 
 
1
+ import os
2
+ import shutil
3
  import gradio as gr
4
  from pathlib import Path
5
  from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
 
82
  interactive=False,
83
  )
84
 
85
+ # def upload_file(file):
86
+ # UPLOAD_FOLDER = "./data"
87
+ # if not os.path.exists(UPLOAD_FOLDER):
88
+ # os.mkdir(UPLOAD_FOLDER)
89
+
90
+ # shutil.copy(file, UPLOAD_FOLDER)
91
+ # gr.Info("File Uploaded!!!")
92
 
93
  demo = gr.Blocks(css=custom_css)
94
  with demo:
 
147
  )
148
  with gr.Row():
149
  gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
150
+ with gr.Row():
151
+ with gr.Column():
152
+ model_name_textbox = gr.Textbox(label="Model name")
153
+ revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
154
+ output_format = gr.Textbox(label="Output format", placeholder="Out-GEN")
155
 
156
  with gr.Row():
157
  u = gr.UploadButton("Upload a file", file_count="single")
 
158
 
159
+ u.upload(upload_file, u)
160
+
161
+ submit_button = gr.Button("Submit Eval")
162
+ submission_result = gr.Markdown()
163
+ submit_button.click(
164
+ add_new_eval,
165
+ [
166
+ model_name_textbox,
167
+ output_format,
168
+ revision_name_textbox,
169
+ u,
170
+ ],
171
+ submission_result,
172
+ )
173
+
174
+
175
 
176
 
177
 
src/submission/submit.py CHANGED
@@ -1,6 +1,7 @@
1
  import json
2
  import os
3
  from datetime import datetime, timezone
 
4
 
5
  from src.display.formatting import styled_error, styled_message, styled_warning
6
  from src.envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
@@ -15,89 +16,59 @@ REQUESTED_MODELS = None
15
  USERS_TO_SUBMISSION_DATES = None
16
 
17
  def add_new_eval(
18
- model: str,
19
- base_model: str,
20
- revision: str,
21
- precision: str,
22
- weight_type: str,
23
- model_type: str,
24
  ):
25
  global REQUESTED_MODELS
26
  global USERS_TO_SUBMISSION_DATES
27
  if not REQUESTED_MODELS:
28
  REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
29
 
30
- user_name = ""
31
- model_path = model
32
- if "/" in model:
33
- user_name = model.split("/")[0]
34
- model_path = model.split("/")[1]
35
-
36
- precision = precision.split(" ")[0]
37
- current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
38
-
39
- if model_type is None or model_type == "":
40
- return styled_error("Please select a model type.")
41
 
42
  # Does the model actually exist?
43
  if revision == "":
44
  revision = "main"
45
 
46
- # Is the model on the hub?
47
- if weight_type in ["Delta", "Adapter"]:
48
- base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
49
- if not base_model_on_hub:
50
- return styled_error(f'Base model "{base_model}" {error}')
51
 
52
- if not weight_type == "Adapter":
53
- model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
54
- if not model_on_hub:
55
- return styled_error(f'Model "{model}" {error}')
56
 
57
- # Is the model info correctly filled?
58
- try:
59
- model_info = API.model_info(repo_id=model, revision=revision)
60
- except Exception:
61
- return styled_error("Could not get your model information. Please fill it up properly.")
62
 
63
- model_size = get_model_size(model_info=model_info, precision=precision)
 
 
 
 
 
 
 
 
64
 
65
- # Were the model card and license filled?
66
- try:
67
- license = model_info.cardData["license"]
68
- except Exception:
69
- return styled_error("Please select a license for your model")
70
 
71
- modelcard_OK, error_msg = check_model_card(model)
72
- if not modelcard_OK:
73
- return styled_error(error_msg)
74
 
75
  # Seems good, creating the eval
76
  print("Adding new eval")
77
 
78
  eval_entry = {
79
- "model": model,
80
- "base_model": base_model,
81
- "revision": revision,
82
- "precision": precision,
83
- "weight_type": weight_type,
84
  "status": "PENDING",
85
  "submitted_time": current_time,
86
- "model_type": model_type,
87
- "likes": model_info.likes,
88
- "params": model_size,
89
- "license": license,
90
  "private": False,
91
  }
92
 
93
- # Check for duplicate submission
94
- if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
95
- return styled_warning("This model has been already submitted.")
96
-
97
- print("Creating eval file")
98
- OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
99
  os.makedirs(OUT_DIR, exist_ok=True)
100
- out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
101
 
102
  with open(out_path, "w") as f:
103
  f.write(json.dumps(eval_entry))
 
1
  import json
2
  import os
3
  from datetime import datetime, timezone
4
+ import shutil
5
 
6
  from src.display.formatting import styled_error, styled_message, styled_warning
7
  from src.envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
 
16
  USERS_TO_SUBMISSION_DATES = None
17
 
18
  def add_new_eval(
19
+ model_name: str,
20
+ output_format: str,
21
+ revision_name: str,
22
+ upload_file,
 
 
23
  ):
24
  global REQUESTED_MODELS
25
  global USERS_TO_SUBMISSION_DATES
26
  if not REQUESTED_MODELS:
27
  REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
28
 
29
+ print(upload_file)
30
+
 
 
 
 
 
 
 
 
 
31
 
32
  # Does the model actually exist?
33
  if revision == "":
34
  revision = "main"
35
 
 
 
 
 
 
36
 
37
+ file_name = f"{model_name}_{datetime.now()}.json"
38
+ current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
 
 
39
 
40
+ path = f"{EVAL_REQUESTS_PATH}/{file_name}.json"
 
 
 
 
41
 
42
+ shutil.copy(upload_file, path)
43
+ print("Uploading eval file")
44
+ API.upload_file(
45
+ path_or_fileobj=path,
46
+ path_in_repo=out_path.split("eval-queue/")[1],
47
+ repo_id=QUEUE_REPO,
48
+ repo_type="dataset",
49
+ commit_message=f"Add {model_name} pred to eval queue",
50
+ )
51
 
52
+ # Remove the local file
53
+ os.remove(path)
 
 
 
54
 
 
 
 
55
 
56
  # Seems good, creating the eval
57
  print("Adding new eval")
58
 
59
  eval_entry = {
60
+ "model": model_name,
61
+ "revision": revision_name,
 
 
 
62
  "status": "PENDING",
63
  "submitted_time": current_time,
64
+ "output_format": output_format,
65
+ "submission_file": file_name,
 
 
66
  "private": False,
67
  }
68
 
69
+ OUT_DIR = f"{EVAL_REQUESTS_PATH}/{version}"
 
 
 
 
 
70
  os.makedirs(OUT_DIR, exist_ok=True)
71
+ out_path = f"{OUT_DIR}/{model_name}_eval_request_False_{output_format}.json"
72
 
73
  with open(out_path, "w") as f:
74
  f.write(json.dumps(eval_entry))