Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
alozowski
commited on
Commit
·
0b31d4e
1
Parent(s):
3b94cb4
add login at submit and user info
Browse files- app.py +1 -0
- src/submission/submit.py +22 -7
app.py
CHANGED
|
@@ -235,6 +235,7 @@ with main_block:
|
|
| 235 |
|
| 236 |
with gr.Row():
|
| 237 |
gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
|
|
|
|
| 238 |
|
| 239 |
with gr.Row():
|
| 240 |
with gr.Column():
|
|
|
|
| 235 |
|
| 236 |
with gr.Row():
|
| 237 |
gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
|
| 238 |
+
login_button = gr.LoginButton(elem_id="oauth-button")
|
| 239 |
|
| 240 |
with gr.Row():
|
| 241 |
with gr.Column():
|
src/submission/submit.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
|
|
|
| 3 |
from datetime import datetime, timezone
|
| 4 |
|
| 5 |
from dataclasses import dataclass
|
|
@@ -59,16 +60,25 @@ def add_new_eval(
|
|
| 59 |
weight_type: str,
|
| 60 |
model_type: str,
|
| 61 |
use_chat_template: bool,
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
global REQUESTED_MODELS
|
| 64 |
global USERS_TO_SUBMISSION_DATES
|
| 65 |
if not REQUESTED_MODELS:
|
| 66 |
REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
|
| 67 |
|
| 68 |
-
|
|
|
|
| 69 |
model_path = model
|
| 70 |
if "/" in model:
|
| 71 |
-
|
| 72 |
model_path = model.split("/")[1]
|
| 73 |
|
| 74 |
precision = precision.split(" ")[0]
|
|
@@ -77,10 +87,14 @@ def add_new_eval(
|
|
| 77 |
if model_type is None or model_type == "":
|
| 78 |
return styled_error("Please select a model type.")
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
# Is the user rate limited?
|
| 81 |
-
if
|
| 82 |
user_can_submit, error_msg = user_submission_permission(
|
| 83 |
-
|
| 84 |
)
|
| 85 |
if not user_can_submit:
|
| 86 |
return styled_error(error_msg)
|
|
@@ -144,7 +158,6 @@ def add_new_eval(
|
|
| 144 |
|
| 145 |
# Seems good, creating the eval
|
| 146 |
print("Adding new eval")
|
| 147 |
-
|
| 148 |
eval_entry = {
|
| 149 |
"model": model,
|
| 150 |
"base_model": base_model,
|
|
@@ -159,10 +172,11 @@ def add_new_eval(
|
|
| 159 |
"job_id": -1,
|
| 160 |
"job_start_time": None,
|
| 161 |
"use_chat_template": use_chat_template,
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
print("Creating eval file")
|
| 165 |
-
OUT_DIR = f"{EVAL_REQUESTS_PATH}/{
|
| 166 |
os.makedirs(OUT_DIR, exist_ok=True)
|
| 167 |
out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
|
| 168 |
|
|
@@ -170,6 +184,7 @@ def add_new_eval(
|
|
| 170 |
f.write(json.dumps(eval_entry))
|
| 171 |
|
| 172 |
print("Uploading eval file")
|
|
|
|
| 173 |
API.upload_file(
|
| 174 |
path_or_fileobj=out_path,
|
| 175 |
path_in_repo=out_path.split("eval-queue/")[1],
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
|
| 6 |
from dataclasses import dataclass
|
|
|
|
| 60 |
weight_type: str,
|
| 61 |
model_type: str,
|
| 62 |
use_chat_template: bool,
|
| 63 |
+
profile: gr.OAuthProfile | None
|
| 64 |
+
):
|
| 65 |
+
# Login require
|
| 66 |
+
if profile is None:
|
| 67 |
+
return styled_error("Hub Login Required")
|
| 68 |
+
|
| 69 |
+
# Name of the actual user who sent the request
|
| 70 |
+
username = profile.username
|
| 71 |
+
|
| 72 |
global REQUESTED_MODELS
|
| 73 |
global USERS_TO_SUBMISSION_DATES
|
| 74 |
if not REQUESTED_MODELS:
|
| 75 |
REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
|
| 76 |
|
| 77 |
+
|
| 78 |
+
org_or_user = ""
|
| 79 |
model_path = model
|
| 80 |
if "/" in model:
|
| 81 |
+
org_or_user = model.split("/")[0]
|
| 82 |
model_path = model.split("/")[1]
|
| 83 |
|
| 84 |
precision = precision.split(" ")[0]
|
|
|
|
| 87 |
if model_type is None or model_type == "":
|
| 88 |
return styled_error("Please select a model type.")
|
| 89 |
|
| 90 |
+
# Is user submitting own model?
|
| 91 |
+
# Check that username in the org.
|
| 92 |
+
# if org_or_user != profile.username:
|
| 93 |
+
|
| 94 |
# Is the user rate limited?
|
| 95 |
+
if org_or_user != "":
|
| 96 |
user_can_submit, error_msg = user_submission_permission(
|
| 97 |
+
org_or_user, USERS_TO_SUBMISSION_DATES, RATE_LIMIT_PERIOD, RATE_LIMIT_QUOTA
|
| 98 |
)
|
| 99 |
if not user_can_submit:
|
| 100 |
return styled_error(error_msg)
|
|
|
|
| 158 |
|
| 159 |
# Seems good, creating the eval
|
| 160 |
print("Adding new eval")
|
|
|
|
| 161 |
eval_entry = {
|
| 162 |
"model": model,
|
| 163 |
"base_model": base_model,
|
|
|
|
| 172 |
"job_id": -1,
|
| 173 |
"job_start_time": None,
|
| 174 |
"use_chat_template": use_chat_template,
|
| 175 |
+
"sender": username
|
| 176 |
}
|
| 177 |
|
| 178 |
print("Creating eval file")
|
| 179 |
+
OUT_DIR = f"{EVAL_REQUESTS_PATH}/{org_or_user}"
|
| 180 |
os.makedirs(OUT_DIR, exist_ok=True)
|
| 181 |
out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
|
| 182 |
|
|
|
|
| 184 |
f.write(json.dumps(eval_entry))
|
| 185 |
|
| 186 |
print("Uploading eval file")
|
| 187 |
+
print(eval_entry)
|
| 188 |
API.upload_file(
|
| 189 |
path_or_fileobj=out_path,
|
| 190 |
path_in_repo=out_path.split("eval-queue/")[1],
|