gabrielchua commited on
Commit
8cad311
Β·
unverified Β·
1 Parent(s): db96ac5
Files changed (1) hide show
  1. app.py +79 -17
app.py CHANGED
@@ -331,14 +331,34 @@ def vote_thumbs_up(text_id):
331
  """Handle thumbs up vote"""
332
  if text_id and GOOGLE_SHEET_URL and GOOGLE_CREDENTIALS:
333
  save_vote_data(text_id, True)
334
- return '<div style="background: linear-gradient(135deg, #065f46 0%, #047857 100%); color: #34d399; padding: 16px; border-radius: 8px; text-align: center; font-weight: 600; border: 1px solid #10b981; margin: 8px 0;">πŸ‘ Thanks for your feedback!</div>'
 
 
 
 
 
 
 
 
 
 
335
  return '<div style="color: #9ca3af; text-align: center; padding: 16px;">Voting not available</div>'
336
 
337
  def vote_thumbs_down(text_id):
338
  """Handle thumbs down vote"""
339
  if text_id and GOOGLE_SHEET_URL and GOOGLE_CREDENTIALS:
340
  save_vote_data(text_id, False)
341
- return '<div style="background: linear-gradient(135deg, #991b1b 0%, #b91c1c 100%); color: #fca5a5; padding: 16px; border-radius: 8px; text-align: center; font-weight: 600; border: 1px solid #ef4444; margin: 8px 0;">πŸ‘Ž Thanks for your feedback!</div>'
 
 
 
 
 
 
 
 
 
 
342
  return '<div style="color: #9ca3af; text-align: center; padding: 16px;">Voting not available</div>'
343
 
344
  # Create Gradio interface with dark theme
@@ -383,21 +403,46 @@ with gr.Blocks(title="LionGuard2", theme=gr.themes.Base().set(
383
  value='<div style="text-align: center; color: #9ca3af; padding: 30px; font-style: italic;">Category scores will appear here after analysis</div>'
384
  )
385
 
386
- # Voting section
387
- voting_section = gr.HTML(value="")
388
-
389
- with gr.Row(visible=False) as voting_row:
390
  with gr.Column():
391
  gr.HTML("""
392
- <div style="margin: 16px 0; text-align: center;">
393
- <h3 style="color: #f9fafb; font-size: 18px; font-weight: 600; margin-bottom: 8px;">πŸ“Š How accurate are these results?</h3>
394
- <p style="color: #d1d5db; font-size: 14px; margin-bottom: 16px;">Your feedback helps improve the model</p>
 
 
 
 
 
 
 
395
  </div>
396
  """)
397
 
398
- with gr.Row():
399
- thumbs_up_btn = gr.Button("πŸ‘ Accurate", variant="secondary", scale=1)
400
- thumbs_down_btn = gr.Button("πŸ‘Ž Inaccurate", variant="secondary", scale=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
 
402
  vote_feedback = gr.HTML(value="")
403
 
@@ -431,22 +476,39 @@ with gr.Blocks(title="LionGuard2", theme=gr.themes.Base().set(
431
  # Function to handle analysis and show voting buttons
432
  def analyze_and_show_voting(text):
433
  binary_score, category_table, text_id, voting_html = analyze_text(text)
434
- # Show voting row if we have results
435
- voting_row_update = gr.update(visible=bool(text_id))
436
- return binary_score, category_table, text_id, voting_row_update, ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
 
438
  # Connect the analyze button to the function
439
  analyze_btn.click(
440
  fn=analyze_and_show_voting,
441
  inputs=[text_input],
442
- outputs=[binary_output, category_table, current_text_id, voting_row, vote_feedback]
443
  )
444
 
445
  # Allow Enter key to trigger analysis
446
  text_input.submit(
447
  fn=analyze_and_show_voting,
448
  inputs=[text_input],
449
- outputs=[binary_output, category_table, current_text_id, voting_row, vote_feedback]
450
  )
451
 
452
  # Connect voting buttons
 
331
  """Handle thumbs up vote"""
332
  if text_id and GOOGLE_SHEET_URL and GOOGLE_CREDENTIALS:
333
  save_vote_data(text_id, True)
334
+ return '''
335
+ <div style="background: linear-gradient(135deg, #065f46 0%, #047857 100%); color: #34d399; padding: 24px; border-radius: 16px; text-align: center; font-weight: 700; border: 2px solid #10b981; margin: 16px 0; box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4); animation: bounceIn 0.6s ease-out;">
336
+ <div style="font-size: 48px; margin-bottom: 12px;">πŸŽ‰</div>
337
+ <h3 style="color: #ffffff; font-size: 20px; margin-bottom: 8px; text-shadow: 0 2px 4px rgba(0,0,0,0.3);">
338
+ Awesome! Thank you!
339
+ </h3>
340
+ <p style="color: #a7f3d0; font-size: 14px; margin: 0;">
341
+ Your positive feedback helps improve our AI safety models
342
+ </p>
343
+ </div>
344
+ '''
345
  return '<div style="color: #9ca3af; text-align: center; padding: 16px;">Voting not available</div>'
346
 
347
  def vote_thumbs_down(text_id):
348
  """Handle thumbs down vote"""
349
  if text_id and GOOGLE_SHEET_URL and GOOGLE_CREDENTIALS:
350
  save_vote_data(text_id, False)
351
+ return '''
352
+ <div style="background: linear-gradient(135deg, #991b1b 0%, #b91c1c 100%); color: #fca5a5; padding: 24px; border-radius: 16px; text-align: center; font-weight: 700; border: 2px solid #ef4444; margin: 16px 0; box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4); animation: bounceIn 0.6s ease-out;">
353
+ <div style="font-size: 48px; margin-bottom: 12px;">πŸ“</div>
354
+ <h3 style="color: #ffffff; font-size: 20px; margin-bottom: 8px; text-shadow: 0 2px 4px rgba(0,0,0,0.3);">
355
+ Thanks for the feedback!
356
+ </h3>
357
+ <p style="color: #fecaca; font-size: 14px; margin: 0;">
358
+ Critical feedback helps us identify and fix model weaknesses
359
+ </p>
360
+ </div>
361
+ '''
362
  return '<div style="color: #9ca3af; text-align: center; padding: 16px;">Voting not available</div>'
363
 
364
  # Create Gradio interface with dark theme
 
403
  value='<div style="text-align: center; color: #9ca3af; padding: 30px; font-style: italic;">Category scores will appear here after analysis</div>'
404
  )
405
 
406
+ # Enhanced Voting section - always visible and prominent
407
+ with gr.Row():
 
 
408
  with gr.Column():
409
  gr.HTML("""
410
+ <div style="background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); border-radius: 16px; padding: 24px; margin: 20px 0; text-align: center; border: 2px solid #60a5fa; box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3); position: relative; overflow: hidden;">
411
+ <div style="position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%); animation: pulse 3s ease-in-out infinite;"></div>
412
+ <div style="position: relative; z-index: 1;">
413
+ <h3 style="color: #ffffff; font-size: 22px; font-weight: 700; margin-bottom: 12px; text-shadow: 0 2px 4px rgba(0,0,0,0.3);">
414
+ 🎯 Help Us Improve! Rate the Analysis
415
+ </h3>
416
+ <p style="color: #dbeafe; font-size: 16px; margin-bottom: 0; font-weight: 500;">
417
+ Your feedback trains better AI safety models
418
+ </p>
419
+ </div>
420
  </div>
421
  """)
422
 
423
+ voting_instruction = gr.HTML(value="""
424
+ <div id="voting-instructions" style="background: #374151; border-radius: 12px; padding: 20px; margin: 16px 0; text-align: center; border: 2px dashed #6b7280; box-shadow: 0 4px 12px rgba(0,0,0,0.2);">
425
+ <p style="color: #d1d5db; font-size: 16px; margin: 0; font-weight: 500;">
426
+ ⬆️ Analyze some text above to unlock voting ⬆️
427
+ </p>
428
+ </div>
429
+ """)
430
+
431
+ with gr.Row(visible=False) as voting_buttons_row:
432
+ with gr.Column(scale=1):
433
+ thumbs_up_btn = gr.Button(
434
+ "πŸ‘ Results Look Accurate",
435
+ variant="primary",
436
+ size="lg",
437
+ elem_classes=["voting-btn-positive"]
438
+ )
439
+ with gr.Column(scale=1):
440
+ thumbs_down_btn = gr.Button(
441
+ "πŸ‘Ž Results Look Wrong",
442
+ variant="secondary",
443
+ size="lg",
444
+ elem_classes=["voting-btn-negative"]
445
+ )
446
 
447
  vote_feedback = gr.HTML(value="")
448
 
 
476
  # Function to handle analysis and show voting buttons
477
  def analyze_and_show_voting(text):
478
  binary_score, category_table, text_id, voting_html = analyze_text(text)
479
+ # Show voting buttons and hide instructions if we have results
480
+ if text_id:
481
+ voting_buttons_update = gr.update(visible=True)
482
+ voting_instruction_update = gr.update(value="""
483
+ <div style="background: linear-gradient(135deg, #065f46 0%, #047857 100%); border-radius: 12px; padding: 20px; margin: 16px 0; text-align: center; border: 2px solid #10b981; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
484
+ <p style="color: #34d399; font-size: 16px; margin: 0; font-weight: 600;">
485
+ βœ… Analysis Complete! Please rate the accuracy below πŸ‘‡
486
+ </p>
487
+ </div>
488
+ """)
489
+ else:
490
+ voting_buttons_update = gr.update(visible=False)
491
+ voting_instruction_update = gr.update(value="""
492
+ <div style="background: #374151; border-radius: 12px; padding: 20px; margin: 16px 0; text-align: center; border: 2px dashed #6b7280; box-shadow: 0 4px 12px rgba(0,0,0,0.2);">
493
+ <p style="color: #d1d5db; font-size: 16px; margin: 0; font-weight: 500;">
494
+ ⬆️ Analyze some text above to unlock voting ⬆️
495
+ </p>
496
+ </div>
497
+ """)
498
+ return binary_score, category_table, text_id, voting_buttons_update, voting_instruction_update, ""
499
 
500
  # Connect the analyze button to the function
501
  analyze_btn.click(
502
  fn=analyze_and_show_voting,
503
  inputs=[text_input],
504
+ outputs=[binary_output, category_table, current_text_id, voting_buttons_row, voting_instruction, vote_feedback]
505
  )
506
 
507
  # Allow Enter key to trigger analysis
508
  text_input.submit(
509
  fn=analyze_and_show_voting,
510
  inputs=[text_input],
511
+ outputs=[binary_output, category_table, current_text_id, voting_buttons_row, voting_instruction, vote_feedback]
512
  )
513
 
514
  # Connect voting buttons