Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,49 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
device=-1) # Force CPU
|
8 |
|
9 |
-
def
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
)
|
16 |
-
return output[0]['generated_text']
|
17 |
|
18 |
-
with gr.Blocks() as
|
19 |
-
gr.Markdown("
|
20 |
-
with gr.Row():
|
21 |
-
inp = gr.Textbox(label="اكتب مقدمة للنص")
|
22 |
-
btn = gr.Button("ولّد")
|
23 |
-
out = gr.Textbox(label="النص المولد")
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from tools import ArabicTextGenerator, QuranSearchEngine
|
3 |
|
4 |
+
# Initialize tools
|
5 |
+
text_gen = ArabicTextGenerator()
|
6 |
+
quran_search = QuranSearchEngine()
|
|
|
7 |
|
8 |
+
def format_quran_results(results):
|
9 |
+
if not results:
|
10 |
+
return "لا توجد نتائج"
|
11 |
+
return "\n\n".join(
|
12 |
+
f"سورة {r['surah']} آية {r['ayah']} (التشابه: {r['similarity']}):\n{r['text']}"
|
13 |
+
for r in results
|
14 |
)
|
|
|
15 |
|
16 |
+
with gr.Blocks(title="الأدوات العربية") as app:
|
17 |
+
gr.Markdown("# <center>الأدوات العربية</center>")
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
with gr.Tab("مولد النصوص"):
|
20 |
+
gr.Markdown("## مولد النصوص العربية")
|
21 |
+
with gr.Row():
|
22 |
+
text_input = gr.Textbox(label="النص الأولي", placeholder="اكتب بداية النص هنا...")
|
23 |
+
length_slider = gr.Slider(50, 300, 100, label="طول النص")
|
24 |
+
generate_btn = gr.Button("توليد")
|
25 |
+
text_output = gr.Textbox(label="النص المولد", lines=6)
|
26 |
+
|
27 |
+
with gr.Tab("بحث قرآني"):
|
28 |
+
gr.Markdown("## محرك البحث الدلالي في القرآن")
|
29 |
+
with gr.Row():
|
30 |
+
search_input = gr.Textbox(label="موضوع البحث", placeholder="ابحث عن مواضيع مثل: الصبر، العدل، الرحمة...")
|
31 |
+
results_slider = gr.Slider(1, 10, 5, label="عدد الآيات")
|
32 |
+
search_btn = gr.Button("بحث")
|
33 |
+
search_output = gr.Textbox(label="النتائج", lines=10)
|
34 |
+
|
35 |
+
# Connect components
|
36 |
+
generate_btn.click(
|
37 |
+
text_gen.generate,
|
38 |
+
inputs=[text_input, length_slider],
|
39 |
+
outputs=text_output
|
40 |
+
)
|
41 |
+
|
42 |
+
search_btn.click(
|
43 |
+
lambda q, k: format_quran_results(quran_search.search(q, k)),
|
44 |
+
inputs=[search_input, results_slider],
|
45 |
+
outputs=search_output
|
46 |
+
)
|
47 |
|
48 |
+
if __name__ == "__main__":
|
49 |
+
app.launch()
|