dhanvanth183's picture
Rename Streamlit_app.py to app.py
c9532ff verified
raw
history blame
5.86 kB
import streamlit as st
import json
from openai_llm import LessonPlanGenerator
# Page configuration
st.set_page_config(
page_title="Lesson Plan Generator",
# page_icon="πŸ“š",
layout="wide"
)
# Custom CSS with corrected container styling
st.markdown("""
<style>
/* Main container */
.main-container {
background-color: white;
border-radius: 8px;
padding: 25px;
margin: 20px 0;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
/* Section styling */
.section {
margin: 15px 0;
padding: 10px 0;
border-bottom: 1px solid #eee;
}
/* Header styling */
.section-header {
color: #1a237e;
font-size: 18px;
font-weight: 600;
margin-bottom: 10px;
}
/* Content styling */
.section-content {
color: #333;
margin-left: 20px;
}
/* List item styling */
.list-item {
margin: 5px 0;
color: #333;
}
/* Nested content */
.nested-content {
margin-left: 20px;
padding-left: 10px;
border-left: 2px solid #e8eaf6;
}
</style>
""", unsafe_allow_html=True)
# Initialize generator
@st.cache_resource
def get_generator():
return LessonPlanGenerator()
generator = get_generator()
# Header
st.title("WizLab Lesson Plan Generator")
st.markdown("We help you generate lesson plans tailored to your needs.")
# Input section
st.header("πŸ“ Input Your Requirements")
# Create two columns for input fields
col1, col2 = st.columns(2)
with col1:
topic = st.text_input("Topic", placeholder="e.g., Introduction to Photosynthesis")
age_group_options = ["Elementary (6-11)", "Middle School (12-14)",
"High School (15-18)", "Adult Learners", "Other"]
age_group_selection = st.selectbox("Target Age Group", age_group_options)
if age_group_selection == "Other":
age_group = st.text_input("Specify Age Group")
else:
age_group = age_group_selection
with col2:
duration_options = ["30 minutes", "45 minutes", "60 minutes", "90 minutes", "Other"]
duration_selection = st.selectbox("Lesson Duration", duration_options)
if duration_selection == "Other":
duration = st.text_input("Specify Duration")
else:
duration = duration_selection
proficiency_options = ["Beginner", "Intermediate", "Advanced", "Other"]
proficiency_selection = st.selectbox("Proficiency Level", proficiency_options)
if proficiency_selection == "Other":
proficiency = st.text_input("Specify Proficiency Level")
else:
proficiency = proficiency_selection
tech_options = ["Interactive Whiteboard", "Computers/Laptops",
"Mobile Devices", "Internet Access", "None", "Other"]
tech_selection = st.multiselect("Technology Requirements", tech_options)
if "Other" in tech_selection:
other_tech = st.text_input("Specify Other Technology Requirements")
tech_usage = [tech for tech in tech_selection if tech != "Other"] + [other_tech]
else:
tech_usage = tech_selection
def format_content(data):
html_content = '<div class="main-container">'
def process_value(value, level=0):
if isinstance(value, dict):
return process_dict(value, level)
elif isinstance(value, list):
return process_list(value, level)
else:
return f'<div class="section-content">{value}</div>'
def process_dict(d, level):
content = ""
for key, value in d.items():
formatted_key = key.replace("_", " ").title()
content += f'<div class="section">'
content += f'<div class="section-header">{formatted_key}</div>'
content += process_value(value, level + 1)
content += '</div>'
return content
def process_list(lst, level):
content = '<div class="section-content">'
for item in lst:
if isinstance(item, dict):
content += process_dict(item, level + 1)
else:
content += f'<div class="list-item">β€’ {item}</div>'
content += '</div>'
return content
html_content += process_dict(data, 0)
html_content += '</div>'
return html_content
# Generate button
if st.button("Generate Lesson Plan", type="primary"):
if not topic:
st.error("Please enter a topic for the lesson plan.")
else:
with st.spinner("Generating your lesson plan..."):
detailed_prompt = f"""
Create a lesson plan for teaching '{topic}' to {age_group} students.
Duration: {duration}
Proficiency Level: {proficiency}
Technology Requirements: {', '.join(tech_usage) if tech_usage else 'None'}
"""
try:
result = generator.generate_lesson_plan(detailed_prompt)
st.success("Lesson plan generated successfully!")
# Create tabs for different views
tab1, tab2 = st.tabs(["Formatted View", "Raw JSON"])
with tab1:
if isinstance(result, dict):
# Display formatted content in white container
st.markdown(format_content(result), unsafe_allow_html=True)
else:
st.error("Invalid response format")
with tab2:
st.json(result)
# Download button
st.download_button(
label="Download Lesson Plan",
data=json.dumps(result, indent=2),
file_name="lesson_plan.json",
mime="application/json"
)
except Exception as e:
st.error(f"An error occurred: {str(e)}")
# Footer
st.markdown("---")