Batnini commited on
Commit
d29634e
·
verified ·
1 Parent(s): f1ffe70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -26
app.py CHANGED
@@ -1,38 +1,72 @@
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 = QuranSearchEngine()
 
7
 
8
- with gr.Blocks(title="الأدوات العربية") as app:
9
- # Tab 1: Your Working Arabic Generator (UNTOUCHED)
10
- with gr.Tab("🖊️ مولد النصوص"):
11
- text_input = gr.Textbox(label="النص الأولي")
12
- length_slider = gr.Slider(50, 300, value=100, label="طول النص")
13
- gen_btn = gr.Button("توليد")
14
- text_output = gr.Textbox(label="النص المولد", lines=6)
15
-
16
- gen_btn.click(
17
- text_gen.generate,
18
- inputs=[text_input, length_slider],
19
- outputs=text_output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  )
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Tab 2: Quran Surah Viewer (GUARANTEED TO WORK)
23
  with gr.Tab("📖 القرآن الكريم"):
24
- surah_dropdown = gr.Dropdown(
25
- label="اختر سورة",
26
- choices=quran.get_surahs(),
27
- value=1 # Default to Al-Fatiha
28
- )
29
- show_btn = gr.Button("عرض السورة")
30
- quran_output = gr.Textbox(label="النص القرآني", lines=15)
 
 
 
 
 
 
31
 
32
- show_btn.click(
33
- quran.get_surah_text,
34
- inputs=surah_dropdown,
35
- outputs=quran_output
36
  )
37
 
38
- app.launch()
 
 
1
  import gradio as gr
2
  from tools.arabic_generator import ArabicTextGenerator
3
  from tools.quran_search import QuranSearchEngine
4
+ from tools.tool_agent import ToolCallingAgent # <-- New import
5
 
6
+ # Initialize all models
7
  text_gen = ArabicTextGenerator()
8
+ quran_searcher = QuranSearchEngine()
9
+ tool_agent = ToolCallingAgent() # <-- New agent
10
 
11
+ # Define tools for the agent
12
+ TOOLS = [
13
+ {
14
+ "name": "search_quran",
15
+ "description": "Search the Quran for verses",
16
+ "parameters": {
17
+ "query": {"type": "string"},
18
+ "max_results": {"type": "integer"}
19
+ }
20
+ },
21
+ {
22
+ "name": "generate_text",
23
+ "description": "Generate Arabic text",
24
+ "parameters": {
25
+ "prompt": {"type": "string"},
26
+ "length": {"type": "integer"}
27
+ }
28
+ }
29
+ ]
30
+
31
+ def execute_tool_call(tool_call):
32
+ """Execute the tool and return results"""
33
+ if tool_call["tool_name"] == "search_quran":
34
+ return quran_searcher.search(
35
+ tool_call["parameters"]["query"],
36
+ tool_call["parameters"]["max_results"]
37
  )
38
+ elif tool_call["tool_name"] == "generate_text":
39
+ return text_gen.generate(
40
+ tool_call["parameters"]["prompt"],
41
+ tool_call["parameters"]["length"]
42
+ )
43
+ return "Tool not found"
44
+
45
+ with gr.Blocks(title="Advanced Arabic Tools") as app:
46
+ # Existing tabs remain unchanged
47
+ with gr.Tab("🖊️ مولد النصوص"):
48
+ # ... (keep your existing Arabic generator UI)
49
 
 
50
  with gr.Tab("📖 القرآن الكريم"):
51
+ # ... (keep your existing Quran search UI)
52
+
53
+ # New Tool Calling Agent tab
54
+ with gr.Tab("🛠️ الوكيل الذكي"):
55
+ tool_input = gr.Textbox(label="أدخل طلبك")
56
+ tool_output = gr.JSON(label="استجابة الأداة")
57
+ tool_btn = gr.Button("تنفيذ")
58
+
59
+ def run_tool_agent(query):
60
+ tool_call = tool_agent.generate(query, TOOLS)
61
+ if "error" in tool_call:
62
+ return tool_call
63
+ return execute_tool_call(tool_call)
64
 
65
+ tool_btn.click(
66
+ run_tool_agent,
67
+ inputs=tool_input,
68
+ outputs=tool_output
69
  )
70
 
71
+ if __name__ == "__main__":
72
+ app.launch()