Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,63 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from tools.arabic_generator import ArabicTextGenerator
|
| 3 |
from tools.quran_search import QuranSearchEngine
|
| 4 |
-
import logging
|
| 5 |
|
| 6 |
-
# Initialize both tools
|
| 7 |
text_gen = ArabicTextGenerator()
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Configure logging
|
| 11 |
-
logging.basicConfig(level=logging.INFO)
|
| 12 |
|
| 13 |
def format_quran_results(results):
|
| 14 |
-
if not results
|
| 15 |
-
return
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
with gr.Blocks(
|
| 22 |
-
gr.Markdown("# <center>الأدوات العربية
|
| 23 |
|
| 24 |
-
with gr.Tab("مولد النصوص
|
| 25 |
-
gr.Markdown("##
|
| 26 |
with gr.Row():
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
# Examples for text generation
|
| 34 |
gr.Examples(
|
| 35 |
-
examples=[
|
| 36 |
-
["الحمد لله رب العالمين"],
|
| 37 |
-
["التعليم في الوطن العربي"],
|
| 38 |
-
["قصيدة عن فلسطين"]
|
| 39 |
-
],
|
| 40 |
inputs=text_input
|
| 41 |
)
|
| 42 |
|
| 43 |
-
with gr.Tab("البحث القرآني"):
|
| 44 |
-
gr.Markdown("##
|
| 45 |
with gr.Row():
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
# Examples for Quran search
|
| 53 |
gr.Examples(
|
| 54 |
-
examples=[
|
| 55 |
-
|
| 56 |
-
["فضل الصبر", 3],
|
| 57 |
-
["الرحمة في القرآن", 4]
|
| 58 |
-
],
|
| 59 |
-
inputs=[search_input, results_slider]
|
| 60 |
)
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
|
| 64 |
text_gen.generate,
|
| 65 |
inputs=[text_input, length_slider],
|
| 66 |
outputs=text_output
|
| 67 |
)
|
| 68 |
|
| 69 |
search_btn.click(
|
| 70 |
-
lambda q,
|
| 71 |
-
inputs=[search_input,
|
| 72 |
outputs=search_output
|
| 73 |
)
|
| 74 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from tools.arabic_generator import ArabicTextGenerator
|
| 3 |
from tools.quran_search import QuranSearchEngine
|
|
|
|
| 4 |
|
|
|
|
| 5 |
text_gen = ArabicTextGenerator()
|
| 6 |
+
quran_search = QuranSearchEngine()
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def format_quran_results(results):
|
| 9 |
+
if not results:
|
| 10 |
+
return "⚠️ لم يتم العثور على نتائج، حاول تغيير مصطلحات البحث"
|
| 11 |
+
|
| 12 |
+
output = []
|
| 13 |
+
for r in results:
|
| 14 |
+
output.append(f"### سورة {r['surah']} ({r['surah_num']}:{r['ayah_num']})")
|
| 15 |
+
output.append(f"**التشابه**: {r['similarity']} \n")
|
| 16 |
+
output.append(f"**النص**: {r['text']}")
|
| 17 |
+
output.append("\n---\n")
|
| 18 |
+
return "\n".join(output)
|
| 19 |
|
| 20 |
+
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 21 |
+
gr.Markdown("# <center>منظومة الأدوات العربية</center>")
|
| 22 |
|
| 23 |
+
with gr.Tab("🖊️ مولد النصوص"):
|
| 24 |
+
gr.Markdown("## توليد نصوص عربية ذكية")
|
| 25 |
with gr.Row():
|
| 26 |
+
with gr.Column():
|
| 27 |
+
text_input = gr.Textbox(label="النص الأولي", interactive=True)
|
| 28 |
+
length_slider = gr.Slider(50, 300, value=100, label="طول النص")
|
| 29 |
+
gen_btn = gr.Button("توليد", variant="primary")
|
| 30 |
+
text_output = gr.Textbox(label="النص المولد", lines=8)
|
| 31 |
|
|
|
|
| 32 |
gr.Examples(
|
| 33 |
+
examples=[["الحمد لله رب العالمين"], ["التعليم في الوطن العربي"], ["قصيدة عن القدس"]],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
inputs=text_input
|
| 35 |
)
|
| 36 |
|
| 37 |
+
with gr.Tab("📖 البحث القرآني"):
|
| 38 |
+
gr.Markdown("## بحث دلالي في القرآن الكريم")
|
| 39 |
with gr.Row():
|
| 40 |
+
with gr.Column():
|
| 41 |
+
search_input = gr.Textbox(label="موضوع البحث")
|
| 42 |
+
top_k = gr.Slider(1, 10, value=3, label="عدد النتائج")
|
| 43 |
+
search_btn = gr.Button("ابحث", variant="primary")
|
| 44 |
+
search_output = gr.Markdown() # Using Markdown for richer output
|
| 45 |
|
|
|
|
| 46 |
gr.Examples(
|
| 47 |
+
examples=[["العدل في الإسلام", 5], ["فضل الصبر", 3], ["الرحمة", 4]],
|
| 48 |
+
inputs=[search_input, top_k]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
+
# Event handlers
|
| 52 |
+
gen_btn.click(
|
| 53 |
text_gen.generate,
|
| 54 |
inputs=[text_input, length_slider],
|
| 55 |
outputs=text_output
|
| 56 |
)
|
| 57 |
|
| 58 |
search_btn.click(
|
| 59 |
+
lambda q,k: format_quran_results(quran_search.search(q,k)),
|
| 60 |
+
inputs=[search_input, top_k],
|
| 61 |
outputs=search_output
|
| 62 |
)
|
| 63 |
|