Batnini commited on
Commit
8389c61
·
verified ·
1 Parent(s): 860a19b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -36
app.py CHANGED
@@ -1,34 +1,64 @@
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(theme=gr.themes.Soft()) as app:
22
- gr.Markdown("# <center>منظومة الأدوات العربية</center>")
 
 
 
 
 
 
23
 
24
- with gr.Tab("🖊️ مولد النصوص"):
25
- # Arabic Generator UI
26
  with gr.Row():
27
- with gr.Column():
28
- text_input = gr.Textbox(label=لنص الأولي")
 
29
  length_slider = gr.Slider(50, 300, value=100, label="طول النص")
30
- gen_btn = gr.Button("توليد", variant="primary")
31
- text_output = gr.Textbox(label="النص المولد", lines=8)
 
 
 
 
 
 
 
 
32
 
33
  gen_btn.click(
34
  text_gen.generate,
@@ -36,33 +66,49 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
36
  outputs=text_output
37
  )
38
 
39
- with gr.Tab("📖 البحث القرآني"):
40
- # Quran Search UI
41
  with gr.Row():
42
- with gr.Column():
43
- search_input = gr.Textbox(label="موضوع البحث")
44
- top_k = gr.Slider(1, 10, value=5, label=دد النتائج")
45
- search_btn = gr.Button("ابحث", variant="primary")
46
- search_output = gr.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- # Connect search button
49
  search_btn.click(
50
  lambda q, k: format_quran_results(quran_searcher.search(q, k)),
51
  inputs=[search_input, top_k],
52
- outputs=search_output
 
53
  )
54
-
55
- # Examples section
56
- with gr.Accordion("أمثلة بحثية", open=False):
57
- gr.Examples(
58
- examples=[
59
- ["العدل في الإسلام", 5],
60
- ["فضل الصبر", 3],
61
- ["الرحمة في القرآن", 4]
62
- ],
63
- inputs=[search_input, top_k],
64
- label="اضغط على مثال لتحميله"
65
- )
66
 
67
  if __name__ == "__main__":
68
- app.launch()
 
 
 
 
 
 
 
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 gr.Markdown("""
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
+ <div style='background: #f8f8ff; padding: 15px; border-radius: 8px; margin-bottom: 10px;'>
29
+ <h3 style='color: #2b5876;'>سورة {r['surah']} ({r['surah_num']}:{r['ayah_num']})</h3>
30
+ <p style='color: #4a6b8a; font-size: 0.9em;'>التشابه: {r['similarity']}</p>
31
+ <p style='font-size: 1.2em; line-height: 1.8; text-align: right;'>{r['text']}</p>
32
+ </div>
33
+ """)
34
+ return "".join(output)
35
 
36
+ with gr.Blocks(theme=gr.themes.Soft(), title="الأدوات العربية") as app:
37
+ # Header
38
+ gr.Markdown("""
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
+ with gr.Column(scale=1):
49
+ gr.Markdown("### إعدادات النص")
50
+ text_input = gr.Textbox(label="النص الأولي", placeholder="اكتب بداية النص هنا...")
51
  length_slider = gr.Slider(50, 300, value=100, label="طول النص")
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,
 
66
  outputs=text_output
67
  )
68
 
69
+ # Quran Search Tab
70
+ with gr.Tab("📖 البحث القرآني", id="quran-search-tab"):
71
  with gr.Row():
72
+ with gr.Column(scale=1):
73
+ gr.Markdown("### إعدادات البحث")
74
+ search_input = gr.Textbox(label="موضوع البحث", placeholder="ابحث عن مواضيع مثل: العدل، الصبر...")
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
+ # Search button with loading indicator
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
+ # Launch with better configuration
109
+ app.launch(
110
+ server_name="0.0.0.0",
111
+ server_port=7860,
112
+ show_error=True,
113
+ debug=True
114
+ )