Turbiling commited on
Commit
23f6294
·
verified ·
1 Parent(s): 7b25f62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -1,4 +1,5 @@
1
  # app.py
 
2
  import os
3
  import gradio as gr
4
  from docx import Document
@@ -17,21 +18,25 @@ client = Groq(api_key=GROQ_API_KEY)
17
  # ✅ Text Generation Function
18
  def generate_lesson_plan(language, class_, subject, topic, students, duration, date, teacher):
19
  try:
 
20
  if language == "English":
 
21
  prompt = f"""
22
- You are an expert lesson plan creator.
23
- Create a detailed English lesson plan using the BOPPPS model for the topic: "{topic}".
24
- Avoid repeating the basic info (class, subject, teacher, etc.) in headings.
25
  Include only these sections:
26
  1. Bridge-In: short, engaging introduction.
27
  2. 3 Clear Learning Objectives.
28
  3. 2 Pre-Assessment Questions.
29
- 4. 1 Participatory Learning Activity (detailed).
30
  5. 2–3 Post-Assessment Questions.
31
  6. Summary paragraph by the teacher.
32
  """
33
 
34
- else: # Urdu mode
 
 
35
  prompt = f"""
36
  آپ ایک ماہر اسباقی منصوبہ ساز ہیں۔
37
  موضوع "{topic}" پر BOPPPS ماڈل کے مطابق ایک مفصل اردو سبق منصوبہ تیار کریں۔
@@ -44,9 +49,9 @@ Include only these sections:
44
  6. سبق کا خلاصہ (Summary)
45
  """
46
 
47
- # ✅ Use the Groq client with the openai/gpt-oss-120b model
48
  response = client.chat.completions.create(
49
- model="openai/gpt-oss-120b",
50
  messages=[{"role": "user", "content": prompt}],
51
  temperature=0.8,
52
  max_completion_tokens=2048,
@@ -54,7 +59,6 @@ Include only these sections:
54
  stream=False
55
  )
56
 
57
- # Extract generated text
58
  lesson_text = response.choices[0].message.content.strip()
59
 
60
  # ✅ Create the Word document
@@ -80,7 +84,7 @@ Include only these sections:
80
 
81
  paragraph = doc.add_paragraph(lesson_text)
82
 
83
- # Urdu formatting (right-aligned text)
84
  if language == "Urdu":
85
  paragraph.alignment = 2
86
  rtl = OxmlElement('w:rtl')
@@ -89,7 +93,7 @@ Include only these sections:
89
 
90
  doc.add_paragraph("\nDeveloped by Najaf Ali Sharqi")
91
 
92
- # Save to temporary file
93
  filename = f"lesson_plan_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.docx"
94
  filepath = f"/tmp/{filename}"
95
  doc.save(filepath)
@@ -136,4 +140,3 @@ with gr.Blocks() as demo:
136
  gr.Markdown("🔹 Developed by **Najaf Ali Sharqi**")
137
 
138
  demo.launch()
139
-
 
1
  # app.py
2
+ # app.py
3
  import os
4
  import gradio as gr
5
  from docx import Document
 
18
  # ✅ Text Generation Function
19
  def generate_lesson_plan(language, class_, subject, topic, students, duration, date, teacher):
20
  try:
21
+ # English mode → Llama 3.1 model
22
  if language == "English":
23
+ model_name = "llama-3.1-8b-instant"
24
  prompt = f"""
25
+ You are an expert lesson plan designer.
26
+ Create a comprehensive English lesson plan using the BOPPPS model for the topic: "{topic}".
27
+ Do NOT repeat the basic info (class, subject, teacher, etc.) in headings.
28
  Include only these sections:
29
  1. Bridge-In: short, engaging introduction.
30
  2. 3 Clear Learning Objectives.
31
  3. 2 Pre-Assessment Questions.
32
+ 4. 1 Detailed Participatory Learning Activity.
33
  5. 2–3 Post-Assessment Questions.
34
  6. Summary paragraph by the teacher.
35
  """
36
 
37
+ # Urdu mode → OpenAI GPT-OSS-120B model
38
+ else:
39
+ model_name = "openai/gpt-oss-120b"
40
  prompt = f"""
41
  آپ ایک ماہر اسباقی منصوبہ ساز ہیں۔
42
  موضوع "{topic}" پر BOPPPS ماڈل کے مطابق ایک مفصل اردو سبق منصوبہ تیار کریں۔
 
49
  6. سبق کا خلاصہ (Summary)
50
  """
51
 
52
+ # ✅ Generate text using selected model
53
  response = client.chat.completions.create(
54
+ model=model_name,
55
  messages=[{"role": "user", "content": prompt}],
56
  temperature=0.8,
57
  max_completion_tokens=2048,
 
59
  stream=False
60
  )
61
 
 
62
  lesson_text = response.choices[0].message.content.strip()
63
 
64
  # ✅ Create the Word document
 
84
 
85
  paragraph = doc.add_paragraph(lesson_text)
86
 
87
+ # Urdu formatting (right-aligned)
88
  if language == "Urdu":
89
  paragraph.alignment = 2
90
  rtl = OxmlElement('w:rtl')
 
93
 
94
  doc.add_paragraph("\nDeveloped by Najaf Ali Sharqi")
95
 
96
+ # Save file
97
  filename = f"lesson_plan_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.docx"
98
  filepath = f"/tmp/{filename}"
99
  doc.save(filepath)
 
140
  gr.Markdown("🔹 Developed by **Najaf Ali Sharqi**")
141
 
142
  demo.launch()