dhanvanth183 commited on
Commit
d914c99
·
verified ·
1 Parent(s): a8b36c3

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -305
app.py DELETED
@@ -1,305 +0,0 @@
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="WizLab Lesson Plan Generator",
8
- page_icon="📚",
9
- layout="wide"
10
- )
11
-
12
- # Custom CSS with improved styling
13
- st.markdown("""
14
- <style>
15
- .main-container {
16
- background-color: white;
17
- border-radius: 8px;
18
- padding: 25px;
19
- margin: 20px 0;
20
- box-shadow: 0 2px 8px rgba(0,0,0,0.1);
21
- }
22
-
23
- .section {
24
- margin: 15px 0;
25
- padding: 10px 0;
26
- }
27
-
28
- .section-level-0 {
29
- border-bottom: 2px solid #e8eaf6;
30
- margin-bottom: 20px;
31
- }
32
-
33
- .section-level-1 {
34
- margin-left: 20px;
35
- border-left: 2px solid #e8eaf6;
36
- padding-left: 15px;
37
- }
38
-
39
- .section-level-2 {
40
- margin-left: 15px;
41
- padding-left: 10px;
42
- }
43
-
44
- .section-header-main {
45
- color: #1a237e;
46
- font-size: 20px;
47
- font-weight: 600;
48
- margin-bottom: 15px;
49
- padding-bottom: 5px;
50
- border-bottom: 1px solid #e8eaf6;
51
- }
52
-
53
- .section-header-sub {
54
- color: #283593;
55
- font-size: 16px;
56
- font-weight: 500;
57
- margin: 10px 0;
58
- }
59
-
60
- .section-content {
61
- color: #333;
62
- margin: 10px 0 10px 20px;
63
- line-height: 1.5;
64
- }
65
-
66
- .list-item {
67
- margin: 8px 0;
68
- color: #333;
69
- padding-left: 20px;
70
- position: relative;
71
- }
72
-
73
- .list-item:before {
74
- content: "•";
75
- position: absolute;
76
- left: 0;
77
- color: #3949ab;
78
- }
79
-
80
- .nested-content {
81
- margin-left: 20px;
82
- padding-left: 15px;
83
- border-left: 2px solid #e8eaf6;
84
- }
85
-
86
- .timing-label {
87
- color: #1565c0;
88
- font-weight: 500;
89
- font-style: italic;
90
- }
91
- </style>
92
- """, unsafe_allow_html=True)
93
-
94
-
95
- # Initialize generator
96
- #@st.cache_resource
97
- #def get_generator():
98
- #return LessonPlanGenerator()
99
-
100
-
101
- generator = LessonPlanGenerator()
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., Lesson Plan to teach Spanish numbers as third language to English Speaking students ")
115
-
116
- age_group_options = ["Elementary (6-11)", "Middle School (12-14)",
117
- "High School (15-18)", "Adult Learners", "Other"]
118
- age_group_selection = st.selectbox("Target Age Group", age_group_options)
119
- if age_group_selection == "Other":
120
- age_group = st.text_input("Specify Age Group")
121
- else:
122
- age_group = age_group_selection
123
-
124
- language_options = [
125
- "English", "日本語 (Japanese)", "中文 (Mandarin Chinese)",
126
- "Español (Spanish)", "हिंदी (Hindi)", "한국어 (Korean)",
127
- "Deutsch (German)", "Français (French)", "Português (Portuguese)",
128
- "العربية (Arabic)", "Русский (Russian)", "Other"
129
- ]
130
-
131
- language_selection = st.selectbox("Select Output Language", language_options)
132
- LANGUAGE_MAPPING = {
133
- "日本語 (Japanese)": "Japanese",
134
- "中文 (Mandarin Chinese)": "Mandarin Chinese",
135
- "Español (Spanish)": "Spanish",
136
- "हिंदी (Hindi)": "Hindi",
137
- "한국어 (Korean)": "Korean",
138
- "Deutsch (German)": "German",
139
- "Français (French)": "French",
140
- "Português (Portuguese)": "Portuguese",
141
- "العربية (Arabic)": "Arabic",
142
- "Русский (Russian)": "Russian"
143
- }
144
-
145
- # Then in your language selection code:
146
- if language_selection == "Other":
147
- language = st.text_input("Specify Language")
148
- else:
149
- # Use mapping if available, otherwise use the base language name
150
- language = LANGUAGE_MAPPING.get(language_selection, language_selection)
151
-
152
- #if language_selection == "Other":
153
- # language = st.text_input("Specify Language")
154
- # else:
155
- # Extract the base language name without the native script
156
- # language = language_selection.split(" (")[0] if " (" in language_selection else language_selection
157
-
158
- with col2:
159
- #duration_options = ["30 minutes", "45 minutes", "60 minutes", "90 minutes", "Other"]
160
- #duration_selection = st.selectbox("Lesson Duration", duration_options)
161
- #if duration_selection == "Other":
162
- # duration = st.text_input("Specify Duration")
163
- #else:
164
- # duration = duration_selection
165
- duration = st.text_input("Duration [in minutes]", placeholder = "e.g., 25 minutes")
166
- proficiency_options = ["Beginner [A1]", "Elementary [A2]", "Intermediate[B1, B2]", "Advanced[C1]", "Proficient [C2]", "Other"]
167
- proficiency_selection = st.selectbox("Proficiency Level [CEFR]", proficiency_options)
168
- if proficiency_selection == "Other":
169
- proficiency = st.text_input("Specify Proficiency Level")
170
- else:
171
- proficiency = proficiency_selection
172
-
173
- tech_options = ["Interactive Whiteboard", "Computers/Laptops",
174
- "Mobile Devices", "Internet Access", "None", "Other"]
175
- tech_selection = st.multiselect("Accessible Tech Resources", tech_options)
176
-
177
- if "Other" in tech_selection:
178
- other_tech = st.text_input("Specify Other Technology Requirements")
179
- tech_usage = [tech for tech in tech_selection if tech != "Other"] + [other_tech]
180
- else:
181
- tech_usage = tech_selection
182
-
183
-
184
- def format_content(data):
185
- html_content = '<div class="main-container">'
186
-
187
- def format_key(key):
188
- """Format key string to be more readable"""
189
- # Handle camelCase
190
- key = ''.join(' ' + char if char.isupper() else char for char in key).strip()
191
- # Replace underscores and normalize spaces
192
- key = key.replace('_', ' ').title()
193
- return key
194
-
195
- def process_value(value, level=0):
196
- if isinstance(value, dict):
197
- return process_dict(value, level)
198
- elif isinstance(value, list):
199
- return process_list(value, level)
200
- else:
201
- return f'<div class="section-content">{value}</div>'
202
-
203
- def process_dict(d, level):
204
- content = ""
205
- for key, value in d.items():
206
- formatted_key = format_key(key)
207
-
208
- section_class = "section-level-" + str(level)
209
- content += f'<div class="section {section_class}">'
210
-
211
- if level == 0:
212
- content += f'<div class="section-header-main">{formatted_key}</div>'
213
- else:
214
- content += f'<div class="section-header-sub">{formatted_key}</div>'
215
-
216
- if isinstance(value, dict) and any(isinstance(v, (dict, list)) for v in value.values()):
217
- content += process_value(value, level + 1)
218
- elif isinstance(value, list) and any(isinstance(item, dict) for item in value):
219
- content += process_value(value, level + 1)
220
- else:
221
- content += process_value(value, level + 1)
222
-
223
- content += '</div>'
224
- return content
225
-
226
- def process_list(lst, level):
227
- content = '<div class="section-content">'
228
- for item in lst:
229
- if isinstance(item, dict):
230
- content += process_dict(item, level + 1)
231
- else:
232
- content += f'<div class="list-item">{item}</div>'
233
- content += '</div>'
234
- return content
235
-
236
- html_content += process_dict(data, 0)
237
- html_content += '</div>'
238
- return html_content
239
-
240
-
241
- # Generate button
242
- # Generate button
243
- if st.button("Generate Lesson Plan", type="primary"):
244
- if not topic:
245
- st.error("Please enter a topic for the lesson plan.")
246
- else:
247
- with st.spinner("Generating your lesson plan..."):
248
- # Set default values if not provided
249
- if not duration:
250
- duration = "30 minutes"
251
- if not proficiency:
252
- proficiency = "Intermediate [B1, B2]"
253
- if not age_group:
254
- age_group = "Elementary (6-11)"
255
- if not tech_usage:
256
- tech_usage = ["White Board", "Internet Access"]
257
- if not language:
258
- language = "English"
259
-
260
- detailed_prompt = f"""
261
- Create a lesson plan for teaching '{topic}' to {age_group} students.
262
- Duration: {duration} minutes,
263
- Proficiency Level [CEFR]: {proficiency},
264
- Technology Requirements: {', '.join(tech_usage) if tech_usage else 'None'},
265
- Generate response in {language} Language.
266
- """
267
-
268
- try:
269
- # Pass both the prompt and language
270
- result = generator.generate_lesson_plan(detailed_prompt, language)
271
-
272
- # Consistent parsing regardless of language
273
- if isinstance(result, dict):
274
- if "lessonPlan" in result:
275
- lesson_content = result["lessonPlan"]
276
- else:
277
- lesson_content = result
278
-
279
- st.success("Lesson plan generated successfully!")
280
-
281
- # Create tabs for different views
282
- tab1, tab2 = st.tabs(["Formatted View", "Raw JSON"])
283
-
284
- with tab1:
285
- st.markdown(format_content(lesson_content), unsafe_allow_html=True)
286
-
287
- with tab2:
288
- st.json(lesson_content)
289
-
290
- # Download button
291
- st.download_button(
292
- label="Download Lesson Plan",
293
- data=json.dumps(lesson_content, indent=2, ensure_ascii=False),
294
- # ensure_ascii=False for proper Unicode handling
295
- file_name=f"lesson_plan_{language}.json",
296
- mime="application/json"
297
- )
298
- else:
299
- st.error("Invalid response format")
300
-
301
- except Exception as e:
302
- st.error(f"An error occurred: {str(e)}")
303
-
304
- # Footer
305
- st.markdown("---")