AbdulWahab14 commited on
Commit
262eec5
Β·
verified Β·
1 Parent(s): 9cef023

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -7
app.py CHANGED
@@ -14,7 +14,7 @@ if not os.path.exists(DATA_FILE):
14
  # Function to save data
15
  def submit_form(name, email, department, message):
16
  if name.strip() == "" or email.strip() == "":
17
- return "❌ Name and Email are required!"
18
 
19
  new_data = pd.DataFrame([{
20
  "Name": name,
@@ -26,15 +26,38 @@ def submit_form(name, email, department, message):
26
 
27
  new_data.to_csv(DATA_FILE, mode="a", header=False, index=False)
28
 
29
- return f"βœ… Thank you {name}! Your response has been recorded."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  # UI Design
32
  with gr.Blocks(title="College Admission App") as app:
33
  gr.Markdown("## πŸŽ“ College Registration Form")
34
  gr.Markdown("Fill the form below to register.")
35
 
36
- name = gr.Textbox(label="Full Name")
37
- email = gr.Textbox(label="Email Address")
 
38
 
39
  department = gr.Dropdown(
40
  ["Computer Science", "Business", "Engineering", "Mathematics", "Other"],
@@ -43,10 +66,35 @@ with gr.Blocks(title="College Admission App") as app:
43
 
44
  message = gr.Textbox(label="Why do you want to join?", lines=4)
45
 
46
- submit_btn = gr.Button("Submit Application")
 
 
47
 
48
  output = gr.Textbox(label="Status")
49
 
50
- submit_btn.click(submit_form, inputs=[name, email, department, message], outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- app.launch()
 
14
  # Function to save data
15
  def submit_form(name, email, department, message):
16
  if name.strip() == "" or email.strip() == "":
17
+ return "❌ Name and Email are required!", load_data()
18
 
19
  new_data = pd.DataFrame([{
20
  "Name": name,
 
26
 
27
  new_data.to_csv(DATA_FILE, mode="a", header=False, index=False)
28
 
29
+ return f"βœ… Thank you {name}! Your response has been recorded.", load_data()
30
+
31
+ # Load all data
32
+ def load_data():
33
+ return pd.read_csv(DATA_FILE)
34
+
35
+ # Clear form function
36
+ def clear_form():
37
+ return "", "", None, "", "Form cleared!", load_data()
38
+
39
+ # Search function
40
+ def search_data(keyword):
41
+ df = pd.read_csv(DATA_FILE)
42
+
43
+ if keyword.strip() == "":
44
+ return df
45
+
46
+ filtered_df = df[
47
+ df.apply(lambda row: row.astype(str).str.contains(keyword, case=False).any(), axis=1)
48
+ ]
49
+
50
+ return filtered_df
51
+
52
 
53
  # UI Design
54
  with gr.Blocks(title="College Admission App") as app:
55
  gr.Markdown("## πŸŽ“ College Registration Form")
56
  gr.Markdown("Fill the form below to register.")
57
 
58
+ with gr.Row():
59
+ name = gr.Textbox(label="Full Name")
60
+ email = gr.Textbox(label="Email Address")
61
 
62
  department = gr.Dropdown(
63
  ["Computer Science", "Business", "Engineering", "Mathematics", "Other"],
 
66
 
67
  message = gr.Textbox(label="Why do you want to join?", lines=4)
68
 
69
+ with gr.Row():
70
+ submit_btn = gr.Button("Submit Application")
71
+ clear_btn = gr.Button("Clear Form")
72
 
73
  output = gr.Textbox(label="Status")
74
 
75
+ gr.Markdown("## πŸ“‹ Submitted Applications")
76
+ data_table = gr.Dataframe(value=load_data(), interactive=False)
77
+
78
+ gr.Markdown("## πŸ”Ž Search Applications")
79
+ search_box = gr.Textbox(label="Enter keyword to search")
80
+ search_btn = gr.Button("Search")
81
+
82
+ # Button actions
83
+ submit_btn.click(
84
+ submit_form,
85
+ inputs=[name, email, department, message],
86
+ outputs=[output, data_table]
87
+ )
88
+
89
+ clear_btn.click(
90
+ clear_form,
91
+ outputs=[name, email, department, message, output, data_table]
92
+ )
93
+
94
+ search_btn.click(
95
+ search_data,
96
+ inputs=search_box,
97
+ outputs=data_table
98
+ )
99
 
100
+ app.launch()