Johnnyyyyy56 commited on
Commit
22a8e71
·
verified ·
1 Parent(s): 9571689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -42
app.py CHANGED
@@ -309,7 +309,7 @@ def delete_images_in_category(emotion, image_type, confirm=False):
309
  deleted_count += 1
310
  except Exception as e:
311
  print(f"Error deleting {file}: {e}")
312
- failed_deletions.append(str(file))
313
 
314
  if deleted_count > 0 and LOG_FILE.exists():
315
  try:
@@ -388,7 +388,7 @@ def clear_all_data():
388
  empty_df = pd.DataFrame(columns=["timestamp", "batch_no", "emotion", "confidence", "face_path", "annotated_path"])
389
  return f"Deleted {deleted_count} items. All data has been cleared.", empty_df, None
390
 
391
- # Desktop-Optimized CSS
392
  desktop_css = """
393
  :root {
394
  --spacing: 0.75rem;
@@ -443,9 +443,9 @@ h1 {
443
  margin-bottom: 1.5rem;
444
  }
445
 
446
- .tab-content {
447
- padding: 1.5rem;
448
  background: white;
 
449
  border-radius: var(--border-radius);
450
  box-shadow: var(--shadow);
451
  margin-bottom: 1.5rem;
@@ -509,14 +509,6 @@ button.danger {
509
  margin-bottom: 1rem;
510
  }
511
 
512
- .dashboard-panel {
513
- background: white;
514
- padding: 1.5rem;
515
- border-radius: var(--border-radius);
516
- box-shadow: var(--shadow);
517
- margin-bottom: 1.5rem;
518
- }
519
-
520
  .management-section {
521
  display: grid;
522
  grid-template-columns: 1fr 1fr;
@@ -524,8 +516,14 @@ button.danger {
524
  margin-top: 1.5rem;
525
  }
526
 
 
 
 
 
 
 
527
  @media (max-width: 992px) {
528
- .management-section {
529
  grid-template-columns: 1fr;
530
  }
531
 
@@ -541,10 +539,9 @@ button.danger {
541
  }
542
  """
543
 
544
- # Capture Interface - Desktop Optimized
545
  with gr.Blocks(title="Emotion Capture", css=desktop_css) as capture_interface:
546
-
547
- with gr.Column():
548
  gr.Markdown("""
549
  # Emotion Capture Interface
550
  """)
@@ -574,27 +571,25 @@ with gr.Blocks(title="Emotion Capture", css=desktop_css) as capture_interface:
574
  visible=False
575
  )
576
 
577
- with gr.Row():
578
- with gr.Column(scale=1):
579
- webcam = gr.Image(
580
- sources=["webcam"],
581
- type="pil",
582
- label="Live Camera Feed",
583
- interactive=True,
584
- mirror_webcam=True,
585
- visible=False,
586
- elem_classes="webcam-container",
587
- height=400
588
- )
589
 
590
- with gr.Column(scale=1):
591
- result_img = gr.Image(
592
- label="Analysis Result",
593
- interactive=False,
594
- visible=False,
595
- elem_classes="result-container",
596
- height=400
597
- )
598
 
599
  with gr.Row():
600
  result_text = gr.Textbox(
@@ -611,14 +606,14 @@ with gr.Blocks(title="Emotion Capture", css=desktop_css) as capture_interface:
611
  elem_classes="primary"
612
  )
613
 
614
- # Detect when user stops typing (with 5 second delay)
615
  batch_no.change(
616
  check_batch_no,
617
  inputs=batch_no,
618
  outputs=[batch_no, message, webcam, result_img, result_text, done_btn],
619
  queue=False
620
  ).then(
621
- lambda: time.sleep(5), # Wait for 5 seconds of inactivity
622
  None,
623
  None,
624
  queue=False
@@ -629,22 +624,19 @@ with gr.Blocks(title="Emotion Capture", css=desktop_css) as capture_interface:
629
  queue=False
630
  )
631
 
632
- # Process when webcam captures an image
633
  webcam.change(
634
  predict_emotion,
635
  inputs=[batch_no, webcam],
636
  outputs=[result_img, result_text, message, result_img, result_text, done_btn]
637
  )
638
 
639
- # Reset interface when Done is clicked
640
  done_btn.click(
641
  reset_interface,
642
  outputs=[batch_no, message, webcam, result_img, result_text, done_btn]
643
  )
644
 
645
- # Data Management Interface - Desktop Optimized
646
  with gr.Blocks(title="Data Management") as data_interface:
647
-
648
  with gr.Column():
649
  gr.Markdown("""
650
  # Data Management Dashboard
 
309
  deleted_count += 1
310
  except Exception as e:
311
  print(f"Error deleting {file}: {e}")
312
+ failed_deletions.append(str(file))
313
 
314
  if deleted_count > 0 and LOG_FILE.exists():
315
  try:
 
388
  empty_df = pd.DataFrame(columns=["timestamp", "batch_no", "emotion", "confidence", "face_path", "annotated_path"])
389
  return f"Deleted {deleted_count} items. All data has been cleared.", empty_df, None
390
 
391
+ # Unified CSS for both interfaces
392
  desktop_css = """
393
  :root {
394
  --spacing: 0.75rem;
 
443
  margin-bottom: 1.5rem;
444
  }
445
 
446
+ .dashboard-panel {
 
447
  background: white;
448
+ padding: 1.5rem;
449
  border-radius: var(--border-radius);
450
  box-shadow: var(--shadow);
451
  margin-bottom: 1.5rem;
 
509
  margin-bottom: 1rem;
510
  }
511
 
 
 
 
 
 
 
 
 
512
  .management-section {
513
  display: grid;
514
  grid-template-columns: 1fr 1fr;
 
516
  margin-top: 1.5rem;
517
  }
518
 
519
+ .capture-section {
520
+ display: grid;
521
+ grid-template-columns: 1fr;
522
+ gap: 1.5rem;
523
+ }
524
+
525
  @media (max-width: 992px) {
526
+ .management-section, .capture-section {
527
  grid-template-columns: 1fr;
528
  }
529
 
 
539
  }
540
  """
541
 
542
+ # Capture Interface - Now matches Data Management style
543
  with gr.Blocks(title="Emotion Capture", css=desktop_css) as capture_interface:
544
+ with gr.Column(elem_classes="dashboard-panel"):
 
545
  gr.Markdown("""
546
  # Emotion Capture Interface
547
  """)
 
571
  visible=False
572
  )
573
 
574
+ with gr.Column(elem_classes="capture-section"):
575
+ webcam = gr.Image(
576
+ sources=["webcam"],
577
+ type="pil",
578
+ label="Live Camera Feed",
579
+ interactive=True,
580
+ mirror_webcam=True,
581
+ visible=False,
582
+ elem_classes="webcam-container",
583
+ height=500
584
+ )
 
585
 
586
+ result_img = gr.Image(
587
+ label="Analysis Result",
588
+ interactive=False,
589
+ visible=False,
590
+ elem_classes="result-container",
591
+ height=500
592
+ )
 
593
 
594
  with gr.Row():
595
  result_text = gr.Textbox(
 
606
  elem_classes="primary"
607
  )
608
 
609
+ # Event handlers
610
  batch_no.change(
611
  check_batch_no,
612
  inputs=batch_no,
613
  outputs=[batch_no, message, webcam, result_img, result_text, done_btn],
614
  queue=False
615
  ).then(
616
+ lambda: time.sleep(5),
617
  None,
618
  None,
619
  queue=False
 
624
  queue=False
625
  )
626
 
 
627
  webcam.change(
628
  predict_emotion,
629
  inputs=[batch_no, webcam],
630
  outputs=[result_img, result_text, message, result_img, result_text, done_btn]
631
  )
632
 
 
633
  done_btn.click(
634
  reset_interface,
635
  outputs=[batch_no, message, webcam, result_img, result_text, done_btn]
636
  )
637
 
638
+ # Data Management Interface
639
  with gr.Blocks(title="Data Management") as data_interface:
 
640
  with gr.Column():
641
  gr.Markdown("""
642
  # Data Management Dashboard