Batnini commited on
Commit
f4c6a6d
·
verified ·
1 Parent(s): 0b9d33f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -28
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 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(
@@ -33,18 +23,22 @@ with gr.Blocks(title="الأدوات العربية") as app:
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__":
 
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__":