Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,53 +5,48 @@ import datetime
|
|
| 5 |
from groq import Groq
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
|
| 8 |
-
# ✅ Load API
|
| 9 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 11 |
|
| 12 |
# ✅ Initialize clients
|
| 13 |
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 14 |
-
hf_client = InferenceClient(model="
|
| 15 |
|
| 16 |
-
|
| 17 |
-
# ✅ Core Function
|
| 18 |
def generate_lesson_plan(language, class_, subject, topic, students, duration, date, teacher):
|
| 19 |
try:
|
| 20 |
if language == "Urdu":
|
|
|
|
| 21 |
prompt = f"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
6. سبق کا خلاصہ (Summary)۔
|
| 32 |
-
براہ کرم مکمل متن قدرتی اور تعلیمی انداز میں اردو میں لکھیں۔
|
| 33 |
"""
|
| 34 |
|
| 35 |
response = hf_client.text_generation(
|
| 36 |
prompt,
|
| 37 |
max_new_tokens=900,
|
| 38 |
-
temperature=0.
|
| 39 |
)
|
| 40 |
-
|
| 41 |
lesson_text = response.strip()
|
| 42 |
|
| 43 |
else:
|
| 44 |
prompt = f"""
|
| 45 |
You are a professional lesson plan expert.
|
| 46 |
Create a detailed English lesson plan using the BOPPPS model for the topic: "{topic}".
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
6. A short Summary paragraph.
|
| 55 |
"""
|
| 56 |
|
| 57 |
response = groq_client.chat.completions.create(
|
|
@@ -62,7 +57,7 @@ Include only the following:
|
|
| 62 |
|
| 63 |
lesson_text = response.choices[0].message.content.strip()
|
| 64 |
|
| 65 |
-
# ✅ Create Word
|
| 66 |
doc = Document()
|
| 67 |
doc.add_heading("BOPPPS Lesson Plan", 0)
|
| 68 |
|
|
@@ -114,7 +109,7 @@ with gr.Blocks() as demo:
|
|
| 114 |
class_ = gr.Textbox(label="Class", placeholder="e.g., 9th")
|
| 115 |
subject = gr.Textbox(label="Subject", placeholder="e.g., Physics")
|
| 116 |
with gr.Row():
|
| 117 |
-
topic = gr.Textbox(label="Topic", placeholder="e.g.,
|
| 118 |
students = gr.Textbox(label="Number of Students", placeholder="e.g., 30")
|
| 119 |
with gr.Row():
|
| 120 |
duration = gr.Textbox(label="Duration (minutes)", placeholder="e.g., 40")
|
|
|
|
| 5 |
from groq import Groq
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
|
| 8 |
+
# ✅ Load API keys
|
| 9 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 11 |
|
| 12 |
# ✅ Initialize clients
|
| 13 |
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 14 |
+
hf_client = InferenceClient(model="facebook/m2m100-1.2B", token=HF_TOKEN)
|
| 15 |
|
|
|
|
|
|
|
| 16 |
def generate_lesson_plan(language, class_, subject, topic, students, duration, date, teacher):
|
| 17 |
try:
|
| 18 |
if language == "Urdu":
|
| 19 |
+
# Prompt in English → translated to Urdu by model
|
| 20 |
prompt = f"""
|
| 21 |
+
Write a complete BOPPPS lesson plan in **Urdu language** for the topic: "{topic}".
|
| 22 |
+
Include the following sections clearly in Urdu:
|
| 23 |
+
1. Bridge-In (interesting introduction)
|
| 24 |
+
2. 3 Learning Objectives
|
| 25 |
+
3. 2 Pre-assessment questions
|
| 26 |
+
4. One detailed participatory learning activity
|
| 27 |
+
5. 2–3 Post-assessment questions
|
| 28 |
+
6. A concluding Summary paragraph
|
| 29 |
+
Make the tone natural and educational for teachers.
|
|
|
|
|
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
response = hf_client.text_generation(
|
| 33 |
prompt,
|
| 34 |
max_new_tokens=900,
|
| 35 |
+
temperature=0.8,
|
| 36 |
)
|
|
|
|
| 37 |
lesson_text = response.strip()
|
| 38 |
|
| 39 |
else:
|
| 40 |
prompt = f"""
|
| 41 |
You are a professional lesson plan expert.
|
| 42 |
Create a detailed English lesson plan using the BOPPPS model for the topic: "{topic}".
|
| 43 |
+
Include:
|
| 44 |
+
1. Bridge-In (short, engaging paragraph)
|
| 45 |
+
2. 3 Clear Learning Objectives
|
| 46 |
+
3. 2 Pre-Assessment Questions
|
| 47 |
+
4. One detailed Participatory Learning Activity
|
| 48 |
+
5. 2–3 Post-Assessment Questions
|
| 49 |
+
6. A short Summary paragraph
|
|
|
|
| 50 |
"""
|
| 51 |
|
| 52 |
response = groq_client.chat.completions.create(
|
|
|
|
| 57 |
|
| 58 |
lesson_text = response.choices[0].message.content.strip()
|
| 59 |
|
| 60 |
+
# ✅ Create Word Document
|
| 61 |
doc = Document()
|
| 62 |
doc.add_heading("BOPPPS Lesson Plan", 0)
|
| 63 |
|
|
|
|
| 109 |
class_ = gr.Textbox(label="Class", placeholder="e.g., 9th")
|
| 110 |
subject = gr.Textbox(label="Subject", placeholder="e.g., Physics")
|
| 111 |
with gr.Row():
|
| 112 |
+
topic = gr.Textbox(label="Topic", placeholder="e.g., Newton’s Laws")
|
| 113 |
students = gr.Textbox(label="Number of Students", placeholder="e.g., 30")
|
| 114 |
with gr.Row():
|
| 115 |
duration = gr.Textbox(label="Duration (minutes)", placeholder="e.g., 40")
|