Batnini commited on
Commit
07a1c4f
·
verified ·
1 Parent(s): aba96eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -35
app.py CHANGED
@@ -1,22 +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
5
 
6
  # Initialize models
7
  text_gen = ArabicTextGenerator()
8
- quran = QuranSearchEngine()
9
  tool_agent = ToolCallingAgent()
10
 
11
  TOOLS = [
12
- {
13
- "name": "search_quran",
14
- "description": "Search Quran verses",
15
- "parameters": {
16
- "query": {"type": "string"},
17
- "max_results": {"type": "integer", "max": 5}
18
- }
19
- },
20
  {
21
  "name": "generate_text",
22
  "description": "Generate Arabic text",
@@ -28,8 +18,6 @@ TOOLS = [
28
  ]
29
 
30
  def format_output(result):
31
- if isinstance(result, list): # Quran results
32
- return "\n".join(f"{r['surah']} {r['ayah']}: {r['text']}" for r in result)
33
  return str(result)
34
 
35
  with gr.Blocks(title="الأدوات العربية") as app:
@@ -48,22 +36,7 @@ with gr.Blocks(title="الأدوات العربية") as app:
48
  outputs=arabic_output
49
  )
50
 
51
- # Tab 2: Quran Search
52
- with gr.Tab("📖 القرآن الكريم"):
53
- with gr.Row():
54
- with gr.Column():
55
- search_input = gr.Textbox(label="موضوع البحث")
56
- results_slider = gr.Slider(1, 5, value=3, label="عدد النتائج")
57
- search_btn = gr.Button("ابحث")
58
- quran_output = gr.Textbox(label="النتائج", lines=10)
59
-
60
- search_btn.click(
61
- lambda q, k: format_output(quran.search(q, k)),
62
- inputs=[search_input, results_slider],
63
- outputs=quran_output
64
- )
65
-
66
- # Tab 3: Tool Agent
67
  with gr.Tab("🛠️ مساعد ذكي"):
68
  with gr.Row():
69
  with gr.Column():
@@ -74,12 +47,7 @@ with gr.Blocks(title="الأدوات العربية") as app:
74
  def process_tool(input_text):
75
  try:
76
  tool_call = tool_agent.generate(input_text, TOOLS)
77
- if tool_call["tool_name"] == "search_quran":
78
- return quran.search(
79
- tool_call["parameters"]["query"],
80
- tool_call["parameters"]["max_results"]
81
- )
82
- elif tool_call["tool_name"] == "generate_text":
83
  return text_gen.generate(
84
  tool_call["parameters"]["prompt"],
85
  tool_call["parameters"]["length"]
@@ -95,4 +63,4 @@ with gr.Blocks(title="الأدوات العربية") as app:
95
  )
96
 
97
  if __name__ == "__main__":
98
- app.launch()
 
1
  import gradio as gr
2
  from tools.arabic_generator import ArabicTextGenerator
 
3
  from tools.tool_agent import ToolCallingAgent
4
 
5
  # Initialize models
6
  text_gen = ArabicTextGenerator()
 
7
  tool_agent = ToolCallingAgent()
8
 
9
  TOOLS = [
 
 
 
 
 
 
 
 
10
  {
11
  "name": "generate_text",
12
  "description": "Generate Arabic text",
 
18
  ]
19
 
20
  def format_output(result):
 
 
21
  return str(result)
22
 
23
  with gr.Blocks(title="الأدوات العربية") as app:
 
36
  outputs=arabic_output
37
  )
38
 
39
+ # Tab 2: Tool Agent (only text generation now)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  with gr.Tab("🛠️ مساعد ذكي"):
41
  with gr.Row():
42
  with gr.Column():
 
47
  def process_tool(input_text):
48
  try:
49
  tool_call = tool_agent.generate(input_text, TOOLS)
50
+ if tool_call["tool_name"] == "generate_text":
 
 
 
 
 
51
  return text_gen.generate(
52
  tool_call["parameters"]["prompt"],
53
  tool_call["parameters"]["length"]
 
63
  )
64
 
65
  if __name__ == "__main__":
66
+ app.launch()