Mahdi Naser Moghadasi commited on
Commit
ed978d2
Β·
1 Parent(s): e41ec3f

Update all generation functions to use LLM consistently - focus on educational materials

Browse files
Files changed (1) hide show
  1. app.py +71 -25
app.py CHANGED
@@ -51,16 +51,40 @@ def generate_lesson_plan_with_progress(topic, subject, grade_level, duration, di
51
  if HF_TOKEN:
52
  print("πŸ€– Token found! Attempting Hugging Face API call...")
53
  try:
54
- result = generate_with_hugging_face(topic, subject, grade_level, duration, difficulty)
55
- print("βœ… Successfully generated with Hugging Face API")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- # Show completion and return result
58
- completion_html = """
59
- <div class="progress-container">
60
- <div class="generation-status">βœ… Lesson Plan Generated Successfully!</div>
61
- </div>
62
- """
63
- yield completion_html, result
 
 
 
 
 
 
64
 
65
  except Exception as e:
66
  print(f"❌ Hugging Face API failed: {e}")
@@ -212,17 +236,21 @@ Difficulty: {difficulty}
212
  Content Type: {content_type}
213
  Length: {content_length}
214
 
 
 
215
  Please generate:
216
- 1. Age-appropriate content for {grade_level} students
217
  2. {difficulty} level complexity
218
- 3. {content_type} format
219
  4. {content_length} content
220
- 5. Clear learning objectives
221
- 6. Engaging activities and exercises
222
- 7. Assessment questions
223
- 8. Additional resources
 
 
224
 
225
- Make it practical, engaging, and ready for classroom use."""
226
 
227
  ai_content = call_hugging_face_api_content(prompt)
228
 
@@ -302,16 +330,34 @@ def generate_quiz_with_progress(topic, subject, grade_level, question_count, que
302
  if HF_TOKEN:
303
  print("πŸ€– Token found! Attempting Hugging Face API call for quiz...")
304
  try:
305
- result = generate_quiz_with_hugging_face(topic, subject, grade_level, question_count, question_types)
306
- print("βœ… Successfully generated quiz with Hugging Face API")
 
 
 
 
 
 
 
 
 
 
 
 
307
 
308
- # Show completion and return result
309
- completion_html = """
310
- <div class="progress-container">
311
- <div class="generation-status">βœ… Quiz Generated Successfully!</div>
312
- </div>
313
- """
314
- yield completion_html, result
 
 
 
 
 
 
315
 
316
  except Exception as e:
317
  print(f"❌ Hugging Face API failed: {e}")
 
51
  if HF_TOKEN:
52
  print("πŸ€– Token found! Attempting Hugging Face API call...")
53
  try:
54
+ prompt = f"""Create a comprehensive lesson plan for:
55
+ Topic: {topic}
56
+ Subject: {subject}
57
+ Grade Level: {grade_level}
58
+ Duration: {duration} minutes
59
+ Difficulty: {difficulty}
60
+
61
+ Include:
62
+ 1. Learning objectives
63
+ 2. Activities with time allocations
64
+ 3. Materials needed
65
+ 4. Assessment methods
66
+ 5. Differentiation strategies
67
+ 6. Educational standards
68
+ 7. Real-world connections
69
+ 8. Extension activities
70
+
71
+ Make it practical, engaging, and ready for classroom use."""
72
+
73
+ result = call_hugging_face_api_content(prompt)
74
 
75
+ if result:
76
+ print("βœ… Successfully generated with Hugging Face API")
77
+
78
+ # Show completion and return result
79
+ completion_html = """
80
+ <div class="progress-container">
81
+ <div class="generation-status">βœ… Lesson Plan Generated Successfully!</div>
82
+ </div>
83
+ """
84
+ yield completion_html, result
85
+ else:
86
+ print("❌ API call returned no content, falling back to algorithms")
87
+ raise Exception("No content returned from API")
88
 
89
  except Exception as e:
90
  print(f"❌ Hugging Face API failed: {e}")
 
236
  Content Type: {content_type}
237
  Length: {content_length}
238
 
239
+ IMPORTANT: Generate educational MATERIALS, not quizzes. Focus on teaching content, activities, and learning resources.
240
+
241
  Please generate:
242
+ 1. Age-appropriate educational content for {grade_level} students
243
  2. {difficulty} level complexity
244
+ 3. {content_type} format (worksheets, handouts, study guides, activities, presentations, lesson materials)
245
  4. {content_length} content
246
+ 5. Clear learning objectives and outcomes
247
+ 6. Engaging educational activities and exercises
248
+ 7. Teaching materials and resources
249
+ 8. Real-world applications and examples
250
+ 9. Step-by-step instructions for teachers
251
+ 10. Additional learning resources and references
252
 
253
+ Make it practical, engaging, and ready for classroom use as educational materials."""
254
 
255
  ai_content = call_hugging_face_api_content(prompt)
256
 
 
330
  if HF_TOKEN:
331
  print("πŸ€– Token found! Attempting Hugging Face API call for quiz...")
332
  try:
333
+ prompt = f"""Create a comprehensive quiz about "{topic}" for {grade_level} students studying {subject}.
334
+
335
+ Requirements:
336
+ - Generate exactly {question_count} questions
337
+ - Include these question types: {', '.join(question_types)}
338
+ - Make questions appropriate for {grade_level} grade level
339
+ - Ensure questions are specific to "{topic}"
340
+ - Include correct answers and explanations
341
+ - Format as a structured quiz with clear questions, options, and explanations
342
+ - Make it engaging and educational
343
+
344
+ Format the response as a structured quiz with clear questions, options, and explanations."""
345
+
346
+ result = call_hugging_face_api_content(prompt)
347
 
348
+ if result:
349
+ print("βœ… Successfully generated quiz with Hugging Face API")
350
+
351
+ # Show completion and return result
352
+ completion_html = """
353
+ <div class="progress-container">
354
+ <div class="generation-status">βœ… Quiz Generated Successfully!</div>
355
+ </div>
356
+ """
357
+ yield completion_html, result
358
+ else:
359
+ print("❌ API call returned no content, falling back to algorithms")
360
+ raise Exception("No content returned from API")
361
 
362
  except Exception as e:
363
  print(f"❌ Hugging Face API failed: {e}")