Spaces:
Sleeping
Sleeping
File size: 6,457 Bytes
40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 37d18ea 40ceeb7 |
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 |
import gradio as gr
import requests
from docx import Document
# ✅ Get Quran Surah or Ayah
def get_surah_ayah(surah_number, ayah_number):
try:
url = f"https://api.alquran.cloud/v1/surah/{surah_number}/editions/quran-simple,en.asad,ur.jalandhry"
response = requests.get(url)
response.raise_for_status()
data = response.json()
if 'data' in data and len(data['data']) == 3:
if ayah_number:
ayah_index = int(ayah_number) - 1
arabic = f"{ayah_number}. {data['data'][0]['ayahs'][ayah_index]['text']}"
english = f"{ayah_number}. {data['data'][1]['ayahs'][ayah_index]['text']}"
urdu = f"{ayah_number}. {data['data'][2]['ayahs'][ayah_index]['text']}"
else:
arabic = "\n\n".join([f"{i+1}. {a['text']}" for i, a in enumerate(data['data'][0]['ayahs'])])
english = "\n\n".join([f"{i+1}. {t['text']}" for i, t in enumerate(data['data'][1]['ayahs'])])
urdu = "\n\n".join([f"{i+1}. {u['text']}" for i, u in enumerate(data['data'][2]['ayahs'])])
return arabic, english, urdu
return "❌ Surah not found.", "❌ English not found.", "❌ Urdu not found."
except Exception as e:
return f"❌ API Error: {e}", "", ""
# ✅ Lesson Plan Generator (Urdu + English)
def generate_lesson_plan(language, class_name, topic, objective, students, duration, teacher, date, blooms_level):
doc = Document()
if language == "English":
doc.add_heading('BOPPPS Lesson Plan', 0)
doc.add_paragraph(f"Class: {class_name}")
doc.add_paragraph(f"Topic: {topic}")
doc.add_paragraph(f"Number of Students: {students}")
doc.add_paragraph(f"Duration: {duration}")
doc.add_paragraph(f"Teacher Name: {teacher}")
doc.add_paragraph(f"Date: {date}")
doc.add_heading('Bridge-In', level=1)
doc.add_paragraph("Start with a hook or story to grab students' attention related to the topic.")
doc.add_heading('Objective', level=1)
doc.add_paragraph(f"Students will be able to: {objective} [{blooms_level}]")
doc.add_heading('Pre-Assessment', level=1)
doc.add_paragraph("Ask students a few questions to check their prior knowledge.")
doc.add_heading('Participatory Learning', level=1)
doc.add_paragraph(f"Deliver content interactively about: {topic}")
doc.add_heading('Post-Assessment', level=1)
doc.add_paragraph("Conduct a short quiz, pair activity, or reflection.")
doc.add_heading('Summary', level=1)
doc.add_paragraph("Summarize key points and reinforce learning.")
else: # Urdu
doc.add_heading('BOPPPS لیسن پلان', 0)
doc.add_paragraph(f"کلاس: {class_name}")
doc.add_paragraph(f"موضوع: {topic}")
doc.add_paragraph(f"طلباء کی تعداد: {students}")
doc.add_paragraph(f"دورانیہ: {duration}")
doc.add_paragraph(f"استاد کا نام: {teacher}")
doc.add_paragraph(f"تاریخ: {date}")
doc.add_heading('آغازِ سبق (Bridge-In)', level=1)
doc.add_paragraph("طلباء کی توجہ حاصل کرنے کے لیے کوئی دلچسپ سوال یا واقعہ پیش کریں۔")
doc.add_heading('مقصد (Objective)', level=1)
doc.add_paragraph(f"طلباء یہ سیکھ سکیں گے: {objective} [{blooms_level}]")
doc.add_heading('پہلے سے جانچ (Pre-Assessment)', level=1)
doc.add_paragraph("طلباء سے ان کے پہلے علم کے بارے میں سوالات کریں۔")
doc.add_heading('شرکت پر مبنی سیکھنا (Participatory Learning)', level=1)
doc.add_paragraph(f"سبق کو متحرک انداز میں پیش کریں: {topic}")
doc.add_heading('بعد از جانچ (Post-Assessment)', level=1)
doc.add_paragraph("مختصر سرگرمی یا سوالات کے ذریعے جانچ کریں۔")
doc.add_heading('خلاصہ (Summary)', level=1)
doc.add_paragraph("اہم نکات کو دہرائیں اور سبق کا اختتام کریں۔")
# ✅ Save Word file
file_path = "/mnt/data/BOPPPS_Lesson_Plan.docx"
doc.save(file_path)
return file_path
# ✅ Surah Names (Short list for simplicity)
surah_names = [
"1 - Al-Fatiha", "2 - Al-Baqarah", "3 - Aal-E-Imran", "4 - An-Nisa", "5 - Al-Ma'idah",
"112 - Al-Ikhlas", "113 - Al-Falaq", "114 - An-Nas"
]
# ✅ Helper: Extract number from Surah string
def extract_number(surah_name):
return int(surah_name.split(" - ")[0])
# ✅ Quran Viewer Tab
quran_viewer = gr.Interface(
fn=lambda surah, ayah: get_surah_ayah(extract_number(surah), ayah),
inputs=[
gr.Dropdown(choices=surah_names, label="📖 Select Surah"),
gr.Textbox(label="🔢 Optional Ayah Number (e.g., 1, 5, 7)")
],
outputs=[
gr.Textbox(label="📜 Arabic", lines=10),
gr.Textbox(label="🌐 English", lines=10),
gr.Textbox(label="🌙 Urdu", lines=10)
],
title="📖 Quran Surah & Ayah Viewer",
description="Select a Surah and optionally enter an Ayah number to view that verse. Leave blank to get the full Surah."
)
# ✅ Lesson Plan Generator Tab
lesson_plan_generator = gr.Interface(
fn=generate_lesson_plan,
inputs=[
gr.Dropdown(["English", "Urdu"], label="🌐 Language"),
gr.Textbox(label="🏫 Class/Grade"),
gr.Textbox(label="🎯 Topic of the Lesson"),
gr.Textbox(label="✅ Learning Objective"),
gr.Textbox(label="👥 Number of Students"),
gr.Textbox(label="⏱ Duration of Class"),
gr.Textbox(label="👤 Name of Teacher"),
gr.Textbox(label="📅 Date (e.g., 2025-07-01)"),
gr.Dropdown(["Knowledge", "Comprehension", "Application", "Analysis", "Synthesis", "Evaluation"], label="🧠 Bloom's Level")
],
outputs=gr.File(label="📥 Download Lesson Plan (MS Word)"),
title="📄 BOPPPS Lesson Plan Generator",
description="Fill the form to generate a Word file of your lesson plan using the BOPPPS framework."
)
# ✅ Combine Tabs
app = gr.TabbedInterface(
interface_list=[quran_viewer, lesson_plan_generator],
tab_names=["📖 Quran Viewer", "📄 Lesson Plan Generator"]
)
# ✅ Launch App
app.launch()
|