Update app.py
Browse files
app.py
CHANGED
|
@@ -2,29 +2,19 @@ import gradio as gr
|
|
| 2 |
from tools.arabic_generator import ArabicTextGenerator
|
| 3 |
from tools.quran_search import QuranSearchEngine
|
| 4 |
|
| 5 |
-
# Initialize
|
| 6 |
text_gen = ArabicTextGenerator()
|
| 7 |
quran_searcher = QuranSearchEngine()
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
return "⚠️ لم يتم العثور على نتائج، حاول تغيير مصطلحات البحث"
|
| 12 |
-
|
| 13 |
-
output = []
|
| 14 |
-
for r in results:
|
| 15 |
-
output.append(f"سورة {r['surah']} ({r['surah_num']}:{r['ayah_num']})")
|
| 16 |
-
output.append(f"التشابه: {r['similarity']}")
|
| 17 |
-
output.append(f"{r['text']}")
|
| 18 |
-
output.append("---")
|
| 19 |
-
return "\n".join(output)
|
| 20 |
|
| 21 |
with gr.Blocks(title="الأدوات العربية") as app:
|
|
|
|
| 22 |
with gr.Tab("🖊️ مولد النصوص"):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
length_slider = gr.Slider(50, 300, value=100, label="طول النص")
|
| 27 |
-
gen_btn = gr.Button("توليد")
|
| 28 |
text_output = gr.Textbox(label="النص المولد", lines=6)
|
| 29 |
|
| 30 |
gen_btn.click(
|
|
@@ -33,18 +23,22 @@ with gr.Blocks(title="الأدوات العربية") as app:
|
|
| 33 |
outputs=text_output
|
| 34 |
)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
search_btn = gr.Button("ابحث")
|
| 41 |
-
search_output = gr.Textbox(label="النتائج", lines=10)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
|
|
|
| 2 |
from tools.arabic_generator import ArabicTextGenerator
|
| 3 |
from tools.quran_search import QuranSearchEngine
|
| 4 |
|
| 5 |
+
# Initialize both models (keep your existing names)
|
| 6 |
text_gen = ArabicTextGenerator()
|
| 7 |
quran_searcher = QuranSearchEngine()
|
| 8 |
|
| 9 |
+
def display_surah(surah_id):
|
| 10 |
+
return quran_searcher.get_full_surah(surah_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
with gr.Blocks(title="الأدوات العربية") as app:
|
| 13 |
+
# Tab 1: Arabic Generator (keep exactly as is)
|
| 14 |
with gr.Tab("🖊️ مولد النصوص"):
|
| 15 |
+
text_input = gr.Textbox(label="النص الأولي")
|
| 16 |
+
length_slider = gr.Slider(50, 300, value=100, label="طول النص")
|
| 17 |
+
gen_btn = gr.Button("توليد")
|
|
|
|
|
|
|
| 18 |
text_output = gr.Textbox(label="النص المولد", lines=6)
|
| 19 |
|
| 20 |
gen_btn.click(
|
|
|
|
| 23 |
outputs=text_output
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# Tab 2: Quran Surah Viewer (new simple implementation)
|
| 27 |
+
with gr.Tab("📖 عرض السور"):
|
| 28 |
+
surahs = quran_searcher.get_all_surahs()
|
| 29 |
+
surah_choices = [(f"{s['name_arabic'} ({s['name_simple']})", s['id']) for s in surahs]
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
surah_dropdown = gr.Dropdown(
|
| 32 |
+
choices=surah_choices,
|
| 33 |
+
label="اختر سورة"
|
| 34 |
+
)
|
| 35 |
+
show_btn = gr.Button("عرض السورة")
|
| 36 |
+
quran_output = gr.Textbox(label="النص القرآني", lines=15)
|
| 37 |
+
|
| 38 |
+
show_btn.click(
|
| 39 |
+
display_surah,
|
| 40 |
+
inputs=surah_dropdown,
|
| 41 |
+
outputs=quran_output
|
| 42 |
)
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|