Shaltiel commited on
Commit
abd0954
1 Parent(s): 7cb5e0a

Added login button

Browse files
Files changed (3) hide show
  1. app.py +48 -43
  2. requirements.txt +1 -1
  3. src/submission/submit.py +12 -1
app.py CHANGED
@@ -298,52 +298,57 @@ with demo:
298
  datatype=EVAL_TYPES,
299
  row_count=5,
300
  )
301
- with gr.Row():
302
- gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
 
 
303
 
304
- with gr.Row():
305
- with gr.Column():
306
- model_name_textbox = gr.Textbox(label="Model name")
307
- revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
308
- model_type = gr.Dropdown(
309
- choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
310
- label="Model type",
311
- multiselect=False,
312
- value=None,
313
- interactive=True,
314
- )
315
 
316
- with gr.Column():
317
- precision = gr.Dropdown(
318
- choices=[i.value.name for i in Precision if i != Precision.Unknown],
319
- label="Precision",
320
- multiselect=False,
321
- value="float16" if DEVICE != "cpu" else "float32",
322
- interactive=True,
323
- )
324
- weight_type = gr.Dropdown(
325
- choices=[i.value.name for i in WeightType],
326
- label="Weights type",
327
- multiselect=False,
328
- value="Original",
329
- interactive=True,
330
- )
331
- base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
332
 
333
- submit_button = gr.Button("Submit Eval")
334
- submission_result = gr.Markdown()
335
- submit_button.click(
336
- add_new_eval,
337
- [
338
- model_name_textbox,
339
- base_model_name_textbox,
340
- revision_name_textbox,
341
- precision,
342
- weight_type,
343
- model_type,
344
- ],
345
- submission_result,
346
- )
 
 
 
347
 
348
  scheduler = BackgroundScheduler()
349
  scheduler.add_job(restart_space, "interval", seconds=1800)
 
298
  datatype=EVAL_TYPES,
299
  row_count=5,
300
  )
301
+
302
+ if gr.OAuthToken:
303
+ with gr.Row():
304
+ gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
305
 
306
+ with gr.Row():
307
+ with gr.Column():
308
+ model_name_textbox = gr.Textbox(label="Model name")
309
+ revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
310
+ model_type = gr.Dropdown(
311
+ choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
312
+ label="Model type",
313
+ multiselect=False,
314
+ value=None,
315
+ interactive=True,
316
+ )
317
 
318
+ with gr.Column():
319
+ precision = gr.Dropdown(
320
+ choices=[i.value.name for i in Precision if i != Precision.Unknown],
321
+ label="Precision",
322
+ multiselect=False,
323
+ value="float16" if DEVICE != "cpu" else "float32",
324
+ interactive=True,
325
+ )
326
+ weight_type = gr.Dropdown(
327
+ choices=[i.value.name for i in WeightType],
328
+ label="Weights type",
329
+ multiselect=False,
330
+ value="Original",
331
+ interactive=True,
332
+ )
333
+ base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
334
 
335
+ gr.Markdown("You must be logged in to submit models.")
336
+ gr.LoginButton(min_width=250)
337
+
338
+ submit_button = gr.Button("Submit Eval")
339
+ submission_result = gr.Markdown()
340
+ submit_button.click(
341
+ add_new_eval,
342
+ [
343
+ model_name_textbox,
344
+ base_model_name_textbox,
345
+ revision_name_textbox,
346
+ precision,
347
+ weight_type,
348
+ model_type,
349
+ ],
350
+ submission_result,
351
+ )
352
 
353
  scheduler = BackgroundScheduler()
354
  scheduler.add_job(restart_space, "interval", seconds=1800)
requirements.txt CHANGED
@@ -2,7 +2,7 @@ APScheduler==3.10.1
2
  black==23.11.0
3
  click==8.1.3
4
  datasets==2.14.5
5
- gradio==4.4.0
6
  gradio_client==0.7.0
7
  huggingface-hub>=0.18.0
8
  matplotlib==3.7.1
 
2
  black==23.11.0
3
  click==8.1.3
4
  datasets==2.14.5
5
+ gradio[oauth]==4.29.0
6
  gradio_client==0.7.0
7
  huggingface-hub>=0.18.0
8
  matplotlib==3.7.1
src/submission/submit.py CHANGED
@@ -1,6 +1,8 @@
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
@@ -21,7 +23,11 @@ def add_new_eval(
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:
@@ -72,6 +78,10 @@ def add_new_eval(
72
  if not modelcard_OK:
73
  return styled_error(error_msg)
74
 
 
 
 
 
75
  # Seems good, creating the eval
76
  print("Adding new eval")
77
 
@@ -88,8 +98,9 @@ def add_new_eval(
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.")
 
1
  import json
2
  import os
3
  from datetime import datetime, timezone
4
+ import gradio as gr
5
+ from huggingface_hub import HfApi
6
 
7
  from src.display.formatting import styled_error, styled_message, styled_warning
8
  from src.envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
 
23
  precision: str,
24
  weight_type: str,
25
  model_type: str,
26
+ oauth_token: gr.OAuthToken
27
  ):
28
+ if not oauth_token:
29
+ return styled_error("Please login in order to submit models")
30
+
31
  global REQUESTED_MODELS
32
  global USERS_TO_SUBMISSION_DATES
33
  if not REQUESTED_MODELS:
 
78
  if not modelcard_OK:
79
  return styled_error(error_msg)
80
 
81
+ print('Getting user info...')
82
+ api = HfApi(token=oauth_token.token)
83
+ user_info = api.whoami()
84
+
85
  # Seems good, creating the eval
86
  print("Adding new eval")
87
 
 
98
  "params": model_size,
99
  "license": license,
100
  "private": False,
101
+ "user_info": user_info
102
  }
103
+
104
  # Check for duplicate submission
105
  if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
106
  return styled_warning("This model has been already submitted.")