Spaces:
Runtime error
Runtime error
File size: 4,447 Bytes
ae0f384 b1f78f1 ae0f384 d4dd98e b1f78f1 ae0f384 d4dd98e b1f78f1 ae0f384 d4dd98e 1047250 b1f78f1 ae0f384 1047250 ae0f384 1047250 ae0f384 1047250 b1f78f1 ae0f384 b1f78f1 ae0f384 1047250 ae0f384 1047250 ae0f384 b1f78f1 |
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# import sqlite3
# import pandas as pd
# import gradio as gr
# from database import initialize_database
# # Initialize DB once at startup
# initialize_database()
# def query_students(department, year):
# conn = sqlite3.connect("college.db")
# query = "SELECT * FROM student WHERE 1=1"
# if department != "All":
# query += f" AND major = '{department}'"
# if year != "All":
# query += f" AND year_of_enrollment = {year}"
# df = pd.read_sql_query(query, conn)
# conn.close()
# return df
# def query_courses(department):
# conn = sqlite3.connect("college.db")
# query = "SELECT * FROM course"
# if department != "All":
# query += f" WHERE department = '{department}'"
# df = pd.read_sql_query(query, conn)
# conn.close()
# return df
# # Get list of unique years from DB to populate dropdown dynamically (optional)
# def get_years():
# conn = sqlite3.connect("college.db")
# df = pd.read_sql_query("SELECT DISTINCT year_of_enrollment FROM student ORDER BY year_of_enrollment", conn)
# conn.close()
# years = df["year_of_enrollment"].tolist()
# years = [str(y) for y in years]
# years.insert(0, "All")
# return years
# departments = ["All", "Computer Science", "Mechanical Engineering", "ECE", "Civil", "IT", "CSE", "AI"]
# with gr.Blocks() as demo:
# gr.Markdown("# College Database Dashboard")
# with gr.Tab("Students"):
# with gr.Row():
# dept_input = gr.Dropdown(choices=departments, label="Department", value="All")
# year_input = gr.Dropdown(choices=get_years(), label="Year of Enrollment", value="All")
# student_table = gr.Dataframe()
# query_btn = gr.Button("Show Students")
# query_btn.click(fn=query_students, inputs=[dept_input, year_input], outputs=student_table)
# with gr.Tab("Courses"):
# course_dept_input = gr.Dropdown(choices=departments, label="Department", value="All")
# course_table = gr.Dataframe()
# course_btn = gr.Button("Show Courses")
# course_btn.click(fn=query_courses, inputs=course_dept_input, outputs=course_table)
# if __name__ == "__main__":
# demo.launch()
import streamlit as st
import pandas as pd
import sqlite3
from database import initialize_database
# Initialize DB on start
initialize_database()
# Function to fetch filtered students
def get_students(department, year):
conn = sqlite3.connect("college.db")
query = "SELECT * FROM student WHERE 1=1"
if department != "All":
query += f" AND major = '{department}'"
if year != "All":
query += f" AND year_of_enrollment = {year}"
df = pd.read_sql_query(query, conn)
conn.close()
return df
# Function to fetch filtered courses
def get_courses(department):
conn = sqlite3.connect("college.db")
query = "SELECT * FROM course"
if department != "All":
query += f" WHERE department = '{department}'"
df = pd.read_sql_query(query, conn)
conn.close()
return df
# Prepare filter options
departments = [
"All",
"Computer Science",
"Mechanical Engineering",
"ECE",
"Civil",
"IT",
"CSE",
"AI"
]
def get_years():
conn = sqlite3.connect("college.db")
df = pd.read_sql_query("SELECT DISTINCT year_of_enrollment FROM student ORDER BY year_of_enrollment", conn)
conn.close()
years = df["year_of_enrollment"].astype(str).tolist()
years.insert(0, "All")
return years
# Streamlit app UI
st.title("College Database Dashboard")
tab1, tab2 = st.tabs(["Students", "Courses"])
with tab1:
st.header("Student Records")
dept_filter = st.selectbox("Select Department", departments)
year_filter = st.selectbox("Select Year of Enrollment", get_years())
if st.button("Show Students"):
students_df = get_students(dept_filter, year_filter)
if students_df.empty:
st.info("No students found with the selected filters.")
else:
st.dataframe(students_df)
with tab2:
st.header("Course Records")
course_dept_filter = st.selectbox("Select Department", departments, key="course_dept")
if st.button("Show Courses"):
courses_df = get_courses(course_dept_filter)
if courses_df.empty:
st.info("No courses found with the selected department.")
else:
st.dataframe(courses_df)
|