Turbiling commited on
Commit
63ce019
·
verified ·
1 Parent(s): 890be8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +163 -90
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from google import genai
3
  from docx import Document
4
  from docx.shared import Pt, RGBColor, Inches
5
  from docx.enum.text import WD_ALIGN_PARAGRAPH
@@ -9,11 +9,13 @@ from datetime import datetime
9
  import os
10
  import re
11
 
12
- # Initialize Gemini client with error handling
13
  try:
14
- client = genai.Client()
 
 
15
  except Exception as e:
16
- print(f"Warning: Gemini client initialization failed: {e}")
17
  client = None
18
 
19
  # Comprehensive data dictionaries
@@ -147,12 +149,12 @@ def generate_lesson_plan(language, grade_range, grade_specific, subject, topic,
147
  # Validate inputs
148
  validation_errors = validate_inputs(language, grade_range, subject, topic, teacher_name, school_name)
149
  if validation_errors:
150
- error_msg = "WARNING: Please fix the following errors:\n" + "\n".join(f"- {e}" for e in validation_errors)
151
  return None, error_msg
152
 
153
  # Check if client is initialized
154
  if client is None:
155
- return None, "ERROR: Gemini API client not initialized. Please check your API key."
156
 
157
  # Format date
158
  if date_input:
@@ -177,8 +179,7 @@ def generate_lesson_plan(language, grade_range, grade_specific, subject, topic,
177
  assessment_time = duration - (intro_time + main_time + conclusion_time)
178
 
179
  # Build enhanced prompt
180
- prompt = f"""
181
- You are an expert Pakistani educator and curriculum specialist with deep knowledge of the National Curriculum Framework, modern pedagogical approaches, and classroom management in Gilgit-Baltistan context.
182
 
183
  Create a COMPREHENSIVE, PRACTICAL, and STUDENT-CENTERED SMART LESSON PLAN in {language} language.
184
 
@@ -282,7 +283,7 @@ Create a COMPREHENSIVE, PRACTICAL, and STUDENT-CENTERED SMART LESSON PLAN in {la
282
  - How well were SLOs achieved?
283
 
284
  **FORMATTING & LANGUAGE GUIDELINES:**
285
- {"For English version:" if language == "English" else "For Urdu version:"}
286
  - Use clear, professional language appropriate for educational documentation
287
  - Write in complete sentences and paragraphs
288
  - Use bullet points ONLY for lists of items or steps
@@ -290,24 +291,47 @@ Create a COMPREHENSIVE, PRACTICAL, and STUDENT-CENTERED SMART LESSON PLAN in {la
290
  - Maintain logical flow between sections
291
  - Be specific and practical, not vague or generic
292
  - Include culturally relevant examples from Gilgit-Baltistan context
293
- - {"Proper English grammar and spelling" if language == "English" else "Proper Urdu script with right-to-left alignment"}
294
 
295
  **OUTPUT FORMAT:**
296
  Generate ONLY the lesson plan content starting from "SMART STUDENT LEARNING OUTCOMES (SLOs)".
297
  Do NOT include any table or repeat the lesson details (Grade, Subject, etc.) as that will be added automatically.
298
  Do NOT add any developer credits, signatures, or metadata at the end.
299
 
300
- Now generate the complete, ready-to-implement lesson plan:
301
- """
302
-
303
  try:
304
- # Generate content using Gemini
305
- response = client.models.generate_content(
306
- model="gemini-2.0-flash-exp",
307
- contents=prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  )
309
 
310
- lesson_text = response.text.strip()
 
 
 
 
 
 
 
311
 
312
  # Remove any accidental inclusion of lesson details from AI response
313
  lesson_text = re.sub(r'^.*?(SMART|SLO)', r'\1', lesson_text, flags=re.DOTALL | re.IGNORECASE)
@@ -384,7 +408,6 @@ Now generate the complete, ready-to-implement lesson plan:
384
 
385
  # Process lesson content with enhanced formatting
386
  lines = lesson_text.split("\n")
387
- current_section = ""
388
 
389
  for line in lines:
390
  line_stripped = line.strip()
@@ -439,7 +462,7 @@ Now generate the complete, ready-to-implement lesson plan:
439
  run.font.italic = True
440
  run.font.color.rgb = RGBColor(100, 100, 100)
441
 
442
- run2 = footer.add_run("SMART Lesson Plan Generator v2.0")
443
  run2.font.size = Pt(8)
444
  run2.font.italic = True
445
  run2.font.color.rgb = RGBColor(100, 100, 100)
@@ -450,30 +473,31 @@ Now generate the complete, ready-to-implement lesson plan:
450
  file_path = f"/tmp/LP_{subject}_{safe_topic}_{full_grade}_{formatted_date}.docx"
451
  doc.save(file_path)
452
 
453
- status_msg = f"""SUCCESS: Lesson Plan Generated Successfully!
454
 
455
- FILE DETAILS:
456
  - Subject: {subject}
457
  - Grade: {full_grade}
458
  - Topic: {topic}
459
  - Duration: {duration} minutes
460
  - Date: {formatted_date}
461
 
462
- FILE NAME: {os.path.basename(file_path)}
463
 
464
- NEXT STEPS:
465
  1. Download the file using the button below
466
  2. Review and customize as needed
467
  3. Print or share with colleagues
468
  4. Use in your classroom!
469
 
470
- QUALITY ASSURANCE:
471
- - SMART SLOs aligned with Bloom's Taxonomy
472
- - Detailed lesson procedure with timings
473
- - Assessment strategies included
474
- - {'Teaching resources listed' if include_resources else 'Standard content included'}
475
- - {'Differentiation strategies added' if include_differentiation else 'Standard content included'}
476
- - Home assignment provided"""
 
477
 
478
  else: # Urdu version
479
  # Create Urdu document
@@ -510,33 +534,41 @@ QUALITY ASSURANCE:
510
  file_path = f"/tmp/LP_Urdu_{safe_topic}_{formatted_date}.docx"
511
  doc.save(file_path)
512
 
513
- status_msg = f"""SUCCESS: سبق کا منصوبہ تیار ہو گیا!
514
 
515
- تفصیلات:
516
  - مضمون: {subject}
517
  - درجہ: {full_grade}
518
  - موضوع: {topic}
519
 
520
- فائل: {os.path.basename(file_path)}"""
 
 
521
 
522
  return file_path, status_msg
523
 
524
  except Exception as e:
525
- error_details = f"""ERROR: Error Generating Lesson Plan
526
 
527
- Error Type: {type(e).__name__}
528
- Details: {str(e)}
529
 
530
- Troubleshooting Steps:
531
  1. Check your internet connection
532
- 2. Verify Gemini API key is configured
533
  3. Ensure all required fields are filled
534
  4. Try again with a simpler topic
 
 
 
 
 
535
 
536
- If problem persists: Contact technical support"""
537
 
538
  return None, error_details
539
 
 
540
  # Create Professional Gradio Interface
541
  custom_css = """
542
  .gradio-container {
@@ -571,12 +603,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
571
  with gr.Row():
572
  gr.HTML("""
573
  <div class="main-header">
574
- <h1 style="margin:0; font-size: 2.5rem;">SMART Lesson Plan Generator</h1>
575
  <p style="margin: 0.5rem 0 0 0; font-size: 1.1rem; opacity: 0.9;">
576
  Professional Lesson Planning Tool for Gilgit-Baltistan Schools
577
  </p>
578
  <p style="margin: 0.3rem 0 0 0; font-size: 0.9rem; opacity: 0.8;">
579
- Powered by Google Gemini AI | Developed by Najaf Ali Sharqi
580
  </p>
581
  </div>
582
  """)
@@ -585,31 +617,33 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
585
  with gr.Row():
586
  gr.Markdown("""
587
  <div class="info-box">
588
- <strong>About This Tool:</strong> Generate comprehensive, curriculum-aligned SMART lesson plans in English or Urdu.
589
  All plans include SMART SLOs based on Bloom's Taxonomy, detailed procedures, assessments, and home assignments.
 
 
590
  </div>
591
  """)
592
 
593
  # Main form sections
594
- gr.HTML('<div class="section-header"><h3>Basic Lesson Information</h3></div>')
595
 
596
  with gr.Row():
597
  language = gr.Dropdown(
598
  choices=["English", "Urdu"],
599
- label="Language",
600
  value="English",
601
  info="Select lesson plan language",
602
  interactive=True
603
  )
604
  grade_range = gr.Dropdown(
605
  choices=["Grade 1-5", "Grade 6-8", "Grade 9-10", "Grade 11-12"],
606
- label="Grade Range",
607
  info="Select grade level range",
608
  interactive=True
609
  )
610
  grade_specific = gr.Dropdown(
611
  choices=[f"Grade {i}" for i in range(1, 13)],
612
- label="Specific Grade (Optional)",
613
  info="Select exact grade level",
614
  interactive=True
615
  )
@@ -617,51 +651,51 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
617
  with gr.Row():
618
  subject = gr.Dropdown(
619
  choices=[],
620
- label="Subject",
621
  info="Will update based on grade selection",
622
  interactive=True
623
  )
624
  topic = gr.Textbox(
625
- label="Lesson Topic",
626
  placeholder="e.g., Photosynthesis, Pythagorean Theorem, Parts of Speech...",
627
  info="Enter the specific topic for this lesson",
628
  lines=1
629
  )
630
 
631
- gr.HTML('<div class="section-header"><h3>School & Teacher Details</h3></div>')
632
 
633
  with gr.Row():
634
  school_name = gr.Textbox(
635
- label="School Name",
636
  placeholder="e.g., Government High School Gilgit",
637
  info="Enter complete school name",
638
  lines=1
639
  )
640
  teacher_name = gr.Textbox(
641
- label="Teacher Name",
642
  placeholder="e.g., Muhammad Ali Khan",
643
  info="Enter teacher's full name",
644
  lines=1
645
  )
646
  district = gr.Dropdown(
647
  choices=DISTRICTS_GB,
648
- label="District",
649
  value="Gilgit",
650
  info="Select district in Gilgit-Baltistan",
651
  interactive=True
652
  )
653
 
654
- gr.HTML('<div class="section-header"><h3>Class Details & Timing</h3></div>')
655
 
656
  with gr.Row():
657
  date_input = gr.Textbox(
658
- label="Lesson Date",
659
  value=datetime.now().strftime("%Y-%m-%d"),
660
  placeholder="YYYY-MM-DD",
661
  info="Enter date in YYYY-MM-DD format"
662
  )
663
  students = gr.Number(
664
- label="Number of Students",
665
  value=35,
666
  minimum=1,
667
  maximum=100,
@@ -670,42 +704,42 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
670
  )
671
  duration = gr.Dropdown(
672
  choices=[35, 40, 45, 50, 60, 70, 80, 90],
673
- label="Duration (minutes)",
674
  value=40,
675
  info="Total lesson duration",
676
  interactive=True
677
  )
678
 
679
- gr.HTML('<div class="section-header"><h3>Teaching Methodology & Assessment</h3></div>')
680
 
681
  with gr.Row():
682
  teaching_method = gr.Dropdown(
683
  choices=TEACHING_METHODS,
684
- label="Primary Teaching Method",
685
  value="Lecture Method",
686
  info="Main instructional approach for this lesson",
687
  interactive=True
688
  )
689
  assessment_type = gr.Dropdown(
690
  choices=ASSESSMENT_TYPES,
691
- label="Assessment Method",
692
  value="Formative Assessment",
693
  info="How will you evaluate student learning?",
694
  interactive=True
695
  )
696
 
697
- gr.HTML('<div class="section-header"><h3>Additional Options</h3></div>')
698
 
699
  with gr.Row():
700
  with gr.Column(scale=1):
701
  include_resources = gr.Checkbox(
702
- label="Include Teaching Resources List",
703
  value=True,
704
  info="Add detailed list of required materials and resources"
705
  )
706
  with gr.Column(scale=1):
707
  include_differentiation = gr.Checkbox(
708
- label="Include Differentiation Strategies",
709
  value=True,
710
  info="Add strategies for diverse learners (advanced, struggling, special needs)"
711
  )
@@ -714,14 +748,14 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
714
 
715
  # Generate button with styling
716
  generate_btn = gr.Button(
717
- "Generate SMART Lesson Plan",
718
  variant="primary",
719
  size="lg",
720
  scale=2
721
  )
722
 
723
  # Instructions
724
- with gr.Accordion("Instructions & Tips", open=False):
725
  gr.Markdown("""
726
  ### How to Use This Generator:
727
 
@@ -734,7 +768,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
734
  7. **Choose Methods**: Select teaching and assessment approaches
735
  8. **Click Generate**: Wait 10-20 seconds for AI to create your plan
736
 
737
- ### Tips for Best Results:
738
 
739
  - **Be Specific**: Instead of "Math", use "Linear Equations" or "Fractions"
740
  - **Realistic Duration**: Match duration to your actual class period
@@ -742,7 +776,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
742
  - **Review & Edit**: Always review and customize the generated plan
743
  - **Save Multiple**: Generate variations to compare approaches
744
 
745
- ### What You'll Get:
746
 
747
  - **3 SMART SLOs** aligned with Bloom's Taxonomy (Knowledge, Understanding, Application)
748
  - **Comprehensive Content Knowledge** with key concepts and misconceptions
@@ -752,7 +786,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
752
  - **SMART Home Assignment** aligned with SLOs
753
  - **Reflection Section** for post-lesson notes
754
 
755
- ### About SMART SLOs:
756
 
757
  SMART stands for:
758
  - **S**pecific: Clear and precise learning outcomes
@@ -760,24 +794,37 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
760
  - **A**chievable: Realistic within lesson time
761
  - **R**elevant: Aligned with curriculum standards
762
  - **T**ime-bound: Achievable in one lesson period
 
 
 
 
 
 
 
 
 
 
 
 
 
763
  """)
764
 
765
  gr.Markdown("---")
766
 
767
  # Output section with enhanced styling
768
- gr.HTML('<div class="section-header"><h3>Your Generated Lesson Plan</h3></div>')
769
 
770
  with gr.Row():
771
  with gr.Column(scale=2):
772
  status_output = gr.Textbox(
773
- label="Generation Status",
774
  interactive=False,
775
- lines=10,
776
  placeholder="Status messages will appear here..."
777
  )
778
  with gr.Column(scale=1):
779
  output_file = gr.File(
780
- label="Download File",
781
  file_count="single"
782
  )
783
 
@@ -802,47 +849,73 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
802
  # Footer with additional information
803
  gr.Markdown("---")
804
 
805
- with gr.Accordion("About & Support", open=False):
806
  gr.Markdown("""
807
- ### About This Application
808
 
809
- **Version:** 2.0 (Production Release)
810
  **Developer:** Najaf Ali Sharqi
811
  **Organization:** School Education Department, Gilgit-Baltistan
812
- **AI Model:** Google Gemini 2.0 Flash
 
 
 
 
 
 
 
 
 
 
 
 
 
813
 
814
- ### Features:
815
 
816
- - SMART Learning Outcomes (Bloom's Taxonomy aligned)
817
- - Comprehensive lesson procedures with timings
818
- - National Curriculum Framework compliance
819
- - Bilingual support (English & Urdu)
820
- - Professional Word document formatting
821
- - Differentiation strategies
822
- - Assessment guidelines
823
- - Home assignments
824
 
825
- ### Support & Feedback:
826
 
827
  For technical support, feature requests, or to report issues:
828
  - **Email:** Contact School Education Department
829
  - **Feedback:** Use the feedback option in your district office
 
830
 
831
- ### Privacy & Data:
832
 
833
  - All lesson plans are generated in real-time
834
  - No data is stored on external servers
835
  - Your lesson plans remain confidential
836
  - Files are temporarily created and deleted after download
837
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838
  ---
839
 
840
- **Copyright 2024 School Education Department, Gilgit-Baltistan**
841
  *Empowering Teachers, Enriching Learning*
842
  """)
843
 
844
  # Quick reference guide
845
- with gr.Accordion("Quick Reference: Bloom's Taxonomy", open=False):
846
  gr.Markdown("""
847
  ### Understanding Bloom's Taxonomy Levels
848
 
@@ -855,7 +928,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan
855
  | **Evaluation** (Evaluate) | Evaluate, Judge, Critique, Justify | "Students will be able to **evaluate** the effectiveness of different solutions" |
856
  | **Creation** (Create) | Create, Design, Develop, Compose | "Students will be able to **design** an experiment to test their hypothesis" |
857
 
858
- ### Tips:
859
  - Start with lower levels (Knowledge, Understanding) for new topics
860
  - Progress to higher levels (Application, Analysis) as students master basics
861
  - Each lesson should target 2-3 adjacent levels
 
1
  import gradio as gr
2
+ from groq import Groq
3
  from docx import Document
4
  from docx.shared import Pt, RGBColor, Inches
5
  from docx.enum.text import WD_ALIGN_PARAGRAPH
 
9
  import os
10
  import re
11
 
12
+ # Initialize Groq client with error handling
13
  try:
14
+ client = Groq()
15
+ # Test the client
16
+ print("✓ Groq client initialized successfully")
17
  except Exception as e:
18
+ print(f"Warning: Groq client initialization failed: {e}")
19
  client = None
20
 
21
  # Comprehensive data dictionaries
 
149
  # Validate inputs
150
  validation_errors = validate_inputs(language, grade_range, subject, topic, teacher_name, school_name)
151
  if validation_errors:
152
+ error_msg = "⚠️ Please fix the following errors:\n" + "\n".join(f"• {e}" for e in validation_errors)
153
  return None, error_msg
154
 
155
  # Check if client is initialized
156
  if client is None:
157
+ return None, "❌ Error: Groq API client not initialized. Please check your API key."
158
 
159
  # Format date
160
  if date_input:
 
179
  assessment_time = duration - (intro_time + main_time + conclusion_time)
180
 
181
  # Build enhanced prompt
182
+ prompt = f"""You are an expert Pakistani educator and curriculum specialist with deep knowledge of the National Curriculum Framework, modern pedagogical approaches, and classroom management in Gilgit-Baltistan context.
 
183
 
184
  Create a COMPREHENSIVE, PRACTICAL, and STUDENT-CENTERED SMART LESSON PLAN in {language} language.
185
 
 
283
  - How well were SLOs achieved?
284
 
285
  **FORMATTING & LANGUAGE GUIDELINES:**
286
+ {"For English version:" if language == "English" else "اردو کے لیے:"}
287
  - Use clear, professional language appropriate for educational documentation
288
  - Write in complete sentences and paragraphs
289
  - Use bullet points ONLY for lists of items or steps
 
291
  - Maintain logical flow between sections
292
  - Be specific and practical, not vague or generic
293
  - Include culturally relevant examples from Gilgit-Baltistan context
294
+ - {"Proper English grammar and spelling" if language == "English" else "صحیح اردو رسم الخط اور املا، دائیں سے بائیں سمت"}
295
 
296
  **OUTPUT FORMAT:**
297
  Generate ONLY the lesson plan content starting from "SMART STUDENT LEARNING OUTCOMES (SLOs)".
298
  Do NOT include any table or repeat the lesson details (Grade, Subject, etc.) as that will be added automatically.
299
  Do NOT add any developer credits, signatures, or metadata at the end.
300
 
301
+ Now generate the complete, ready-to-implement lesson plan:"""
302
+
 
303
  try:
304
+ # Generate content using Groq API with streaming
305
+ print("🔄 Generating lesson plan with Groq API...")
306
+
307
+ completion = client.chat.completions.create(
308
+ model="openai/gpt-oss-120b",
309
+ messages=[
310
+ {
311
+ "role": "system",
312
+ "content": "You are an expert Pakistani educator and curriculum specialist. Generate comprehensive, professional lesson plans following the exact format and requirements provided."
313
+ },
314
+ {
315
+ "role": "user",
316
+ "content": prompt
317
+ }
318
+ ],
319
+ temperature=0.7, # Slightly lower for more consistent educational content
320
+ max_completion_tokens=8192,
321
+ top_p=0.95,
322
+ reasoning_effort="high", # Use high reasoning for better educational content
323
+ stream=True,
324
+ stop=None
325
  )
326
 
327
+ # Collect the streamed response
328
+ lesson_text = ""
329
+ for chunk in completion:
330
+ if chunk.choices[0].delta.content:
331
+ lesson_text += chunk.choices[0].delta.content
332
+
333
+ lesson_text = lesson_text.strip()
334
+ print(f"✓ Generated {len(lesson_text)} characters")
335
 
336
  # Remove any accidental inclusion of lesson details from AI response
337
  lesson_text = re.sub(r'^.*?(SMART|SLO)', r'\1', lesson_text, flags=re.DOTALL | re.IGNORECASE)
 
408
 
409
  # Process lesson content with enhanced formatting
410
  lines = lesson_text.split("\n")
 
411
 
412
  for line in lines:
413
  line_stripped = line.strip()
 
462
  run.font.italic = True
463
  run.font.color.rgb = RGBColor(100, 100, 100)
464
 
465
+ run2 = footer.add_run("SMART Lesson Plan Generator v2.1 (Powered by Groq AI)")
466
  run2.font.size = Pt(8)
467
  run2.font.italic = True
468
  run2.font.color.rgb = RGBColor(100, 100, 100)
 
473
  file_path = f"/tmp/LP_{subject}_{safe_topic}_{full_grade}_{formatted_date}.docx"
474
  doc.save(file_path)
475
 
476
+ status_msg = f"""✅ **Lesson Plan Generated Successfully!**
477
 
478
+ 📄 **File Details:**
479
  - Subject: {subject}
480
  - Grade: {full_grade}
481
  - Topic: {topic}
482
  - Duration: {duration} minutes
483
  - Date: {formatted_date}
484
 
485
+ 💾 **File Name:** {os.path.basename(file_path)}
486
 
487
+ ✨ **Next Steps:**
488
  1. Download the file using the button below
489
  2. Review and customize as needed
490
  3. Print or share with colleagues
491
  4. Use in your classroom!
492
 
493
+ 🎯 **Quality Assurance:**
494
+ - ✓ SMART SLOs aligned with Bloom's Taxonomy
495
+ - ✓ Detailed lesson procedure with timings
496
+ - ✓ Assessment strategies included
497
+ - ✓ {('Teaching resources listed' if include_resources else 'Differentiation strategies added' if include_differentiation else 'Complete lesson plan')}
498
+ - ✓ Home assignment provided
499
+
500
+ 🤖 **Powered by:** Groq AI (openai/gpt-oss-120b)"""
501
 
502
  else: # Urdu version
503
  # Create Urdu document
 
534
  file_path = f"/tmp/LP_Urdu_{safe_topic}_{formatted_date}.docx"
535
  doc.save(file_path)
536
 
537
+ status_msg = f"""✅ **سبق کا منصوبہ تیار ہو گیا!**
538
 
539
+ 📄 **تفصیلات:**
540
  - مضمون: {subject}
541
  - درجہ: {full_grade}
542
  - موضوع: {topic}
543
 
544
+ 💾 فائل: {os.path.basename(file_path)}
545
+
546
+ 🤖 **تیار کردہ بذریعہ:** Groq AI"""
547
 
548
  return file_path, status_msg
549
 
550
  except Exception as e:
551
+ error_details = f"""❌ **Error Generating Lesson Plan**
552
 
553
+ **Error Type:** {type(e).__name__}
554
+ **Details:** {str(e)}
555
 
556
+ **Troubleshooting Steps:**
557
  1. Check your internet connection
558
+ 2. Verify Groq API key is configured (GROQ_API_KEY environment variable)
559
  3. Ensure all required fields are filled
560
  4. Try again with a simpler topic
561
+ 5. Check if you have sufficient API credits
562
+
563
+ **API Configuration:**
564
+ - Set your Groq API key: `export GROQ_API_KEY=your_api_key_here`
565
+ - Get your API key from: https://console.groq.com/
566
 
567
+ **If problem persists:** Contact technical support"""
568
 
569
  return None, error_details
570
 
571
+
572
  # Create Professional Gradio Interface
573
  custom_css = """
574
  .gradio-container {
 
603
  with gr.Row():
604
  gr.HTML("""
605
  <div class="main-header">
606
+ <h1 style="margin:0; font-size: 2.5rem;">📚 SMART Lesson Plan Generator</h1>
607
  <p style="margin: 0.5rem 0 0 0; font-size: 1.1rem; opacity: 0.9;">
608
  Professional Lesson Planning Tool for Gilgit-Baltistan Schools
609
  </p>
610
  <p style="margin: 0.3rem 0 0 0; font-size: 0.9rem; opacity: 0.8;">
611
+ Powered by Groq AI (openai/gpt-oss-120b) | Developed by Najaf Ali Sharqi
612
  </p>
613
  </div>
614
  """)
 
617
  with gr.Row():
618
  gr.Markdown("""
619
  <div class="info-box">
620
+ <strong>🎯 About This Tool:</strong> Generate comprehensive, curriculum-aligned SMART lesson plans in English or Urdu.
621
  All plans include SMART SLOs based on Bloom's Taxonomy, detailed procedures, assessments, and home assignments.
622
+ <br><br>
623
+ <strong>🤖 AI Model:</strong> Using Groq's openai/gpt-oss-120b for high-quality, fast lesson plan generation.
624
  </div>
625
  """)
626
 
627
  # Main form sections
628
+ gr.HTML('<div class="section-header"><h3>📋 Basic Lesson Information</h3></div>')
629
 
630
  with gr.Row():
631
  language = gr.Dropdown(
632
  choices=["English", "Urdu"],
633
+ label="📝 Language",
634
  value="English",
635
  info="Select lesson plan language",
636
  interactive=True
637
  )
638
  grade_range = gr.Dropdown(
639
  choices=["Grade 1-5", "Grade 6-8", "Grade 9-10", "Grade 11-12"],
640
+ label="🎓 Grade Range",
641
  info="Select grade level range",
642
  interactive=True
643
  )
644
  grade_specific = gr.Dropdown(
645
  choices=[f"Grade {i}" for i in range(1, 13)],
646
+ label="📊 Specific Grade (Optional)",
647
  info="Select exact grade level",
648
  interactive=True
649
  )
 
651
  with gr.Row():
652
  subject = gr.Dropdown(
653
  choices=[],
654
+ label="📖 Subject",
655
  info="Will update based on grade selection",
656
  interactive=True
657
  )
658
  topic = gr.Textbox(
659
+ label="📌 Lesson Topic",
660
  placeholder="e.g., Photosynthesis, Pythagorean Theorem, Parts of Speech...",
661
  info="Enter the specific topic for this lesson",
662
  lines=1
663
  )
664
 
665
+ gr.HTML('<div class="section-header"><h3>👨‍🏫 School & Teacher Details</h3></div>')
666
 
667
  with gr.Row():
668
  school_name = gr.Textbox(
669
+ label="🏫 School Name",
670
  placeholder="e.g., Government High School Gilgit",
671
  info="Enter complete school name",
672
  lines=1
673
  )
674
  teacher_name = gr.Textbox(
675
+ label="👤 Teacher Name",
676
  placeholder="e.g., Muhammad Ali Khan",
677
  info="Enter teacher's full name",
678
  lines=1
679
  )
680
  district = gr.Dropdown(
681
  choices=DISTRICTS_GB,
682
+ label="📍 District",
683
  value="Gilgit",
684
  info="Select district in Gilgit-Baltistan",
685
  interactive=True
686
  )
687
 
688
+ gr.HTML('<div class="section-header"><h3>⏰ Class Details & Timing</h3></div>')
689
 
690
  with gr.Row():
691
  date_input = gr.Textbox(
692
+ label="📅 Lesson Date",
693
  value=datetime.now().strftime("%Y-%m-%d"),
694
  placeholder="YYYY-MM-DD",
695
  info="Enter date in YYYY-MM-DD format"
696
  )
697
  students = gr.Number(
698
+ label="👥 Number of Students",
699
  value=35,
700
  minimum=1,
701
  maximum=100,
 
704
  )
705
  duration = gr.Dropdown(
706
  choices=[35, 40, 45, 50, 60, 70, 80, 90],
707
+ label="⏱️ Duration (minutes)",
708
  value=40,
709
  info="Total lesson duration",
710
  interactive=True
711
  )
712
 
713
+ gr.HTML('<div class="section-header"><h3>🎯 Teaching Methodology & Assessment</h3></div>')
714
 
715
  with gr.Row():
716
  teaching_method = gr.Dropdown(
717
  choices=TEACHING_METHODS,
718
+ label="🎓 Primary Teaching Method",
719
  value="Lecture Method",
720
  info="Main instructional approach for this lesson",
721
  interactive=True
722
  )
723
  assessment_type = gr.Dropdown(
724
  choices=ASSESSMENT_TYPES,
725
+ label="📊 Assessment Method",
726
  value="Formative Assessment",
727
  info="How will you evaluate student learning?",
728
  interactive=True
729
  )
730
 
731
+ gr.HTML('<div class="section-header"><h3>⚙️ Additional Options</h3></div>')
732
 
733
  with gr.Row():
734
  with gr.Column(scale=1):
735
  include_resources = gr.Checkbox(
736
+ label="📦 Include Teaching Resources List",
737
  value=True,
738
  info="Add detailed list of required materials and resources"
739
  )
740
  with gr.Column(scale=1):
741
  include_differentiation = gr.Checkbox(
742
+ label="🎯 Include Differentiation Strategies",
743
  value=True,
744
  info="Add strategies for diverse learners (advanced, struggling, special needs)"
745
  )
 
748
 
749
  # Generate button with styling
750
  generate_btn = gr.Button(
751
+ "🚀 Generate SMART Lesson Plan",
752
  variant="primary",
753
  size="lg",
754
  scale=2
755
  )
756
 
757
  # Instructions
758
+ with gr.Accordion("📖 Instructions & Tips", open=False):
759
  gr.Markdown("""
760
  ### How to Use This Generator:
761
 
 
768
  7. **Choose Methods**: Select teaching and assessment approaches
769
  8. **Click Generate**: Wait 10-20 seconds for AI to create your plan
770
 
771
+ ### 💡 Tips for Best Results:
772
 
773
  - **Be Specific**: Instead of "Math", use "Linear Equations" or "Fractions"
774
  - **Realistic Duration**: Match duration to your actual class period
 
776
  - **Review & Edit**: Always review and customize the generated plan
777
  - **Save Multiple**: Generate variations to compare approaches
778
 
779
+ ### ✨ What You'll Get:
780
 
781
  - **3 SMART SLOs** aligned with Bloom's Taxonomy (Knowledge, Understanding, Application)
782
  - **Comprehensive Content Knowledge** with key concepts and misconceptions
 
786
  - **SMART Home Assignment** aligned with SLOs
787
  - **Reflection Section** for post-lesson notes
788
 
789
+ ### 🎓 About SMART SLOs:
790
 
791
  SMART stands for:
792
  - **S**pecific: Clear and precise learning outcomes
 
794
  - **A**chievable: Realistic within lesson time
795
  - **R**elevant: Aligned with curriculum standards
796
  - **T**ime-bound: Achievable in one lesson period
797
+
798
+ ### 🔑 API Configuration:
799
+
800
+ **Before using this tool**, you need to set up your Groq API key:
801
+
802
+ 1. Get your free API key from: https://console.groq.com/
803
+ 2. Set it as an environment variable:
804
+ ```bash
805
+ export GROQ_API_KEY=your_api_key_here
806
+ ```
807
+ 3. Or add it to your `.env` file
808
+
809
+ The app uses the **openai/gpt-oss-120b** model for high-quality educational content generation.
810
  """)
811
 
812
  gr.Markdown("---")
813
 
814
  # Output section with enhanced styling
815
+ gr.HTML('<div class="section-header"><h3>📥 Your Generated Lesson Plan</h3></div>')
816
 
817
  with gr.Row():
818
  with gr.Column(scale=2):
819
  status_output = gr.Textbox(
820
+ label="📊 Generation Status",
821
  interactive=False,
822
+ lines=12,
823
  placeholder="Status messages will appear here..."
824
  )
825
  with gr.Column(scale=1):
826
  output_file = gr.File(
827
+ label="💾 Download File",
828
  file_count="single"
829
  )
830
 
 
849
  # Footer with additional information
850
  gr.Markdown("---")
851
 
852
+ with gr.Accordion("ℹ️ About & Support", open=False):
853
  gr.Markdown("""
854
+ ### 📱 About This Application
855
 
856
+ **Version:** 2.1 (Groq AI Edition)
857
  **Developer:** Najaf Ali Sharqi
858
  **Organization:** School Education Department, Gilgit-Baltistan
859
+ **AI Model:** Groq openai/gpt-oss-120b
860
+ **Speed:** Ultra-fast generation (10-20 seconds)
861
+
862
+ ### 🎯 Features:
863
+
864
+ - ✅ SMART Learning Outcomes (Bloom's Taxonomy aligned)
865
+ - ✅ Comprehensive lesson procedures with timings
866
+ - ✅ National Curriculum Framework compliance
867
+ - ✅ Bilingual support (English & Urdu)
868
+ - ✅ Professional Word document formatting
869
+ - ✅ Differentiation strategies
870
+ - ✅ Assessment guidelines
871
+ - ✅ Home assignments
872
+ - ✅ Powered by Groq's ultra-fast AI inference
873
 
874
+ ### 🤖 About Groq AI:
875
 
876
+ This application uses Groq's **openai/gpt-oss-120b** model, which provides:
877
+ - Lightning-fast inference speed
878
+ - High-quality educational content
879
+ - Reasoning capabilities for better lesson structure
880
+ - Support for both English and Urdu languages
 
 
 
881
 
882
+ ### 📞 Support & Feedback:
883
 
884
  For technical support, feature requests, or to report issues:
885
  - **Email:** Contact School Education Department
886
  - **Feedback:** Use the feedback option in your district office
887
+ - **API Issues:** Check https://console.groq.com/ for API status
888
 
889
+ ### 🔒 Privacy & Data:
890
 
891
  - All lesson plans are generated in real-time
892
  - No data is stored on external servers
893
  - Your lesson plans remain confidential
894
  - Files are temporarily created and deleted after download
895
 
896
+ ### 📚 Resources:
897
+
898
+ - **Groq Console:** https://console.groq.com/
899
+ - **Groq Documentation:** https://console.groq.com/docs
900
+ - **National Curriculum:** http://www.mofept.gov.pk/
901
+ - **Bloom's Taxonomy Guide:** Refer to teacher training materials
902
+
903
+ ### 🙏 Acknowledgments:
904
+
905
+ This tool was developed to support teachers in Gilgit-Baltistan in creating high-quality,
906
+ standards-aligned lesson plans efficiently. Special thanks to:
907
+ - All educators who provided feedback during development
908
+ - Groq AI for providing powerful, fast AI inference
909
+ - School Education Department, Gilgit-Baltistan
910
+
911
  ---
912
 
913
+ **© 2024 School Education Department, Gilgit-Baltistan**
914
  *Empowering Teachers, Enriching Learning*
915
  """)
916
 
917
  # Quick reference guide
918
+ with gr.Accordion("📋 Quick Reference: Bloom's Taxonomy", open=False):
919
  gr.Markdown("""
920
  ### Understanding Bloom's Taxonomy Levels
921
 
 
928
  | **Evaluation** (Evaluate) | Evaluate, Judge, Critique, Justify | "Students will be able to **evaluate** the effectiveness of different solutions" |
929
  | **Creation** (Create) | Create, Design, Develop, Compose | "Students will be able to **design** an experiment to test their hypothesis" |
930
 
931
+ ### 💡 Tips:
932
  - Start with lower levels (Knowledge, Understanding) for new topics
933
  - Progress to higher levels (Application, Analysis) as students master basics
934
  - Each lesson should target 2-3 adjacent levels