Update app.py
Browse files
app.py
CHANGED
|
@@ -1,114 +1,51 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from tools.arabic_generator import ArabicTextGenerator
|
| 3 |
from tools.quran_search import QuranSearchEngine
|
| 4 |
-
import logging
|
| 5 |
-
|
| 6 |
-
# Configure logging
|
| 7 |
-
logging.basicConfig(
|
| 8 |
-
level=logging.INFO,
|
| 9 |
-
format='%(asctime)s - %(levelname)s - %(message)s'
|
| 10 |
-
)
|
| 11 |
|
| 12 |
# Initialize tools
|
| 13 |
text_gen = ArabicTextGenerator()
|
| 14 |
quran_searcher = QuranSearchEngine()
|
| 15 |
|
| 16 |
def format_quran_results(results):
|
| 17 |
-
"""Format search results with enhanced styling"""
|
| 18 |
if not results:
|
| 19 |
-
return
|
| 20 |
-
<div style='text-align: center; padding: 20px; background: #fff8f8; border-radius: 5px;'>
|
| 21 |
-
⚠️ لم يتم العثور على نتائج، حاول تغيير مصطلحات البحث
|
| 22 |
-
</div>
|
| 23 |
-
""")
|
| 24 |
|
| 25 |
output = []
|
| 26 |
for r in results:
|
| 27 |
-
output.append(f""
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
</div>
|
| 33 |
-
""")
|
| 34 |
-
return "".join(output)
|
| 35 |
|
| 36 |
-
with gr.Blocks(
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
<div style='text-align: center;'>
|
| 40 |
-
<h1 style='color: #2b5876;'>منظومة الأدوات العربية</h1>
|
| 41 |
-
<p>أدوات متكاملة للتعامل مع النصوص العربية والقرآن الكريم</p>
|
| 42 |
-
</div>
|
| 43 |
-
""")
|
| 44 |
-
|
| 45 |
-
# Arabic Text Generator Tab
|
| 46 |
-
with gr.Tab("🖊️ مولد النصوص", id="text-gen-tab"):
|
| 47 |
with gr.Row():
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
gen_btn = gr.Button("توليد النص", variant="primary")
|
| 53 |
-
|
| 54 |
-
gr.Examples(
|
| 55 |
-
examples=[["الحمد لله رب العالمين"], ["التعليم في الوطن العربي"], ["قصيدة عن القدس"]],
|
| 56 |
-
inputs=text_input,
|
| 57 |
-
label="أمثلة جاهزة"
|
| 58 |
-
)
|
| 59 |
-
|
| 60 |
-
with gr.Column(scale=2):
|
| 61 |
-
text_output = gr.Textbox(label="النص المولد", lines=10, interactive=False)
|
| 62 |
|
| 63 |
gen_btn.click(
|
| 64 |
text_gen.generate,
|
| 65 |
inputs=[text_input, length_slider],
|
| 66 |
outputs=text_output
|
| 67 |
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
top_k = gr.Slider(1, 10, value=5, step=1, label="عدد النتائج")
|
| 76 |
-
search_btn = gr.Button("ابحث الآن", variant="primary")
|
| 77 |
-
|
| 78 |
-
with gr.Accordion("أمثلة بحثية", open=False):
|
| 79 |
-
gr.Examples(
|
| 80 |
-
examples=[
|
| 81 |
-
["العدل في الإسلام", 5],
|
| 82 |
-
["فضل الصبر", 3],
|
| 83 |
-
["الرحمة في القرآن", 4]
|
| 84 |
-
],
|
| 85 |
-
inputs=[search_input, top_k],
|
| 86 |
-
label="اضغط على مثال لتحميله"
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
with gr.Column(scale=2):
|
| 90 |
-
search_output = gr.HTML(label="نتائج البحث")
|
| 91 |
|
| 92 |
-
#
|
| 93 |
search_btn.click(
|
| 94 |
lambda q, k: format_quran_results(quran_searcher.search(q, k)),
|
| 95 |
inputs=[search_input, top_k],
|
| 96 |
-
outputs=search_output
|
| 97 |
-
api_name="quran_search"
|
| 98 |
)
|
| 99 |
-
|
| 100 |
-
# Footer
|
| 101 |
-
gr.Markdown("""
|
| 102 |
-
<div style='text-align: center; margin-top: 20px; color: #666; font-size: 0.9em;'>
|
| 103 |
-
تم التطوير باستخدام Quran-API و Hugging Face
|
| 104 |
-
</div>
|
| 105 |
-
""")
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
-
|
| 109 |
-
app.launch(
|
| 110 |
-
server_name="0.0.0.0",
|
| 111 |
-
server_port=7860,
|
| 112 |
-
show_error=True,
|
| 113 |
-
debug=True
|
| 114 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from tools.arabic_generator import ArabicTextGenerator
|
| 3 |
from tools.quran_search import QuranSearchEngine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Initialize tools
|
| 6 |
text_gen = ArabicTextGenerator()
|
| 7 |
quran_searcher = QuranSearchEngine()
|
| 8 |
|
| 9 |
def format_quran_results(results):
|
|
|
|
| 10 |
if not results:
|
| 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 |
+
# Arabic Generator UI (working - keep as is)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
with gr.Row():
|
| 25 |
+
text_input = gr.Textbox(label="النص الأولي")
|
| 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(
|
| 31 |
text_gen.generate,
|
| 32 |
inputs=[text_input, length_slider],
|
| 33 |
outputs=text_output
|
| 34 |
)
|
| 35 |
+
|
| 36 |
+
with gr.Tab("📖 البحث القرآني"):
|
| 37 |
+
# Quran Search UI (dynamic only)
|
| 38 |
+
search_input = gr.Textbox(label="موضوع البحث")
|
| 39 |
+
top_k = gr.Slider(1, 10, value=3, label="عدد النتائج")
|
| 40 |
+
search_btn = gr.Button("ابحث")
|
| 41 |
+
search_output = gr.Textbox(label="النتائج", lines=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Dynamic search only - no static examples
|
| 44 |
search_btn.click(
|
| 45 |
lambda q, k: format_quran_results(quran_searcher.search(q, k)),
|
| 46 |
inputs=[search_input, top_k],
|
| 47 |
+
outputs=search_output
|
|
|
|
| 48 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|