Spaces:
Sleeping
Sleeping
Mahdi Naser Moghadasi commited on
Commit Β·
e7d5393
1
Parent(s): 3b03b98
Add Content Generator tab with educational material generation functionality
Browse files
app.py
CHANGED
|
@@ -180,6 +180,97 @@ def typewriter_effect(text, status_message):
|
|
| 180 |
# Final result without cursor - just return the text content
|
| 181 |
yield "", text
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
def generate_quiz_with_progress(topic, subject, grade_level, question_count, question_types):
|
| 184 |
"""Generate a quiz with progress updates"""
|
| 185 |
|
|
@@ -2895,7 +2986,89 @@ with gr.Blocks(
|
|
| 2895 |
outputs=[progress_display, lesson_plan_output],
|
| 2896 |
show_progress=True
|
| 2897 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2898 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2899 |
with gr.TabItem("π― Quiz Generator"):
|
| 2900 |
with gr.Row():
|
| 2901 |
with gr.Column():
|
|
|
|
| 180 |
# Final result without cursor - just return the text content
|
| 181 |
yield "", text
|
| 182 |
|
| 183 |
+
def generate_content_with_progress(topic, subject, grade_level, difficulty, content_type, content_length):
|
| 184 |
+
"""Generate educational content with progress updates"""
|
| 185 |
+
|
| 186 |
+
# Show progress bar
|
| 187 |
+
progress_html = """
|
| 188 |
+
<div class="progress-container">
|
| 189 |
+
<div class="generation-status">π Generating your educational content...</div>
|
| 190 |
+
<div class="progress-bar">
|
| 191 |
+
<div class="progress-fill"></div>
|
| 192 |
+
</div>
|
| 193 |
+
<div class="generation-status">Creating materials tailored to your specifications...</div>
|
| 194 |
+
</div>
|
| 195 |
+
"""
|
| 196 |
+
|
| 197 |
+
yield progress_html, ""
|
| 198 |
+
|
| 199 |
+
print(f"π Starting content generation for: {topic}")
|
| 200 |
+
print(f"π Subject: {subject}, Grade: {grade_level}, Type: {content_type}")
|
| 201 |
+
|
| 202 |
+
# Try Hugging Face API first if token is available
|
| 203 |
+
if HF_TOKEN:
|
| 204 |
+
try:
|
| 205 |
+
prompt = f"""Create comprehensive educational {content_type.lower()} for the following specifications:
|
| 206 |
+
|
| 207 |
+
Topic: {topic}
|
| 208 |
+
Subject: {subject}
|
| 209 |
+
Grade Level: {grade_level}
|
| 210 |
+
Difficulty: {difficulty}
|
| 211 |
+
Content Type: {content_type}
|
| 212 |
+
Length: {content_length}
|
| 213 |
+
|
| 214 |
+
Please generate:
|
| 215 |
+
1. Age-appropriate content for {grade_level} students
|
| 216 |
+
2. {difficulty} level complexity
|
| 217 |
+
3. {content_type} format
|
| 218 |
+
4. {content_length} content
|
| 219 |
+
5. Clear learning objectives
|
| 220 |
+
6. Engaging activities and exercises
|
| 221 |
+
7. Assessment questions
|
| 222 |
+
8. Additional resources
|
| 223 |
+
|
| 224 |
+
Make it practical, engaging, and ready for classroom use."""
|
| 225 |
+
|
| 226 |
+
ai_content = call_hugging_face_api(prompt)
|
| 227 |
+
|
| 228 |
+
if ai_content:
|
| 229 |
+
yield "", ai_content
|
| 230 |
+
return
|
| 231 |
+
except Exception as e:
|
| 232 |
+
print(f"β Content generation API error: {str(e)}")
|
| 233 |
+
|
| 234 |
+
# Fallback content
|
| 235 |
+
fallback_content = f"""# {content_type}: {topic}
|
| 236 |
+
|
| 237 |
+
## Learning Objectives
|
| 238 |
+
By the end of this {content_type.lower()}, students will be able to:
|
| 239 |
+
- Understand the basic concepts of {topic}
|
| 240 |
+
- Apply knowledge through practical exercises
|
| 241 |
+
- Demonstrate comprehension through assessment
|
| 242 |
+
|
| 243 |
+
## Grade Level: {grade_level}
|
| 244 |
+
## Subject: {subject}
|
| 245 |
+
## Difficulty: {difficulty}
|
| 246 |
+
|
| 247 |
+
---
|
| 248 |
+
|
| 249 |
+
## Introduction
|
| 250 |
+
This {content_type.lower()} is designed for {grade_level} students studying {subject}. The content focuses on {topic} at a {difficulty.lower()} level.
|
| 251 |
+
|
| 252 |
+
## Main Content
|
| 253 |
+
|
| 254 |
+
### Section 1: Understanding {topic}
|
| 255 |
+
[Content will be generated based on the specific topic and grade level]
|
| 256 |
+
|
| 257 |
+
### Section 2: Practical Applications
|
| 258 |
+
[Real-world examples and applications]
|
| 259 |
+
|
| 260 |
+
### Section 3: Activities and Exercises
|
| 261 |
+
[Hands-on activities appropriate for {grade_level}]
|
| 262 |
+
|
| 263 |
+
## Assessment
|
| 264 |
+
[Questions and exercises to test understanding]
|
| 265 |
+
|
| 266 |
+
## Additional Resources
|
| 267 |
+
[Links and references for further learning]
|
| 268 |
+
|
| 269 |
+
---
|
| 270 |
+
*Generated for {grade_level} {subject} students - {difficulty} level*"""
|
| 271 |
+
|
| 272 |
+
yield "", fallback_content
|
| 273 |
+
|
| 274 |
def generate_quiz_with_progress(topic, subject, grade_level, question_count, question_types):
|
| 275 |
"""Generate a quiz with progress updates"""
|
| 276 |
|
|
|
|
| 2986 |
outputs=[progress_display, lesson_plan_output],
|
| 2987 |
show_progress=True
|
| 2988 |
)
|
| 2989 |
+
|
| 2990 |
+
generate_content_btn.click(
|
| 2991 |
+
fn=generate_content_with_progress,
|
| 2992 |
+
inputs=[content_topic, content_subject, content_grade_level, content_difficulty, content_type, content_length],
|
| 2993 |
+
outputs=[progress_display, content_output],
|
| 2994 |
+
show_progress=True
|
| 2995 |
+
)
|
| 2996 |
+
|
| 2997 |
+
clear_content_btn.click(
|
| 2998 |
+
fn=lambda: ("", "Your educational content will appear here..."),
|
| 2999 |
+
inputs=[],
|
| 3000 |
+
outputs=[progress_display, content_output]
|
| 3001 |
+
)
|
| 3002 |
|
| 3003 |
+
with gr.TabItem("π Content Generator"):
|
| 3004 |
+
with gr.Row():
|
| 3005 |
+
with gr.Column(scale=1):
|
| 3006 |
+
# Modern Form Section
|
| 3007 |
+
gr.HTML("""
|
| 3008 |
+
<div class="modern-card slide-in-left">
|
| 3009 |
+
<h3>π Content Generation</h3>
|
| 3010 |
+
<p>Generate educational materials tailored to your specific needs</p>
|
| 3011 |
+
</div>
|
| 3012 |
+
""")
|
| 3013 |
+
|
| 3014 |
+
with gr.Group():
|
| 3015 |
+
content_topic = gr.Textbox(label="π Topic", placeholder="e.g., Photosynthesis, World War II, Algebra")
|
| 3016 |
+
content_subject = gr.Dropdown(
|
| 3017 |
+
choices=["Science", "Mathematics", "History", "English Language Arts", "Geography", "Art"],
|
| 3018 |
+
label="π Subject",
|
| 3019 |
+
value="Science",
|
| 3020 |
+
interactive=True
|
| 3021 |
+
)
|
| 3022 |
+
content_grade_level = gr.Dropdown(
|
| 3023 |
+
choices=["K-2", "3-5", "6-8", "9-12"],
|
| 3024 |
+
label="π Grade Level",
|
| 3025 |
+
value="6-8",
|
| 3026 |
+
interactive=True
|
| 3027 |
+
)
|
| 3028 |
+
content_difficulty = gr.Dropdown(
|
| 3029 |
+
choices=["Beginner", "Intermediate", "Advanced"],
|
| 3030 |
+
label="π― Difficulty",
|
| 3031 |
+
value="Intermediate",
|
| 3032 |
+
interactive=True
|
| 3033 |
+
)
|
| 3034 |
+
content_type = gr.Dropdown(
|
| 3035 |
+
choices=["Worksheets", "Handouts", "Study Guides", "Activities", "Presentations", "Lesson Materials"],
|
| 3036 |
+
label="π Content Type",
|
| 3037 |
+
value="Worksheets",
|
| 3038 |
+
interactive=True
|
| 3039 |
+
)
|
| 3040 |
+
content_length = gr.Dropdown(
|
| 3041 |
+
choices=["Short (1-2 pages)", "Medium (3-5 pages)", "Long (6+ pages)"],
|
| 3042 |
+
label="π Length",
|
| 3043 |
+
value="Medium (3-5 pages)",
|
| 3044 |
+
interactive=True
|
| 3045 |
+
)
|
| 3046 |
+
|
| 3047 |
+
generate_content_btn = gr.Button("π Generate Content", variant="primary", size="lg")
|
| 3048 |
+
clear_content_btn = gr.Button("ποΈ Clear", variant="secondary")
|
| 3049 |
+
|
| 3050 |
+
with gr.Column(scale=2):
|
| 3051 |
+
# Modern Output Section
|
| 3052 |
+
gr.HTML("""
|
| 3053 |
+
<div class="modern-card slide-in-right">
|
| 3054 |
+
<h3>π Generated Content</h3>
|
| 3055 |
+
<p>Your educational materials will appear here</p>
|
| 3056 |
+
</div>
|
| 3057 |
+
""")
|
| 3058 |
+
|
| 3059 |
+
content_output = gr.Markdown(value="Your educational content will appear here...")
|
| 3060 |
+
|
| 3061 |
+
# Content examples
|
| 3062 |
+
content_examples = gr.Dataset(
|
| 3063 |
+
components=[content_topic, content_subject, content_grade_level, content_difficulty, content_type, content_length],
|
| 3064 |
+
samples=[
|
| 3065 |
+
["Photosynthesis", "Science", "6-8", "Intermediate", "Worksheets", "Medium (3-5 pages)"],
|
| 3066 |
+
["World War II", "History", "9-12", "Advanced", "Study Guides", "Long (6+ pages)"],
|
| 3067 |
+
["Basic Algebra", "Mathematics", "3-5", "Beginner", "Activities", "Short (1-2 pages)"]
|
| 3068 |
+
],
|
| 3069 |
+
label="π‘ Content Examples"
|
| 3070 |
+
)
|
| 3071 |
+
|
| 3072 |
with gr.TabItem("π― Quiz Generator"):
|
| 3073 |
with gr.Row():
|
| 3074 |
with gr.Column():
|