Update app.py
Browse files
app.py
CHANGED
|
@@ -634,23 +634,30 @@ button.primary:active {
|
|
| 634 |
}
|
| 635 |
"""
|
| 636 |
|
| 637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
# Header
|
| 639 |
-
gr.Markdown("# π― Face Recognition Attendance System"
|
| 640 |
-
gr.Markdown("### Powered by UniFace (RetinaFace + ArcFace)"
|
| 641 |
|
| 642 |
# Camera Tab
|
| 643 |
with gr.Tab("π· Camera"):
|
| 644 |
gr.Markdown("## π· Camera Control")
|
| 645 |
-
with gr.Row(
|
| 646 |
-
start_btn = gr.Button("βΆοΈ Start Camera", variant="primary"
|
| 647 |
-
stop_btn = gr.Button("βΉοΈ Stop Camera", variant="secondary"
|
| 648 |
-
refresh_btn = gr.Button("π Refresh Preview", variant="secondary"
|
| 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(
|
| 663 |
-
with gr.Column(
|
| 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"
|
| 676 |
|
| 677 |
-
with gr.Column(
|
| 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(
|
| 703 |
-
with gr.Column(
|
| 704 |
detection_image = gr.Image(
|
| 705 |
label="πΈ Detection Result",
|
| 706 |
-
interactive=False
|
| 707 |
-
height=400
|
| 708 |
)
|
| 709 |
-
with gr.Column(
|
| 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(
|
| 728 |
-
with gr.Column(
|
| 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(
|
| 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(
|
| 752 |
-
filter_btn = gr.Button("π Apply Filter", variant="primary"
|
| 753 |
-
users_btn = gr.Button("π₯ All Users", variant="secondary"
|
| 754 |
-
download_btn = gr.Button("π₯ Download CSV", variant="secondary"
|
| 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"
|
| 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)
|