Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|