Spaces:
Sleeping
Sleeping
Update app.py
Browse filesUpdated the streamlit UI to improve the parsing
app.py
CHANGED
|
@@ -5,14 +5,13 @@ from openai_llm import LessonPlanGenerator
|
|
| 5 |
# Page configuration
|
| 6 |
st.set_page_config(
|
| 7 |
page_title="Lesson Plan Generator",
|
| 8 |
-
|
| 9 |
layout="wide"
|
| 10 |
)
|
| 11 |
|
| 12 |
-
# Custom CSS with
|
| 13 |
st.markdown("""
|
| 14 |
<style>
|
| 15 |
-
/* Main container */
|
| 16 |
.main-container {
|
| 17 |
background-color: white;
|
| 18 |
border-radius: 8px;
|
|
@@ -21,39 +20,74 @@ st.markdown("""
|
|
| 21 |
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 22 |
}
|
| 23 |
|
| 24 |
-
/* Section styling */
|
| 25 |
.section {
|
| 26 |
margin: 15px 0;
|
| 27 |
padding: 10px 0;
|
| 28 |
-
border-bottom: 1px solid #eee;
|
| 29 |
}
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
color: #1a237e;
|
| 34 |
-
font-size:
|
| 35 |
font-weight: 600;
|
| 36 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
-
/* Content styling */
|
| 40 |
.section-content {
|
| 41 |
color: #333;
|
| 42 |
-
margin
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
-
/* List item styling */
|
| 46 |
.list-item {
|
| 47 |
-
margin:
|
| 48 |
color: #333;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
-
/* Nested content */
|
| 52 |
.nested-content {
|
| 53 |
margin-left: 20px;
|
| 54 |
-
padding-left:
|
| 55 |
border-left: 2px solid #e8eaf6;
|
| 56 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
</style>
|
| 58 |
""", unsafe_allow_html=True)
|
| 59 |
|
|
@@ -116,6 +150,14 @@ else:
|
|
| 116 |
def format_content(data):
|
| 117 |
html_content = '<div class="main-container">'
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
def process_value(value, level=0):
|
| 120 |
if isinstance(value, dict):
|
| 121 |
return process_dict(value, level)
|
|
@@ -127,10 +169,23 @@ def format_content(data):
|
|
| 127 |
def process_dict(d, level):
|
| 128 |
content = ""
|
| 129 |
for key, value in d.items():
|
| 130 |
-
formatted_key = key
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
content +=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
content += '</div>'
|
| 135 |
return content
|
| 136 |
|
|
@@ -140,7 +195,7 @@ def format_content(data):
|
|
| 140 |
if isinstance(item, dict):
|
| 141 |
content += process_dict(item, level + 1)
|
| 142 |
else:
|
| 143 |
-
content += f'<div class="list-item"
|
| 144 |
content += '</div>'
|
| 145 |
return content
|
| 146 |
|
|
@@ -164,6 +219,11 @@ if st.button("Generate Lesson Plan", type="primary"):
|
|
| 164 |
|
| 165 |
try:
|
| 166 |
result = generator.generate_lesson_plan(detailed_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
st.success("Lesson plan generated successfully!")
|
| 168 |
|
| 169 |
# Create tabs for different views
|
|
@@ -171,7 +231,6 @@ if st.button("Generate Lesson Plan", type="primary"):
|
|
| 171 |
|
| 172 |
with tab1:
|
| 173 |
if isinstance(result, dict):
|
| 174 |
-
# Display formatted content in white container
|
| 175 |
st.markdown(format_content(result), unsafe_allow_html=True)
|
| 176 |
else:
|
| 177 |
st.error("Invalid response format")
|
|
|
|
| 5 |
# Page configuration
|
| 6 |
st.set_page_config(
|
| 7 |
page_title="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;
|
|
|
|
| 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 |
|
|
|
|
| 150 |
def format_content(data):
|
| 151 |
html_content = '<div class="main-container">'
|
| 152 |
|
| 153 |
+
def format_key(key):
|
| 154 |
+
"""Format key string to be more readable"""
|
| 155 |
+
# Handle camelCase
|
| 156 |
+
key = ''.join(' ' + char if char.isupper() else char for char in key).strip()
|
| 157 |
+
# Replace underscores and normalize spaces
|
| 158 |
+
key = key.replace('_', ' ').title()
|
| 159 |
+
return key
|
| 160 |
+
|
| 161 |
def process_value(value, level=0):
|
| 162 |
if isinstance(value, dict):
|
| 163 |
return process_dict(value, level)
|
|
|
|
| 169 |
def process_dict(d, level):
|
| 170 |
content = ""
|
| 171 |
for key, value in d.items():
|
| 172 |
+
formatted_key = format_key(key)
|
| 173 |
+
|
| 174 |
+
section_class = "section-level-" + str(level)
|
| 175 |
+
content += f'<div class="section {section_class}">'
|
| 176 |
+
|
| 177 |
+
if level == 0:
|
| 178 |
+
content += f'<div class="section-header-main">{formatted_key}</div>'
|
| 179 |
+
else:
|
| 180 |
+
content += f'<div class="section-header-sub">{formatted_key}</div>'
|
| 181 |
+
|
| 182 |
+
if isinstance(value, dict) and any(isinstance(v, (dict, list)) for v in value.values()):
|
| 183 |
+
content += process_value(value, level + 1)
|
| 184 |
+
elif isinstance(value, list) and any(isinstance(item, dict) for item in value):
|
| 185 |
+
content += process_value(value, level + 1)
|
| 186 |
+
else:
|
| 187 |
+
content += process_value(value, level + 1)
|
| 188 |
+
|
| 189 |
content += '</div>'
|
| 190 |
return content
|
| 191 |
|
|
|
|
| 195 |
if isinstance(item, dict):
|
| 196 |
content += process_dict(item, level + 1)
|
| 197 |
else:
|
| 198 |
+
content += f'<div class="list-item">{item}</div>'
|
| 199 |
content += '</div>'
|
| 200 |
return content
|
| 201 |
|
|
|
|
| 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
|
|
|
|
| 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")
|