Spaces:
Sleeping
Sleeping
File size: 3,963 Bytes
f83e458 3c8c6ec b0b651f 2167bd6 b0b651f f83e458 3c8c6ec fc88781 3c8c6ec f83e458 3c8c6ec f83e458 3c8c6ec f83e458 dfe052f 4bef520 3931be8 4bef520 3c8c6ec f83e458 4bef520 be00862 06f7d90 3931be8 be00862 3931be8 be00862 3931be8 be00862 3c8c6ec f83e458 3c8c6ec f83e458 dfe052f 3c8c6ec f83e458 3c8c6ec f83e458 dfe052f f83e458 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import gradio as gr
import pandas as pd
import os
from datetime import datetime
# Attendance Tracker Setup
try:
if not os.path.exists("attendance_records"):
os.makedirs("attendance_records")
except error:
print(error)
# Helper Functions
def log_attendance(name, day, date, status):
month = datetime.strptime(date, "%Y-%m-%d").strftime("%Y-%m")
file_path = f"attendance_records/{month}.csv"
# Load or create attendance sheet for the month
if os.path.exists(file_path):
df = pd.read_csv(file_path)
else:
df = pd.DataFrame(columns=["Name", "Day", "Date", "Status"])
# Add new attendance record
new_entry = {"Name": name, "Day": day, "Date": date, "Status": status}
df = pd.concat([df, pd.DataFrame([new_entry])], ignore_index=True)
# Save back to the file
df.to_csv(file_path, index=False)
return "Attendance logged successfully!"
def calculate_fees():
attendance_summaries = []
for file in os.listdir("attendance_records"):
if file.endswith(".csv"):
file_path = os.path.join("attendance_records", file)
df = pd.read_csv(file_path)
# Calculate fees for each candidate
fees_summary = df[df["Status"] == "Present"].groupby("Name").size() * (1000 / 12) # Example: Monthly fees divided by 12
fees_summary.name = "Fees"
# Merge fees into the attendance sheet
df = df.merge(fees_summary, on="Name", how="left")
# Save updated file
df.to_csv(file_path, index=False)
# Summarize for all candidates
attendance_summaries.append(df[["Name", "Fees"]].drop_duplicates())
if attendance_summaries:
summary_df = pd.concat(attendance_summaries).drop_duplicates()
summary_df.to_csv("attendance_records/fees_summary.csv", index=False)
return "Fees calculated and updated successfully!"
return "No attendance records found for fees calculation."
# Gradio Interface
def submit_attendance(name, day, date, status):
return log_attendance(name, day, date, status)
def generate_fees():
return calculate_fees()
def is_month_end():
today = datetime.now()
return (today.day == (pd.Period(today.strftime("%Y-%m")).days_in_month))
# Function to extract data from Excel
def get_dropdown_options(file_path, column_name):
# Read the Excel file
df = pd.read_excel(file_path)
# Extract the unique values from the specified column
options = df["Name"].dropna().unique().tolist()
options.sort()
return options
with gr.Blocks() as app:
gr.Markdown("# Attendance Tracker")
with gr.Row():
# name = gr.Textbox(label="Name")
file_path = "participants_form.xlsx"
column_name = "Name"
options = get_dropdown_options(file_path, column_name)
name = gr.Dropdown(choices=options, label="Select an Option", show_label=True)
# output = gr.Textbox(label="You Selected")
# def show_selection(choice):
# return f"You selected: {choice}"
# name.change(show_selection, inputs=[name], outputs=[output])
day = gr.Textbox(label="Day")
date = gr.Textbox(label="Date (YYYY-MM-DD)")
status = gr.Radio(["Present", "Absent"], label="Status")
submit_button = gr.Button("Submit Attendance")
submit_message = gr.Textbox(label="Message", interactive=False)
calculate_button = gr.Button("Calculate Fees", interactive=is_month_end())
calculate_message = gr.Textbox(label="Fees Calculation Message", interactive=False)
submit_button.click(submit_attendance, inputs=[name, day, date, status], outputs=[submit_message])
calculate_button.click(generate_fees, outputs=[calculate_message])
def update_calculate_button():
return gr.update(interactive=is_month_end())
app.load(update_calculate_button, None, [calculate_button])
app.launch()
|