Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,28 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from fpdf import FPDF
|
| 3 |
-
from groq import Groq
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
if not api_key:
|
| 10 |
-
st.error("API Key not found. Please set the GROQ_API_KEY environment variable in your Space settings.")
|
| 11 |
-
st.stop()
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
# Function to generate a timetable
|
| 17 |
def generate_timetable(teachers, subjects, slots):
|
| 18 |
"""
|
| 19 |
-
Generate a timetable
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
chat_completion = client.chat.completions.create(
|
| 30 |
-
messages=[{"role": "user", "content": prompt}],
|
| 31 |
-
model="llama3-8b-8192",
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
return chat_completion.choices[0].message.content
|
| 35 |
-
|
| 36 |
-
except Exception as e:
|
| 37 |
-
st.error(f"Error generating timetable: {e}")
|
| 38 |
-
return None
|
| 39 |
|
| 40 |
# Function to save timetable as PDF
|
| 41 |
def save_timetable_as_pdf(timetable, filename="timetable.pdf"):
|
|
@@ -55,15 +42,7 @@ def save_timetable_as_pdf(timetable, filename="timetable.pdf"):
|
|
| 55 |
pdf.output(filename)
|
| 56 |
return filename
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
st.title("Class Timetable Generator")
|
| 60 |
-
st.write("Generate and manage class schedules effortlessly.")
|
| 61 |
-
|
| 62 |
-
# Input fields
|
| 63 |
-
teachers_input = st.text_input("Enter the names of teachers (comma-separated)")
|
| 64 |
-
subjects_input = st.text_input("Enter the subjects (comma-separated)")
|
| 65 |
-
slots_input = st.text_input("Enter the available slots (comma-separated)")
|
| 66 |
-
|
| 67 |
if st.button("Generate Timetable"):
|
| 68 |
if teachers_input and subjects_input and slots_input:
|
| 69 |
teachers = [t.strip() for t in teachers_input.split(",")]
|
|
@@ -73,16 +52,13 @@ if st.button("Generate Timetable"):
|
|
| 73 |
st.info("Generating timetable...")
|
| 74 |
timetable = generate_timetable(teachers, subjects, slots)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
st.text_area("Generated Timetable", timetable, height=300)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
else:
|
| 86 |
-
st.error("Failed to generate the timetable. Please check the inputs or API settings.")
|
| 87 |
else:
|
| 88 |
st.warning("Please fill all fields to generate the timetable.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from fpdf import FPDF
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Streamlit App UI
|
| 5 |
+
st.title("Class Timetable Generator")
|
| 6 |
+
st.write("Generate and manage class schedules effortlessly.")
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Input fields for timetable generation
|
| 9 |
+
teachers_input = st.text_input("Enter the names of teachers (comma-separated)")
|
| 10 |
+
subjects_input = st.text_input("Enter the subjects (comma-separated)")
|
| 11 |
+
slots_input = st.text_input("Enter the available slots (comma-separated)")
|
| 12 |
|
| 13 |
+
# Function to generate a simple timetable
|
| 14 |
def generate_timetable(teachers, subjects, slots):
|
| 15 |
"""
|
| 16 |
+
Generate a basic timetable by assigning teachers to subjects and slots.
|
| 17 |
"""
|
| 18 |
+
timetable = []
|
| 19 |
+
for i in range(min(len(teachers), len(subjects), len(slots))):
|
| 20 |
+
timetable.append(f"Slot: {slots[i]} | Subject: {subjects[i]} | Teacher: {teachers[i]}")
|
| 21 |
+
|
| 22 |
+
if len(timetable) == 0:
|
| 23 |
+
timetable.append("No timetable could be generated. Ensure there are enough teachers, subjects, and slots.")
|
| 24 |
+
|
| 25 |
+
return "\n".join(timetable)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Function to save timetable as PDF
|
| 28 |
def save_timetable_as_pdf(timetable, filename="timetable.pdf"):
|
|
|
|
| 42 |
pdf.output(filename)
|
| 43 |
return filename
|
| 44 |
|
| 45 |
+
# Generate timetable based on input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
if st.button("Generate Timetable"):
|
| 47 |
if teachers_input and subjects_input and slots_input:
|
| 48 |
teachers = [t.strip() for t in teachers_input.split(",")]
|
|
|
|
| 52 |
st.info("Generating timetable...")
|
| 53 |
timetable = generate_timetable(teachers, subjects, slots)
|
| 54 |
|
| 55 |
+
st.success("Timetable generated successfully!")
|
| 56 |
+
st.text_area("Generated Timetable", timetable, height=300)
|
|
|
|
| 57 |
|
| 58 |
+
# Option to download the timetable as a PDF
|
| 59 |
+
if st.button("Download PDF"):
|
| 60 |
+
pdf_file = save_timetable_as_pdf(timetable)
|
| 61 |
+
with open(pdf_file, "rb") as file:
|
| 62 |
+
st.download_button("Download Timetable PDF", file, file_name="timetable.pdf")
|
|
|
|
|
|
|
| 63 |
else:
|
| 64 |
st.warning("Please fill all fields to generate the timetable.")
|