Spaces:
Sleeping
Sleeping
File size: 6,166 Bytes
5a15d4f 4a87d12 12a724e 4a87d12 5d65935 4a87d12 7b25f62 5a15d4f 2021d53 4a87d12 afaf86f 4a87d12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | import os
import gradio as gr
import datetime
from groq import Groq
from docx import Document
from docx.shared import Pt
from tempfile import NamedTemporaryFile
# ✅ Groq API Key
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
client = Groq(api_key=GROQ_API_KEY)
# ✅ Function to generate lesson plan
def generate_lesson_plan(language, class_, subject, topic, students, duration, date, teacher, theme):
if language == "Urdu":
model_name = "openai/gpt-oss-120b"
else:
model_name = "llama-3.1-8b-instant"
# ✅ Prompt templates
if language == "English":
prompt = f"""
You are an expert lesson plan designer.
Create a complete **BOPPPS Model Lesson Plan** in English with the following sections:
1. Bridge-in
2. Pre-Assessment
3. Learning Outcomes
4. Participatory Learning Activities
5. Post-Assessment
6. Summary
7. Home Assignment aligned with SLOs
Make it logical, creative, and suitable for grade level.
Do not repeat input details in body text.
Include only one concise header table of details.
Class: {class_}
Subject: {subject}
Topic: {topic}
Students: {students}
Duration: {duration}
Date: {date}
Teacher: {teacher}
"""
else:
prompt = f"""
آپ ایک ماہر استاد ہیں۔ درج ذیل معلومات کی بنیاد پر **BOPPPS ماڈل** کے مطابق ایک مکمل روزانہ کا تدریسی منصوبہ اردو زبان میں تیار کریں۔
انگریزی حروف استعمال نہ کریں، صرف اردو رسم الخط استعمال کریں۔
درج ذیل حصے لازمی شامل ہوں:
۱۔ ابتدائی تعارف (Bridge-in)
۲۔ ابتدائی تشخیص (Pre-Assessment)
۳۔ تعلیمی مقاصد (Learning Outcomes)
۴۔ شراکتی تعلیمی سرگرمیاں (Participatory Learning Activities)
۵۔ بعد از تدریس تشخیص (Post-Assessment)
۶۔ خلاصہ (Summary)
۷۔ گھریلو کام (SLOs کے مطابق)
جماعت: {class_}
مضمون: {subject}
عنوان: {topic}
طلباء کی تعداد: {students}
دورانیہ: {duration}
تاریخ: {date}
معلم: {teacher}
"""
# ✅ Generate text
response = client.chat.completions.create(
model=model_name,
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
)
lesson_text = response.choices[0].message.content.strip()
# ✅ ENGLISH VERSION — create .docx
if language == "English":
doc = Document()
doc.add_heading("BOPPPS Lesson Plan", level=1)
table = doc.add_table(rows=7, cols=2)
table.style = "Table Grid"
headers = ["Class", "Subject", "Topic", "Students", "Duration", "Date", "Teacher"]
values = [class_, subject, topic, students, duration, date, teacher]
for i in range(7):
table.cell(i, 0).text = headers[i]
table.cell(i, 1).text = str(values[i])
doc.add_paragraph("\n" + lesson_text)
doc.add_paragraph("\nDeveloped by Najaf Ali Sharqi")
temp_file = NamedTemporaryFile(delete=False, suffix=".docx")
doc.save(temp_file.name)
final_text = f"✅ English lesson plan generated successfully for {subject} (Grade {class_})."
file_output = temp_file.name
# ✅ URDU VERSION — create .md
else:
urdu_md = f"""
<div dir="rtl" align="right">
# یومیہ تدریسی منصوبہ (BOPPPS ماڈل)
| کلیدی معلومات | تفصیل |
|----------------|--------|
| جماعت | {class_} |
| مضمون | {subject} |
| عنوان | {topic} |
| طلباء کی تعداد | {students} |
| دورانیہ | {duration} |
| تاریخ | {date} |
| معلم | {teacher} |
---
{lesson_text}
---
**مرتب کردہ: نجف علی شرقی**
</div>
"""
temp_file = NamedTemporaryFile(delete=False, suffix=".md", mode="w", encoding="utf-8")
temp_file.write(urdu_md)
temp_file.close()
final_text = f"✅ اردو تدریسی منصوبہ برائے مضمون {subject} کامیابی سے تیار ہو گیا۔"
file_output = temp_file.name
# ✅ Theme customization (brightness)
if theme == "Dark":
theme_css = "background-color:#111;color:#fff;padding:10px;border-radius:10px;"
else:
theme_css = "background-color:#fdfdfd;color:#000;padding:10px;border-radius:10px;"
safe_html = final_text.replace("\n", "<br>")
display_html = f"<div style='{theme_css}'>{safe_html}</div>"
return display_html, file_output
# ✅ Dropdowns and Interface
demo = gr.Interface(
fn=generate_lesson_plan,
inputs=[
gr.Radio(["English", "Urdu"], label="Select Language / زبان کا انتخاب"),
gr.Dropdown([f"Grade {i}" for i in range(1, 17)], label="Class / جماعت"),
gr.Dropdown(
["Urdu", "English", "Arabic", "Science", "Mathematics", "Biology",
"Chemistry", "Physics", "Zoology", "Botany", "Civics", "Islamiat"],
label="Subject / مضمون"
),
gr.Textbox(label="Topic / عنوان"),
gr.Slider(1, 200, value=30, step=1, label="Number of Students / طلباء کی تعداد"),
gr.Slider(30, 60, value=40, step=5, label="Duration (minutes) / دورانیہ (منٹ)"),
gr.Textbox(label="Date / تاریخ", value=str(datetime.date.today())),
gr.Textbox(label="Teacher Name / معلم کا نام"),
gr.Radio(["Light", "Dark"], label="Theme / پس منظر کا انتخاب", value="Light"),
],
outputs=[
gr.HTML(label="📄 Lesson Plan Preview"),
gr.File(label="⬇️ Download File (.docx or .md)")
],
title="📘 AI BOPPPS Lesson Plan Generator (Urdu + English)",
description=(
"⚙️ Developed by **Najaf Ali Sharqi**. <br>"
"یہ ایپ خودکار طور پر اردو یا انگریزی میں مکمل BOPPPS ماڈل کے مطابق یومیہ تدریسی منصوبہ تیار کرتی ہے۔<br>"
"اردو ورژن `.md` فارمیٹ میں جبکہ انگریزی ورژن `.docx` میں ڈاؤن لوڈ ہوتا ہے۔"
),
theme="default"
)
demo.launch()
|