|
import streamlit as st |
|
from fpdf import FPDF |
|
|
|
|
|
st.title("Class Timetable Generator") |
|
st.write("Generate and manage class schedules effortlessly.") |
|
|
|
|
|
teachers_input = st.text_input("Enter the names of teachers (comma-separated)") |
|
subjects_input = st.text_input("Enter the subjects (comma-separated)") |
|
slots_input = st.text_input("Enter the available slots (comma-separated)") |
|
|
|
|
|
def generate_timetable(teachers, subjects, slots): |
|
""" |
|
Generate a basic timetable by assigning teachers to subjects and slots. |
|
""" |
|
timetable = [] |
|
for i in range(min(len(teachers), len(subjects), len(slots))): |
|
timetable.append(f"Slot: {slots[i]} | Subject: {subjects[i]} | Teacher: {teachers[i]}") |
|
|
|
if len(timetable) == 0: |
|
timetable.append("No timetable could be generated. Ensure there are enough teachers, subjects, and slots.") |
|
|
|
return "\n".join(timetable) |
|
|
|
|
|
def save_timetable_as_pdf(timetable, filename="timetable.pdf"): |
|
""" |
|
Save the generated timetable as a PDF. |
|
""" |
|
pdf = FPDF() |
|
pdf.add_page() |
|
pdf.set_font("Arial", size=12) |
|
|
|
pdf.cell(200, 10, txt="Class Timetable", ln=True, align="C") |
|
pdf.ln(10) |
|
|
|
for line in timetable.split("\n"): |
|
pdf.cell(200, 10, txt=line, ln=True) |
|
|
|
pdf.output(filename) |
|
return filename |
|
|
|
|
|
if st.button("Generate Timetable"): |
|
if teachers_input and subjects_input and slots_input: |
|
teachers = [t.strip() for t in teachers_input.split(",")] |
|
subjects = [s.strip() for s in subjects_input.split(",")] |
|
slots = [s.strip() for s in slots_input.split(",")] |
|
|
|
st.info("Generating timetable...") |
|
timetable = generate_timetable(teachers, subjects, slots) |
|
|
|
st.success("Timetable generated successfully!") |
|
st.text_area("Generated Timetable", timetable, height=300) |
|
|
|
|
|
if st.button("Download PDF"): |
|
pdf_file = save_timetable_as_pdf(timetable) |
|
with open(pdf_file, "rb") as file: |
|
st.download_button("Download Timetable PDF", file, file_name="timetable.pdf") |
|
else: |
|
st.warning("Please fill all fields to generate the timetable.") |
|
|