Spaces:
Sleeping
Sleeping
backup
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ from pathlib import Path
|
|
14 |
from io import BytesIO
|
15 |
import PIL
|
16 |
import time # Add this import at the top
|
|
|
17 |
|
18 |
api = HfApi(token=os.environ["HF_TOKEN"])
|
19 |
|
@@ -281,16 +282,28 @@ def select_verdict(verdict, state):
|
|
281 |
)
|
282 |
|
283 |
|
284 |
-
def
|
285 |
-
"""
|
286 |
-
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
return (
|
290 |
2, # next page
|
291 |
gr.update(value=""), # clear input
|
292 |
-
gr.update(value=
|
293 |
-
|
294 |
)
|
295 |
|
296 |
|
@@ -372,12 +385,8 @@ with gr.Blocks() as demo:
|
|
372 |
image_path="./instructions/home.jpg",
|
373 |
)
|
374 |
username_input = gr.Textbox(
|
375 |
-
label="Please enter your
|
376 |
-
placeholder="
|
377 |
-
)
|
378 |
-
validation_text = gr.HTML(
|
379 |
-
visible=False,
|
380 |
-
value='<p style="color: red;">Please enter a valid username (min 2 characters)</p>',
|
381 |
)
|
382 |
start_btn = gr.Button("Start", variant="primary")
|
383 |
|
@@ -411,9 +420,6 @@ with gr.Blocks() as demo:
|
|
411 |
|
412 |
# Main Evaluation UI (existing code)
|
413 |
with gr.Column(visible=False) as main_ui:
|
414 |
-
# ... existing evaluation UI code ...
|
415 |
-
# Move all the existing UI elements here
|
416 |
-
|
417 |
# Add instruction panel at the top
|
418 |
gr.HTML(
|
419 |
"""
|
@@ -648,16 +654,12 @@ with gr.Blocks() as demo:
|
|
648 |
current_page,
|
649 |
username_input,
|
650 |
username_debug,
|
651 |
-
username_state,
|
652 |
],
|
653 |
).then(
|
654 |
update_page_visibility,
|
655 |
inputs=[current_page],
|
656 |
outputs=[page1, page2, page3, main_ui],
|
657 |
-
).then(
|
658 |
-
lambda x: gr.update(visible=x is None),
|
659 |
-
inputs=[current_page],
|
660 |
-
outputs=[validation_text],
|
661 |
)
|
662 |
|
663 |
next_btn1.click(
|
|
|
14 |
from io import BytesIO
|
15 |
import PIL
|
16 |
import time # Add this import at the top
|
17 |
+
import re
|
18 |
|
19 |
api = HfApi(token=os.environ["HF_TOKEN"])
|
20 |
|
|
|
282 |
)
|
283 |
|
284 |
|
285 |
+
def is_valid_email(email):
|
286 |
+
"""Validate email format using regex pattern"""
|
287 |
+
pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
|
288 |
+
return bool(re.match(pattern, email))
|
289 |
+
|
290 |
+
|
291 |
+
def handle_username_submit(email, current_page):
|
292 |
+
"""Handle email submission and advance to next page"""
|
293 |
+
if not email or not is_valid_email(email.strip()):
|
294 |
+
# Return current page and show error message
|
295 |
+
gr.Warning("Please enter a valid email address (e.g., [email protected])")
|
296 |
+
return (
|
297 |
+
current_page, # stay on current page
|
298 |
+
gr.update(value=email), # keep current email value
|
299 |
+
gr.update(value=""), # clear debug
|
300 |
+
None, # no username state
|
301 |
+
)
|
302 |
return (
|
303 |
2, # next page
|
304 |
gr.update(value=""), # clear input
|
305 |
+
gr.update(value=email), # update debug
|
306 |
+
email, # update state
|
307 |
)
|
308 |
|
309 |
|
|
|
385 |
image_path="./instructions/home.jpg",
|
386 |
)
|
387 |
username_input = gr.Textbox(
|
388 |
+
label="Please enter your email address",
|
389 |
+
placeholder="[email protected]",
|
|
|
|
|
|
|
|
|
390 |
)
|
391 |
start_btn = gr.Button("Start", variant="primary")
|
392 |
|
|
|
420 |
|
421 |
# Main Evaluation UI (existing code)
|
422 |
with gr.Column(visible=False) as main_ui:
|
|
|
|
|
|
|
423 |
# Add instruction panel at the top
|
424 |
gr.HTML(
|
425 |
"""
|
|
|
654 |
current_page,
|
655 |
username_input,
|
656 |
username_debug,
|
657 |
+
username_state,
|
658 |
],
|
659 |
).then(
|
660 |
update_page_visibility,
|
661 |
inputs=[current_page],
|
662 |
outputs=[page1, page2, page3, main_ui],
|
|
|
|
|
|
|
|
|
663 |
)
|
664 |
|
665 |
next_btn1.click(
|