Balaprime commited on
Commit
d4dd98e
·
verified ·
1 Parent(s): 1d7c45d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -47
app.py CHANGED
@@ -1,60 +1,28 @@
1
  import sqlite3
2
  import pandas as pd
3
  import gradio as gr
 
4
 
5
- DB_PATH = "college.db"
 
6
 
7
- def query_students(department):
8
- conn = sqlite3.connect(DB_PATH)
9
- if department == "All":
10
  df = pd.read_sql_query("SELECT * FROM student", conn)
11
  else:
12
- df = pd.read_sql_query("SELECT * FROM student WHERE major = ?", conn, params=(department,))
13
  conn.close()
14
  return df
15
 
16
- def query_employees(department):
17
- conn = sqlite3.connect(DB_PATH)
18
- if department == "All":
19
- df = pd.read_sql_query("SELECT * FROM employee", conn)
20
- else:
21
- df = pd.read_sql_query("SELECT * FROM employee WHERE department = ?", conn, params=(department,))
22
- conn.close()
23
- return df
24
-
25
- def query_courses(department):
26
- conn = sqlite3.connect(DB_PATH)
27
- if department == "All":
28
- df = pd.read_sql_query("SELECT * FROM course", conn)
29
- else:
30
- df = pd.read_sql_query("SELECT * FROM course WHERE department = ?", conn, params=(department,))
31
- conn.close()
32
- return df
33
-
34
- departments_students = ["All", "Computer Science", "Mechanical Engineering", "ECE", "Civil", "IT", "CSE", "AI"]
35
- departments_employees = ["All", "CSE", "ECE", "IT", "Civil", "Mechanical", "AI"]
36
- departments_courses = ["All", "CSE", "ECE", "IT", "Civil", "Mechanical", "AI"]
37
-
38
- with gr.Blocks() as demo:
39
- gr.Markdown("# 🎓 College Dashboard")
40
-
41
- with gr.Tab("Students"):
42
- dept_stu = gr.Dropdown(choices=departments_students, value="All", label="Filter by Major/Department")
43
- stu_table = gr.Dataframe(headers=["student_id","first_name","last_name","date_of_birth","email","phone_number","major","year_of_enrollment"], interactive=False)
44
- dept_stu.change(fn=query_students, inputs=dept_stu, outputs=stu_table)
45
- # Show all by default
46
- stu_table.value = query_students("All")
47
 
48
- with gr.Tab("Employees"):
49
- dept_emp = gr.Dropdown(choices=departments_employees, value="All", label="Filter by Department")
50
- emp_table = gr.Dataframe(headers=["employee_id","first_name","last_name","email","department","position","salary","date_of_joining"], interactive=False)
51
- dept_emp.change(fn=query_employees, inputs=dept_emp, outputs=emp_table)
52
- emp_table.value = query_employees("All")
53
 
54
- with gr.Tab("Courses"):
55
- dept_crs = gr.Dropdown(choices=departments_courses, value="All", label="Filter by Department")
56
- crs_table = gr.Dataframe(headers=["course_id","course_name","course_code","instructor_id","department","credits","semester"], interactive=False)
57
- dept_crs.change(fn=query_courses, inputs=dept_crs, outputs=crs_table)
58
- crs_table.value = query_courses("All")
59
 
60
- demo.launch()
 
 
1
  import sqlite3
2
  import pandas as pd
3
  import gradio as gr
4
+ from database import initialize_database
5
 
6
+ # Initialize the database at startup (creates tables if not exist)
7
+ initialize_database()
8
 
9
+ def query_students(dept):
10
+ conn = sqlite3.connect("college.db")
11
+ if dept == "All":
12
  df = pd.read_sql_query("SELECT * FROM student", conn)
13
  else:
14
+ df = pd.read_sql_query(f"SELECT * FROM student WHERE major = '{dept}'", conn)
15
  conn.close()
16
  return df
17
 
18
+ # Gradio UI components (simplified example)
19
+ dept_dropdown = gr.Dropdown(choices=["All", "CSE", "ECE", "IT", "AI"], label="Select Department")
20
+ stu_table = gr.Dataframe()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ def update_table(dept):
23
+ return query_students(dept)
 
 
 
24
 
25
+ demo = gr.Interface(fn=update_table, inputs=dept_dropdown, outputs=stu_table)
 
 
 
 
26
 
27
+ if __name__ == "__main__":
28
+ demo.launch()