taesiri commited on
Commit
0622c28
·
1 Parent(s): 047c657
Files changed (1) hide show
  1. app.py +23 -21
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 handle_username_submit(username, current_page):
285
- """Handle username submission and advance to next page"""
286
- if not username or len(username.strip()) < 2:
287
- # Just stay on current page if validation fails
288
- return current_page, gr.update(value=username), gr.update(value=""), None
 
 
 
 
 
 
 
 
 
 
 
 
289
  return (
290
  2, # next page
291
  gr.update(value=""), # clear input
292
- gr.update(value=username), # update debug
293
- username, # update state
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 username",
376
- placeholder="Username (min 2 characters)",
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, # Add username_state to outputs
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(