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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -12
app.py CHANGED
@@ -1,12 +1,12 @@
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 = [
@@ -43,25 +43,38 @@ def execute_tool_call(tool_call):
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,
 
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
5
 
6
  # Initialize all models
7
  text_gen = ArabicTextGenerator()
8
  quran_searcher = QuranSearchEngine()
9
+ tool_agent = ToolCallingAgent()
10
 
11
  # Define tools for the agent
12
  TOOLS = [
 
43
  return "Tool not found"
44
 
45
  with gr.Blocks(title="Advanced Arabic Tools") as app:
46
+ # Tab 1: Arabic Text Generator
47
  with gr.Tab("🖊️ مولد النصوص"):
48
+ text_input = gr.Textbox(label="النص الأولي")
49
+ length_slider = gr.Slider(50, 300, value=100, label="طول النص")
50
+ gen_btn = gr.Button("توليد")
51
+ text_output = gr.Textbox(label="النص المولد", lines=6)
52
+
53
+ gen_btn.click(
54
+ text_gen.generate,
55
+ inputs=[text_input, length_slider],
56
+ outputs=text_output
57
+ )
58
 
59
+ # Tab 2: Quran Search
60
  with gr.Tab("📖 القرآن الكريم"):
61
+ search_input = gr.Textbox(label="موضوع البحث")
62
+ top_k = gr.Slider(1, 10, value=5, label="عدد النتائج")
63
+ search_btn = gr.Button("ابحث")
64
+ search_output = gr.Textbox(label="النتائج", lines=10)
65
+
66
+ search_btn.click(
67
+ lambda q, k: format_quran_results(quran_searcher.search(q, k)),
68
+ inputs=[search_input, top_k],
69
+ outputs=search_output
70
+ )
71
 
72
+ # Tab 3: Tool Calling Agent
73
  with gr.Tab("🛠️ الوكيل الذكي"):
74
  tool_input = gr.Textbox(label="أدخل طلبك")
75
  tool_output = gr.JSON(label="استجابة الأداة")
76
  tool_btn = gr.Button("تنفيذ")
77
 
 
 
 
 
 
 
78
  tool_btn.click(
79
  run_tool_agent,
80
  inputs=tool_input,