Turbiling commited on
Commit
3fc2369
·
verified ·
1 Parent(s): 998c084

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -36
app.py CHANGED
@@ -1,53 +1,54 @@
 
1
  import gradio as gr
2
- import datetime
3
  from groq import Groq
4
 
5
- # Initialize Groq Client
6
- client = Groq(api_key="YOUR_GROQ_API_KEY")
7
 
8
- # Models
9
  URDU_MODEL = "openai/gpt-oss-120b"
10
  ENGLISH_MODEL = "llama-3.1-8b-instant"
11
 
12
- # Generation function
 
13
  def generate_content(language, plan_type, feature, grade, subject, topic, duration, student_level):
14
  if language == "Urdu":
15
  model = URDU_MODEL
16
  prompt = f"""
17
- آپ ایک ماہر استاد ہیں۔ براہ کرم نیچے دی گئی معلومات کی بنیاد پر ایک تفصیلی SMART طرز کا {plan_type} پلان تیار کریں۔
18
- اگر {feature} منتخب کیا گیا ہے تو اس کے مطابق مواد بھی شامل کریں۔
19
-
20
- درجہ: {grade}
 
 
 
 
 
21
  مضمون: {subject}
22
  موضوع: {topic}
23
  دورانیہ: {duration} منٹ
24
  طلبہ کی سطح: {student_level}
25
-
26
- مندرجہ ذیل چیزیں شامل کریں:
27
- 1. مقاصدِ سبق (SMART طرز میں)
28
- 2. سرگرمیاں
29
- 3. تدریسی حکمتِ عملی
30
- 4. جائزہ/Assessment
31
- 5. اگر منتخب کیا گیا ہو تو {feature} کے نمونے
32
  """
33
  else:
34
  model = ENGLISH_MODEL
35
  prompt = f"""
36
- You are an expert teacher. Create a detailed SMART-style {plan_type} plan.
37
- If {feature} is selected, include relevant examples or content.
 
 
 
 
 
 
 
38
 
39
  Grade: {grade}
40
  Subject: {subject}
41
  Topic: {topic}
42
  Duration: {duration} minutes
43
  Student Level: {student_level}
44
-
45
- Include the following sections:
46
- 1. SMART Objectives
47
- 2. Learning Activities
48
- 3. Teaching Strategies
49
- 4. Assessment
50
- 5. Include {feature} if applicable
51
  """
52
 
53
  try:
@@ -62,18 +63,24 @@ def generate_content(language, plan_type, feature, grade, subject, topic, durati
62
  return f"❌ Error: {str(e)}"
63
 
64
 
65
- # UI Layout
66
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal")) as demo:
67
  gr.Markdown("## 🧠 SMART LESSON PLAN GENERATOR")
68
  gr.Markdown("**Developed by: Najaf Ali**")
69
 
70
  with gr.Row():
71
- language = gr.Dropdown(["English", "Urdu"], label="Select Language", value="English")
 
 
 
 
 
72
  plan_type = gr.Dropdown(
73
- ["Daily Lesson Plan", "Weekly Lesson Plan", "Unit Plan", "SMART Lesson Plan"],
74
  label="Select Lesson Plan Type",
75
  value="SMART Lesson Plan"
76
  )
 
77
  feature = gr.Dropdown(
78
  ["None", "Flashcards", "Quiz"],
79
  label="Select Additional Feature",
@@ -81,15 +88,36 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal")) as demo:
81
  )
82
 
83
  with gr.Row():
84
- grade = gr.Textbox(label="Grade / Class (e.g., Grade 8)")
85
- subject = gr.Textbox(label="Subject (e.g., Science, Urdu)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  with gr.Row():
88
- topic = gr.Textbox(label="Topic (e.g., Photosynthesis)")
89
- duration = gr.Number(label="Duration (minutes)", value=40)
90
- student_level = gr.Dropdown(["Beginner", "Average", "Advanced"], label="Student Level", value="Average")
 
 
 
 
91
 
92
- generate_btn = gr.Button("🚀 Generate Now")
93
  output = gr.Textbox(label="Generated Output", lines=25)
94
 
95
  generate_btn.click(
@@ -98,5 +126,5 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal")) as demo:
98
  outputs=output
99
  )
100
 
101
- # Launch App
102
  demo.launch()
 
1
+ import os
2
  import gradio as gr
 
3
  from groq import Groq
4
 
5
+ # ✅ Load Groq API Key
6
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
7
 
8
+ # ✅ Define models
9
  URDU_MODEL = "openai/gpt-oss-120b"
10
  ENGLISH_MODEL = "llama-3.1-8b-instant"
11
 
12
+
13
+ # ✅ Core Function
14
  def generate_content(language, plan_type, feature, grade, subject, topic, duration, student_level):
15
  if language == "Urdu":
16
  model = URDU_MODEL
17
  prompt = f"""
18
+ آپ ایک ماہر استاد ہیں۔ براہ کرم نیچے دی گئی معلومات کی بنیاد پر SMART طرز کا {plan_type} تیار کریں۔
19
+ درج ذیل حصے شامل ہوں:
20
+ 1. معلوماتی جدول (Input Table)
21
+ 2. SMART سیکھنے کے نتائج (SLOs)
22
+ 3. "پڑھایا جانے والا مواد" (Content to be delivered) — تعریفیں، کلیدی تصورات اور بنیادی اصطلاحات کے ساتھ۔
23
+ 4. گھریلو کام (Home Assignment) — SLOs کے مطابق۔
24
+ 5. سرپرست یا پرنسپل کے تاثرات کے لیے جگہ (Feedback by Mentor/Principal)
25
+
26
+ جماعت: {grade}
27
  مضمون: {subject}
28
  موضوع: {topic}
29
  دورانیہ: {duration} منٹ
30
  طلبہ کی سطح: {student_level}
31
+ اگر {feature} منتخب کیا گیا ہے تو اس کے مطابق مواد بھی تیار کریں۔
 
 
 
 
 
 
32
  """
33
  else:
34
  model = ENGLISH_MODEL
35
  prompt = f"""
36
+ You are an experienced Pakistani school teacher.
37
+ Please create a SMART-style {plan_type} lesson plan based on the given details.
38
+
39
+ Include only the following sections:
40
+ 1. Input Table (with basic information)
41
+ 2. SMART Learning Outcomes (SLOs)
42
+ 3. "Content to be Delivered" — include definitions, key terms, and core concepts.
43
+ 4. Home Assignment aligned with SLOs.
44
+ 5. Feedback by Mentor/Principal (leave blank space for handwritten feedback).
45
 
46
  Grade: {grade}
47
  Subject: {subject}
48
  Topic: {topic}
49
  Duration: {duration} minutes
50
  Student Level: {student_level}
51
+ Also, if {feature} is selected, generate relevant {feature} content aligned with SLOs.
 
 
 
 
 
 
52
  """
53
 
54
  try:
 
63
  return f"❌ Error: {str(e)}"
64
 
65
 
66
+ # ✅ Build Gradio Interface
67
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan")) as demo:
68
  gr.Markdown("## 🧠 SMART LESSON PLAN GENERATOR")
69
  gr.Markdown("**Developed by: Najaf Ali**")
70
 
71
  with gr.Row():
72
+ language = gr.Dropdown(
73
+ ["English", "Urdu"],
74
+ label="Select Language",
75
+ value="English"
76
+ )
77
+
78
  plan_type = gr.Dropdown(
79
+ ["SMART Lesson Plan", "Daily Lesson Plan", "Weekly Lesson Plan", "Unit Plan"],
80
  label="Select Lesson Plan Type",
81
  value="SMART Lesson Plan"
82
  )
83
+
84
  feature = gr.Dropdown(
85
  ["None", "Flashcards", "Quiz"],
86
  label="Select Additional Feature",
 
88
  )
89
 
90
  with gr.Row():
91
+ grade = gr.Dropdown(
92
+ [
93
+ "Grade 1", "Grade 2", "Grade 3", "Grade 4", "Grade 5",
94
+ "Grade 6", "Grade 7", "Grade 8", "Grade 9", "Grade 10",
95
+ "Grade 11", "Grade 12"
96
+ ],
97
+ label="Select Class/Grade",
98
+ value="Grade 8"
99
+ )
100
+
101
+ subject = gr.Dropdown(
102
+ [
103
+ "English", "Urdu", "Mathematics", "Science", "Computer",
104
+ "Islamiyat", "Pakistan Studies", "Physics", "Chemistry",
105
+ "Biology", "Civics", "History", "Geography"
106
+ ],
107
+ label="Select Subject",
108
+ value="Science"
109
+ )
110
 
111
  with gr.Row():
112
+ topic = gr.Textbox(label="Enter Topic (e.g., Photosynthesis / Noun Types)")
113
+ duration = gr.Number(label="Lesson Duration (minutes)", value=40)
114
+ student_level = gr.Dropdown(
115
+ ["Beginner", "Average", "Advanced"],
116
+ label="Student Level",
117
+ value="Average"
118
+ )
119
 
120
+ generate_btn = gr.Button("🚀 Generate SMART Lesson Plan")
121
  output = gr.Textbox(label="Generated Output", lines=25)
122
 
123
  generate_btn.click(
 
126
  outputs=output
127
  )
128
 
129
+ # ✅ Launch App
130
  demo.launch()