File size: 2,394 Bytes
f2d3105
 
 
4a9df9c
 
 
24bd156
4a9df9c
 
 
 
f2d3105
4a9df9c
f2d3105
 
4a9df9c
f2d3105
4a9df9c
 
 
 
 
 
 
 
f2d3105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a9df9c
f2d3105
24bd156
 
 
 
 
f2d3105
 
 
4a9df9c
 
f2d3105
4a9df9c
 
 
 
 
f2d3105
 
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
import streamlit as st
from fpdf import FPDF

# Streamlit App UI
st.title("Class Timetable Generator")
st.write("Generate and manage class schedules effortlessly.")

# Input fields for timetable generation
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)")

# Function to generate a simple timetable
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)

# Function to save timetable as PDF
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)  # Add some space
    
    for line in timetable.split("\n"):
        pdf.cell(200, 10, txt=line, ln=True)
    
    pdf.output(filename)
    return filename

# Generate timetable based on input
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)

        # Option to download the timetable as a PDF
        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.")