Spaces:
Sleeping
Sleeping
File size: 2,637 Bytes
56c3c26 262eec5 56c3c26 262eec5 56c3c26 262eec5 56c3c26 262eec5 56c3c26 262eec5 56c3c26 262eec5 | 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 | import gradio as gr
import pandas as pd
import os
from datetime import datetime
# File to store student data
DATA_FILE = "students.csv"
# Create file if not exists
if not os.path.exists(DATA_FILE):
df = pd.DataFrame(columns=["Name", "Email", "Department", "Message", "Time"])
df.to_csv(DATA_FILE, index=False)
# Function to save data
def submit_form(name, email, department, message):
if name.strip() == "" or email.strip() == "":
return "β Name and Email are required!", load_data()
new_data = pd.DataFrame([{
"Name": name,
"Email": email,
"Department": department,
"Message": message,
"Time": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}])
new_data.to_csv(DATA_FILE, mode="a", header=False, index=False)
return f"β
Thank you {name}! Your response has been recorded.", load_data()
# Load all data
def load_data():
return pd.read_csv(DATA_FILE)
# Clear form function
def clear_form():
return "", "", None, "", "Form cleared!", load_data()
# Search function
def search_data(keyword):
df = pd.read_csv(DATA_FILE)
if keyword.strip() == "":
return df
filtered_df = df[
df.apply(lambda row: row.astype(str).str.contains(keyword, case=False).any(), axis=1)
]
return filtered_df
# UI Design
with gr.Blocks(title="College Admission App") as app:
gr.Markdown("## π College Registration Form")
gr.Markdown("Fill the form below to register.")
with gr.Row():
name = gr.Textbox(label="Full Name")
email = gr.Textbox(label="Email Address")
department = gr.Dropdown(
["Computer Science", "Business", "Engineering", "Mathematics", "Other"],
label="Select Department"
)
message = gr.Textbox(label="Why do you want to join?", lines=4)
with gr.Row():
submit_btn = gr.Button("Submit Application")
clear_btn = gr.Button("Clear Form")
output = gr.Textbox(label="Status")
gr.Markdown("## π Submitted Applications")
data_table = gr.Dataframe(value=load_data(), interactive=False)
gr.Markdown("## π Search Applications")
search_box = gr.Textbox(label="Enter keyword to search")
search_btn = gr.Button("Search")
# Button actions
submit_btn.click(
submit_form,
inputs=[name, email, department, message],
outputs=[output, data_table]
)
clear_btn.click(
clear_form,
outputs=[name, email, department, message, output, data_table]
)
search_btn.click(
search_data,
inputs=search_box,
outputs=data_table
)
app.launch() |