Spaces:
Running
Running
Maharshi Gor
commited on
Commit
·
c1ae336
1
Parent(s):
cd9f5b3
validations for submission name
Browse files- src/components/commons.py +8 -1
- src/submission/submit.py +19 -1
src/components/commons.py
CHANGED
@@ -37,7 +37,7 @@ def get_panel_header(header: str, subheader: str | None = None):
|
|
37 |
|
38 |
def get_model_submission_accordion(app: gr.Blocks):
|
39 |
with gr.Accordion(
|
40 |
-
"Feel happy with your agent? Make a submission!", elem_classes="model-submission-accordion", open=True
|
41 |
):
|
42 |
with gr.Row():
|
43 |
model_name_input = gr.Textbox(label="Submission Name")
|
@@ -47,6 +47,13 @@ def get_model_submission_accordion(app: gr.Blocks):
|
|
47 |
submit_btn = gr.Button("Submit", variant="primary", interactive=False)
|
48 |
|
49 |
submit_status = gr.HTML(label="Submission Status")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
def check_user_login(profile: gr.OAuthProfile | None):
|
52 |
if profile is not None:
|
|
|
37 |
|
38 |
def get_model_submission_accordion(app: gr.Blocks):
|
39 |
with gr.Accordion(
|
40 |
+
"🤗 Feel happy with your agent? Make a submission!", elem_classes="model-submission-accordion", open=True
|
41 |
):
|
42 |
with gr.Row():
|
43 |
model_name_input = gr.Textbox(label="Submission Name")
|
|
|
47 |
submit_btn = gr.Button("Submit", variant="primary", interactive=False)
|
48 |
|
49 |
submit_status = gr.HTML(label="Submission Status")
|
50 |
+
gr.Markdown(
|
51 |
+
"""**Submission Name Guidelines**
|
52 |
+
1. Must start with a letter.
|
53 |
+
2. Can only contain letters, numbers, underscores, and hyphens.
|
54 |
+
3. Cannot contain white spaces or other special characters.
|
55 |
+
"""
|
56 |
+
)
|
57 |
|
58 |
def check_user_login(profile: gr.OAuthProfile | None):
|
59 |
if profile is not None:
|
src/submission/submit.py
CHANGED
@@ -2,6 +2,7 @@ import glob
|
|
2 |
import json
|
3 |
import logging
|
4 |
import os
|
|
|
5 |
import traceback
|
6 |
from datetime import datetime, timedelta, timezone
|
7 |
|
@@ -124,6 +125,17 @@ def create_submission(
|
|
124 |
return submission
|
125 |
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
def submit_model(
|
128 |
model_name: str,
|
129 |
description: str,
|
@@ -156,7 +168,13 @@ def submit_model(
|
|
156 |
)
|
157 |
|
158 |
if f"{username}/{model_name}" in get_user_submission_names(competition_type, profile):
|
159 |
-
return styled_error(
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
try:
|
162 |
submission = create_submission(
|
|
|
2 |
import json
|
3 |
import logging
|
4 |
import os
|
5 |
+
import re
|
6 |
import traceback
|
7 |
from datetime import datetime, timedelta, timezone
|
8 |
|
|
|
125 |
return submission
|
126 |
|
127 |
|
128 |
+
def validate_model_name(model_name: str):
|
129 |
+
# check if model_name has no white spaces, no special characters apart from _ and -
|
130 |
+
if " " in model_name:
|
131 |
+
return False, "Model name cannot contain spaces."
|
132 |
+
if not re.match(r"^[a-zA-Z0-9_-]+$", model_name):
|
133 |
+
return False, "Model name can only contain letters, numbers, underscores, and hyphens."
|
134 |
+
if not re.match(r"^[a-zA-Z]", model_name):
|
135 |
+
return False, "Model name must start with a letter."
|
136 |
+
return True, ""
|
137 |
+
|
138 |
+
|
139 |
def submit_model(
|
140 |
model_name: str,
|
141 |
description: str,
|
|
|
168 |
)
|
169 |
|
170 |
if f"{username}/{model_name}" in get_user_submission_names(competition_type, profile):
|
171 |
+
return styled_error(
|
172 |
+
f"Submission Error!<br>'{model_name}' already exists. Please use a different name for your submission."
|
173 |
+
)
|
174 |
+
|
175 |
+
is_valid, error_msg = validate_model_name(model_name)
|
176 |
+
if not is_valid:
|
177 |
+
return styled_error(f"Submission Error! Invalid model name '{model_name}'.<br>{error_msg}")
|
178 |
|
179 |
try:
|
180 |
submission = create_submission(
|