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