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()