hari7261 commited on
Commit
29ffdeb
Β·
verified Β·
1 Parent(s): ab3fafc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -55
app.py CHANGED
@@ -634,23 +634,30 @@ button.primary:active {
634
  }
635
  """
636
 
637
- with gr.Blocks(title="Face Attendance System", theme=gr.themes.Soft(), css=custom_css) as demo:
 
 
 
 
 
 
 
 
638
  # Header
639
- gr.Markdown("# 🎯 Face Recognition Attendance System", elem_classes=["main-header"])
640
- gr.Markdown("### Powered by UniFace (RetinaFace + ArcFace)", elem_classes=["sub-header"])
641
 
642
  # Camera Tab
643
  with gr.Tab("πŸ“· Camera"):
644
  gr.Markdown("## πŸ“· Camera Control")
645
- with gr.Row(equal_height=True):
646
- start_btn = gr.Button("▢️ Start Camera", variant="primary", size="lg")
647
- stop_btn = gr.Button("⏹️ Stop Camera", variant="secondary", size="lg")
648
- refresh_btn = gr.Button("πŸ”„ Refresh Preview", variant="secondary", size="lg")
649
  camera_status = gr.Textbox(
650
  label="πŸ“‘ Status",
651
  interactive=False,
652
- value="πŸ“· Camera auto-started! Click 'Refresh Preview' to see the feed.",
653
- lines=1
654
  )
655
  preview = gr.Image(label="πŸ“Ί Live Preview", interactive=False)
656
 
@@ -659,33 +666,29 @@ with gr.Blocks(title="Face Attendance System", theme=gr.themes.Soft(), css=custo
659
  gr.Markdown("## πŸ“ Register New User")
660
  gr.Markdown("*Fill in details and capture your face to register*")
661
 
662
- with gr.Row(equal_height=True):
663
- with gr.Column(scale=1):
664
  gr.Markdown("### πŸ“‹ User Details")
665
  name_input = gr.Textbox(
666
  label="πŸ‘€ Full Name",
667
- placeholder="Enter your full name...",
668
- lines=1
669
  )
670
  roll_no_input = gr.Textbox(
671
  label="πŸ”’ Roll Number / ID",
672
- placeholder="Enter roll number or ID...",
673
- lines=1
674
  )
675
- register_btn = gr.Button("πŸ“Έ Capture & Register", variant="primary", size="lg")
676
 
677
- with gr.Column(scale=1):
678
  gr.Markdown("### πŸ“Š Registration Status")
679
  registration_output = gr.Textbox(
680
  label="ℹ️ Status",
681
  interactive=False,
682
- lines=5,
683
- placeholder="Status will appear here..."
684
  )
685
  registration_image = gr.Image(
686
  label="πŸ“Έ Captured Face",
687
- interactive=False,
688
- height=250
689
  )
690
 
691
  # Attendance Tab
@@ -693,30 +696,23 @@ with gr.Blocks(title="Face Attendance System", theme=gr.themes.Soft(), css=custo
693
  gr.Markdown("## βœ… Mark Your Attendance")
694
  gr.Markdown("*Click the button below to detect your face and mark attendance*")
695
 
696
- detect_btn = gr.Button(
697
- "πŸ” Detect & Mark Attendance",
698
- variant="primary",
699
- size="lg"
700
- )
701
 
702
- with gr.Row(equal_height=True):
703
- with gr.Column(scale=2):
704
  detection_image = gr.Image(
705
  label="πŸ“Έ Detection Result",
706
- interactive=False,
707
- height=400
708
  )
709
- with gr.Column(scale=1):
710
  detection_status = gr.Textbox(
711
  label="πŸ“‘ Status",
712
- interactive=False,
713
- lines=2
714
  )
715
  recognized_users = gr.Textbox(
716
  label="🎯 Result",
717
  lines=8,
718
- interactive=False,
719
- placeholder="Recognition result will appear here..."
720
  )
721
 
722
  # Reports Tab
@@ -724,61 +720,55 @@ with gr.Blocks(title="Face Attendance System", theme=gr.themes.Soft(), css=custo
724
  gr.Markdown("## πŸ“Š Attendance Reports & Analytics")
725
 
726
  # Filter Section
727
- with gr.Row(equal_height=True):
728
- with gr.Column(scale=1):
729
  gr.Markdown("### πŸ“… Select Date Range")
730
  filter_type = gr.Radio(
731
  choices=["Today", "This Week", "This Month", "Custom Range", "All Time"],
732
  value="Today",
733
- label="Filter Period",
734
- interactive=True
735
  )
736
- with gr.Column(scale=1):
737
  gr.Markdown("### πŸ“† Custom Date Range")
738
  start_date = gr.Textbox(
739
  label="Start Date",
740
- placeholder="YYYY-MM-DD (e.g., 2024-01-01)",
741
- lines=1
742
  )
743
  end_date = gr.Textbox(
744
  label="End Date",
745
- placeholder="YYYY-MM-DD (e.g., 2024-12-31)",
746
- lines=1
747
  )
748
 
749
  # Action Buttons
750
  gr.Markdown("### πŸŽ›οΈ Actions")
751
- with gr.Row(equal_height=True):
752
- filter_btn = gr.Button("πŸ” Apply Filter", variant="primary", size="lg")
753
- users_btn = gr.Button("πŸ‘₯ All Users", variant="secondary", size="lg")
754
- download_btn = gr.Button("πŸ“₯ Download CSV", variant="secondary", size="lg")
755
 
756
  # Report Info
757
  report_info = gr.Textbox(
758
  label="πŸ“Š Report Summary",
759
  interactive=False,
760
- value="πŸ‘† Select a filter and click 'Apply Filter' to view records",
761
- lines=1
762
  )
763
 
764
  # Summary Stats
765
  gr.Markdown("### πŸ“ˆ Quick Stats")
766
  summary_output = gr.Dataframe(
767
  label="Statistics",
768
- interactive=False,
769
- wrap=True
770
  )
771
 
772
  # Main Report Table
773
  gr.Markdown("### πŸ“‹ Attendance Records")
774
  report_output = gr.Dataframe(
775
  label="Records",
776
- interactive=False,
777
- wrap=True
778
  )
779
 
780
  # Download Section
781
- download_file = gr.File(label="πŸ“₯ Downloaded Report", visible=True)
782
 
783
  # Event Handlers
784
  start_btn.click(start_camera_interface, inputs=None, outputs=camera_status)
 
634
  }
635
  """
636
 
637
+ # Create Gradio interface - compatible with different versions
638
+ try:
639
+ # Try newer Gradio version with theme
640
+ demo = gr.Blocks(title="Face Attendance System", theme=gr.themes.Soft(), css=custom_css)
641
+ except TypeError:
642
+ # Fallback for older Gradio versions without theme support
643
+ demo = gr.Blocks(title="Face Attendance System", css=custom_css)
644
+
645
+ with demo:
646
  # Header
647
+ gr.Markdown("# 🎯 Face Recognition Attendance System")
648
+ gr.Markdown("### Powered by UniFace (RetinaFace + ArcFace)")
649
 
650
  # Camera Tab
651
  with gr.Tab("πŸ“· Camera"):
652
  gr.Markdown("## πŸ“· Camera Control")
653
+ with gr.Row():
654
+ start_btn = gr.Button("▢️ Start Camera", variant="primary")
655
+ stop_btn = gr.Button("⏹️ Stop Camera", variant="secondary")
656
+ refresh_btn = gr.Button("πŸ”„ Refresh Preview", variant="secondary")
657
  camera_status = gr.Textbox(
658
  label="πŸ“‘ Status",
659
  interactive=False,
660
+ value="πŸ“· Camera auto-started! Click 'Refresh Preview' to see the feed."
 
661
  )
662
  preview = gr.Image(label="πŸ“Ί Live Preview", interactive=False)
663
 
 
666
  gr.Markdown("## πŸ“ Register New User")
667
  gr.Markdown("*Fill in details and capture your face to register*")
668
 
669
+ with gr.Row():
670
+ with gr.Column():
671
  gr.Markdown("### πŸ“‹ User Details")
672
  name_input = gr.Textbox(
673
  label="πŸ‘€ Full Name",
674
+ placeholder="Enter your full name..."
 
675
  )
676
  roll_no_input = gr.Textbox(
677
  label="πŸ”’ Roll Number / ID",
678
+ placeholder="Enter roll number or ID..."
 
679
  )
680
+ register_btn = gr.Button("πŸ“Έ Capture & Register", variant="primary")
681
 
682
+ with gr.Column():
683
  gr.Markdown("### πŸ“Š Registration Status")
684
  registration_output = gr.Textbox(
685
  label="ℹ️ Status",
686
  interactive=False,
687
+ lines=5
 
688
  )
689
  registration_image = gr.Image(
690
  label="πŸ“Έ Captured Face",
691
+ interactive=False
 
692
  )
693
 
694
  # Attendance Tab
 
696
  gr.Markdown("## βœ… Mark Your Attendance")
697
  gr.Markdown("*Click the button below to detect your face and mark attendance*")
698
 
699
+ detect_btn = gr.Button("πŸ” Detect & Mark Attendance", variant="primary")
 
 
 
 
700
 
701
+ with gr.Row():
702
+ with gr.Column():
703
  detection_image = gr.Image(
704
  label="πŸ“Έ Detection Result",
705
+ interactive=False
 
706
  )
707
+ with gr.Column():
708
  detection_status = gr.Textbox(
709
  label="πŸ“‘ Status",
710
+ interactive=False
 
711
  )
712
  recognized_users = gr.Textbox(
713
  label="🎯 Result",
714
  lines=8,
715
+ interactive=False
 
716
  )
717
 
718
  # Reports Tab
 
720
  gr.Markdown("## πŸ“Š Attendance Reports & Analytics")
721
 
722
  # Filter Section
723
+ with gr.Row():
724
+ with gr.Column():
725
  gr.Markdown("### πŸ“… Select Date Range")
726
  filter_type = gr.Radio(
727
  choices=["Today", "This Week", "This Month", "Custom Range", "All Time"],
728
  value="Today",
729
+ label="Filter Period"
 
730
  )
731
+ with gr.Column():
732
  gr.Markdown("### πŸ“† Custom Date Range")
733
  start_date = gr.Textbox(
734
  label="Start Date",
735
+ placeholder="YYYY-MM-DD (e.g., 2024-01-01)"
 
736
  )
737
  end_date = gr.Textbox(
738
  label="End Date",
739
+ placeholder="YYYY-MM-DD (e.g., 2024-12-31)"
 
740
  )
741
 
742
  # Action Buttons
743
  gr.Markdown("### πŸŽ›οΈ Actions")
744
+ with gr.Row():
745
+ filter_btn = gr.Button("πŸ” Apply Filter", variant="primary")
746
+ users_btn = gr.Button("πŸ‘₯ All Users", variant="secondary")
747
+ download_btn = gr.Button("πŸ“₯ Download CSV", variant="secondary")
748
 
749
  # Report Info
750
  report_info = gr.Textbox(
751
  label="πŸ“Š Report Summary",
752
  interactive=False,
753
+ value="πŸ‘† Select a filter and click 'Apply Filter' to view records"
 
754
  )
755
 
756
  # Summary Stats
757
  gr.Markdown("### πŸ“ˆ Quick Stats")
758
  summary_output = gr.Dataframe(
759
  label="Statistics",
760
+ interactive=False
 
761
  )
762
 
763
  # Main Report Table
764
  gr.Markdown("### πŸ“‹ Attendance Records")
765
  report_output = gr.Dataframe(
766
  label="Records",
767
+ interactive=False
 
768
  )
769
 
770
  # Download Section
771
+ download_file = gr.File(label="πŸ“₯ Downloaded Report")
772
 
773
  # Event Handlers
774
  start_btn.click(start_camera_interface, inputs=None, outputs=camera_status)