Spaces:
Runtime error
Runtime error
Commit
·
fe3cf53
1
Parent(s):
02c88c1
Add inputs
Browse files
app.py
CHANGED
|
@@ -86,22 +86,22 @@ def build_demo():
|
|
| 86 |
submitter_username = gr.Textbox(label="Username") # can we get this info from hf??
|
| 87 |
model_link_web = gr.Textbox(label="Link to Model") # can we get this info from hf??
|
| 88 |
|
| 89 |
-
def upload_file(file):
|
| 90 |
file_name = file.name.split("/")[-1] if "/" in file.name else file.name
|
| 91 |
-
file_name =
|
| 92 |
|
| 93 |
with open(f"{DATA_PATH}/{SUBMITS_META_FILE}", "r", encoding="utf-8") as submit_meta_file:
|
| 94 |
current_info = json.loads(submit_meta_file)
|
| 95 |
|
| 96 |
# for now just do not save same name model
|
| 97 |
-
if any(filter(lambda x: x["model_name"] ==
|
| 98 |
return False
|
| 99 |
|
| 100 |
submit_info = {
|
| 101 |
-
"model_name":
|
| 102 |
-
"username":
|
| 103 |
"file_name": file_name,
|
| 104 |
-
"link":
|
| 105 |
}
|
| 106 |
|
| 107 |
current_info.append(submit_info)
|
|
@@ -111,9 +111,9 @@ def build_demo():
|
|
| 111 |
|
| 112 |
logging.info(
|
| 113 |
"New submition: file from %s saved to %s with model %s",
|
| 114 |
-
|
| 115 |
file_name,
|
| 116 |
-
|
| 117 |
)
|
| 118 |
API.upload_file(
|
| 119 |
path_or_fileobj=file.name,
|
|
@@ -137,7 +137,7 @@ def build_demo():
|
|
| 137 |
upload_button = gr.UploadButton(
|
| 138 |
"Click to Upload & Submit Answers", file_types=["*"], file_count="single"
|
| 139 |
)
|
| 140 |
-
upload_button.upload(upload_file, upload_button, file_output)
|
| 141 |
|
| 142 |
return demo
|
| 143 |
|
|
|
|
| 86 |
submitter_username = gr.Textbox(label="Username") # can we get this info from hf??
|
| 87 |
model_link_web = gr.Textbox(label="Link to Model") # can we get this info from hf??
|
| 88 |
|
| 89 |
+
def upload_file(file, model_name, username, link):
|
| 90 |
file_name = file.name.split("/")[-1] if "/" in file.name else file.name
|
| 91 |
+
file_name = model_name.value + "_" + file_name
|
| 92 |
|
| 93 |
with open(f"{DATA_PATH}/{SUBMITS_META_FILE}", "r", encoding="utf-8") as submit_meta_file:
|
| 94 |
current_info = json.loads(submit_meta_file)
|
| 95 |
|
| 96 |
# for now just do not save same name model
|
| 97 |
+
if any(filter(lambda x: x["model_name"] == model_name, current_info)):
|
| 98 |
return False
|
| 99 |
|
| 100 |
submit_info = {
|
| 101 |
+
"model_name": model_name,
|
| 102 |
+
"username": username,
|
| 103 |
"file_name": file_name,
|
| 104 |
+
"link": link if link else "",
|
| 105 |
}
|
| 106 |
|
| 107 |
current_info.append(submit_info)
|
|
|
|
| 111 |
|
| 112 |
logging.info(
|
| 113 |
"New submition: file from %s saved to %s with model %s",
|
| 114 |
+
username,
|
| 115 |
file_name,
|
| 116 |
+
model_name,
|
| 117 |
)
|
| 118 |
API.upload_file(
|
| 119 |
path_or_fileobj=file.name,
|
|
|
|
| 137 |
upload_button = gr.UploadButton(
|
| 138 |
"Click to Upload & Submit Answers", file_types=["*"], file_count="single"
|
| 139 |
)
|
| 140 |
+
upload_button.upload(upload_file, upload_button, file_output, inputs=[model_name_textbox, submitter_username, model_link_web])
|
| 141 |
|
| 142 |
return demo
|
| 143 |
|