dhanvanth183 commited on
Commit
36ed9a4
·
verified ·
1 Parent(s): 362bfcd

Update app.py

Browse files

Updated UI with adding language, changed the option input to text input for duration and rephrased names of Text headings

Files changed (1) hide show
  1. app.py +97 -44
app.py CHANGED
@@ -1,10 +1,11 @@
1
  import streamlit as st
2
  import json
 
3
  from openai_llm import LessonPlanGenerator
4
 
5
  # Page configuration
6
  st.set_page_config(
7
- page_title="Lesson Plan Generator",
8
  page_icon="📚",
9
  layout="wide"
10
  )
@@ -93,25 +94,25 @@ st.markdown("""
93
 
94
 
95
  # Initialize generator
96
- @st.cache_resource
97
- def get_generator():
98
- return LessonPlanGenerator()
99
 
100
 
101
- generator = get_generator()
102
 
103
  # Header
104
  st.title("WizLab Lesson Plan Generator")
105
  st.markdown("We help you generate lesson plans tailored to your needs.")
106
 
107
  # Input section
108
- st.header("📝 Input Your Requirements")
109
 
110
  # Create two columns for input fields
111
  col1, col2 = st.columns(2)
112
 
113
  with col1:
114
- topic = st.text_input("Topic", placeholder="e.g., Introduction to Photosynthesis")
115
 
116
  age_group_options = ["Elementary (6-11)", "Middle School (12-14)",
117
  "High School (15-18)", "Adult Learners", "Other"]
@@ -121,16 +122,50 @@ with col1:
121
  else:
122
  age_group = age_group_selection
123
 
124
- with col2:
125
- duration_options = ["30 minutes", "45 minutes", "60 minutes", "90 minutes", "Other"]
126
- duration_selection = st.selectbox("Lesson Duration", duration_options)
127
- if duration_selection == "Other":
128
- duration = st.text_input("Specify Duration")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  else:
130
- duration = duration_selection
 
 
 
 
 
 
 
131
 
132
- proficiency_options = ["Beginner", "Intermediate", "Advanced", "Other"]
133
- proficiency_selection = st.selectbox("Proficiency Level", proficiency_options)
 
 
 
 
 
 
 
 
134
  if proficiency_selection == "Other":
135
  proficiency = st.text_input("Specify Proficiency Level")
136
  else:
@@ -138,7 +173,7 @@ with col2:
138
 
139
  tech_options = ["Interactive Whiteboard", "Computers/Laptops",
140
  "Mobile Devices", "Internet Access", "None", "Other"]
141
- tech_selection = st.multiselect("Technology Requirements", tech_options)
142
 
143
  if "Other" in tech_selection:
144
  other_tech = st.text_input("Specify Other Technology Requirements")
@@ -204,47 +239,65 @@ def format_content(data):
204
  return html_content
205
 
206
 
 
207
  # Generate button
208
  if st.button("Generate Lesson Plan", type="primary"):
209
  if not topic:
210
  st.error("Please enter a topic for the lesson plan.")
211
  else:
212
  with st.spinner("Generating your lesson plan..."):
 
 
 
 
 
 
 
 
 
 
 
 
213
  detailed_prompt = f"""
214
- Create a lesson plan for teaching '{topic}' to {age_group} students.
215
- Duration: {duration}
216
- Proficiency Level: {proficiency}
217
- Technology Requirements: {', '.join(tech_usage) if tech_usage else 'None'}
218
- """
 
219
 
220
  try:
221
- result = generator.generate_lesson_plan(detailed_prompt)
 
 
 
 
 
 
 
 
222
 
223
- # Clean up the structure if needed
224
- if "lessonPlan" in result:
225
- result = result["lessonPlan"]
226
 
227
- st.success("Lesson plan generated successfully!")
 
228
 
229
- # Create tabs for different views
230
- tab1, tab2 = st.tabs(["Formatted View", "Raw JSON"])
231
 
232
- with tab1:
233
- if isinstance(result, dict):
234
- st.markdown(format_content(result), unsafe_allow_html=True)
235
- else:
236
- st.error("Invalid response format")
237
-
238
- with tab2:
239
- st.json(result)
240
-
241
- # Download button
242
- st.download_button(
243
- label="Download Lesson Plan",
244
- data=json.dumps(result, indent=2),
245
- file_name="lesson_plan.json",
246
- mime="application/json"
247
- )
248
 
249
  except Exception as e:
250
  st.error(f"An error occurred: {str(e)}")
 
1
  import streamlit as st
2
  import json
3
+
4
  from openai_llm import LessonPlanGenerator
5
 
6
  # Page configuration
7
  st.set_page_config(
8
+ page_title="WizLab Lesson Plan Generator",
9
  page_icon="📚",
10
  layout="wide"
11
  )
 
94
 
95
 
96
  # Initialize generator
97
+ #@st.cache_resource
98
+ #def get_generator():
99
+ #return LessonPlanGenerator()
100
 
101
 
102
+ generator = LessonPlanGenerator()
103
 
104
  # Header
105
  st.title("WizLab Lesson Plan Generator")
106
  st.markdown("We help you generate lesson plans tailored to your needs.")
107
 
108
  # Input section
109
+ st.header("Input Your Requirements")
110
 
111
  # Create two columns for input fields
112
  col1, col2 = st.columns(2)
113
 
114
  with col1:
115
+ topic = st.text_input("Topic", placeholder="e.g., Lesson Plan to teach Spanish numbers as third language to English Speaking students ")
116
 
117
  age_group_options = ["Elementary (6-11)", "Middle School (12-14)",
118
  "High School (15-18)", "Adult Learners", "Other"]
 
122
  else:
123
  age_group = age_group_selection
124
 
125
+ language_options = [
126
+ "English", "日本語 (Japanese)", "中文 (Mandarin Chinese)",
127
+ "Español (Spanish)", "हिंदी (Hindi)", "한국어 (Korean)",
128
+ "Deutsch (German)", "Français (French)", "Português (Portuguese)",
129
+ "العربية (Arabic)", "Русский (Russian)", "Other"
130
+ ]
131
+
132
+ language_selection = st.selectbox("Select Output Language", language_options)
133
+ LANGUAGE_MAPPING = {
134
+ "日本語 (Japanese)": "Japanese",
135
+ "中文 (Mandarin Chinese)": "Mandarin Chinese",
136
+ "Español (Spanish)": "Spanish",
137
+ "हिंदी (Hindi)": "Hindi",
138
+ "한국어 (Korean)": "Korean",
139
+ "Deutsch (German)": "German",
140
+ "Français (French)": "French",
141
+ "Português (Portuguese)": "Portuguese",
142
+ "العربية (Arabic)": "Arabic",
143
+ "Русский (Russian)": "Russian"
144
+ }
145
+
146
+ # Then in your language selection code:
147
+ if language_selection == "Other":
148
+ language = st.text_input("Specify Language")
149
  else:
150
+ # Use mapping if available, otherwise use the base language name
151
+ language = LANGUAGE_MAPPING.get(language_selection, language_selection)
152
+
153
+ #if language_selection == "Other":
154
+ # language = st.text_input("Specify Language")
155
+ # else:
156
+ # Extract the base language name without the native script
157
+ # language = language_selection.split(" (")[0] if " (" in language_selection else language_selection
158
 
159
+ with col2:
160
+ #duration_options = ["30 minutes", "45 minutes", "60 minutes", "90 minutes", "Other"]
161
+ #duration_selection = st.selectbox("Lesson Duration", duration_options)
162
+ #if duration_selection == "Other":
163
+ # duration = st.text_input("Specify Duration")
164
+ #else:
165
+ # duration = duration_selection
166
+ duration = st.text_input("Duration [in minutes]", placeholder = "e.g., 25 minutes")
167
+ proficiency_options = ["Beginner [A1]", "Elementary [A2]", "Intermediate[B1, B2]", "Advanced[C1]", "Proficient [C2]", "Other"]
168
+ proficiency_selection = st.selectbox("Proficiency Level [CEFR]", proficiency_options)
169
  if proficiency_selection == "Other":
170
  proficiency = st.text_input("Specify Proficiency Level")
171
  else:
 
173
 
174
  tech_options = ["Interactive Whiteboard", "Computers/Laptops",
175
  "Mobile Devices", "Internet Access", "None", "Other"]
176
+ tech_selection = st.multiselect("Accessible Tech Resources", tech_options)
177
 
178
  if "Other" in tech_selection:
179
  other_tech = st.text_input("Specify Other Technology Requirements")
 
239
  return html_content
240
 
241
 
242
+ # Generate button
243
  # Generate button
244
  if st.button("Generate Lesson Plan", type="primary"):
245
  if not topic:
246
  st.error("Please enter a topic for the lesson plan.")
247
  else:
248
  with st.spinner("Generating your lesson plan..."):
249
+ # Set default values if not provided
250
+ if not duration:
251
+ duration = "30 minutes"
252
+ if not proficiency:
253
+ proficiency = "Intermediate [B1, B2]"
254
+ if not age_group:
255
+ age_group = "Elementary (6-11)"
256
+ if not tech_usage:
257
+ tech_usage = ["White Board", "Internet Access"]
258
+ if not language:
259
+ language = "English"
260
+
261
  detailed_prompt = f"""
262
+ Create a lesson plan for teaching '{topic}' to {age_group} students.
263
+ Duration: {duration} minutes,
264
+ Proficiency Level [CEFR]: {proficiency},
265
+ Technology Requirements: {', '.join(tech_usage) if tech_usage else 'None'},
266
+ Generate response in {language} Language.
267
+ """
268
 
269
  try:
270
+ # Pass both the prompt and language
271
+ result = generator.generate_lesson_plan(detailed_prompt, language)
272
+
273
+ # Consistent parsing regardless of language
274
+ if isinstance(result, dict):
275
+ if "lessonPlan" in result:
276
+ lesson_content = result["lessonPlan"]
277
+ else:
278
+ lesson_content = result
279
 
280
+ st.success("Lesson plan generated successfully!")
 
 
281
 
282
+ # Create tabs for different views
283
+ tab1, tab2 = st.tabs(["Formatted View", "Raw JSON"])
284
 
285
+ with tab1:
286
+ st.markdown(format_content(lesson_content), unsafe_allow_html=True)
287
 
288
+ with tab2:
289
+ st.json(lesson_content)
290
+
291
+ # Download button
292
+ st.download_button(
293
+ label="Download Lesson Plan",
294
+ data=json.dumps(lesson_content, indent=2, ensure_ascii=False),
295
+ # ensure_ascii=False for proper Unicode handling
296
+ file_name=f"lesson_plan_{language}.json",
297
+ mime="application/json"
298
+ )
299
+ else:
300
+ st.error("Invalid response format")
 
 
 
301
 
302
  except Exception as e:
303
  st.error(f"An error occurred: {str(e)}")