Vinsmart06 commited on
Commit
9eae9e0
·
verified ·
1 Parent(s): eeb51ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -21
app.py CHANGED
@@ -46,7 +46,30 @@ def read_audio(file_path):
46
  return f"Audio length: {len(audio)} ms"
47
  except:
48
  return "Audio read error"
 
 
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  def read_youtube(url):
52
  try:
@@ -61,7 +84,68 @@ def read_youtube(url):
61
  from openai import OpenAI
62
 
63
  class BasicAgent:
64
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  def __init__(self):
66
  print("🚀 Super GAIA Agent initialized")
67
  self.client = OpenAI()
@@ -325,27 +409,13 @@ Return only the answer.
325
  # ------------------------------------------------
326
 
327
  def __call__(self, question, file_url=None):
328
-
329
  print("Question:", question)
330
-
331
- math = self.calculator(question)
332
-
333
- if math:
334
- print("Math used:", math)
335
- return math
336
-
337
- file_content = self.load_file(file_url)
338
-
339
- reasoning = self.reason(question, file_content)
340
-
341
- print("Reasoning:", reasoning)
342
-
343
- answer = self.extract(reasoning)
344
-
345
- answer = self.clean(answer)
346
-
347
- print("Final Answer:", answer)
348
-
349
  return answer
350
 
351
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
46
  return f"Audio length: {len(audio)} ms"
47
  except:
48
  return "Audio read error"
49
+
50
+ def execute_tool(self, tool, input_data, file_url):
51
 
52
+ if tool == "read_excel":
53
+
54
+ return self.read_excel(self.download_file(file_url))
55
+
56
+ if tool == "read_image":
57
+
58
+ return self.read_image(self.download_file(file_url))
59
+
60
+ if tool == "scrape_page":
61
+
62
+ return self.scrape_page(input_data)
63
+
64
+ if tool == "calculator":
65
+
66
+ return str(eval(input_data, {"__builtins__": {}}))
67
+
68
+ if tool == "wiki_search":
69
+
70
+ return self.wiki_search(input_data)
71
+
72
+ return "Unknown tool"
73
 
74
  def read_youtube(url):
75
  try:
 
84
  from openai import OpenAI
85
 
86
  class BasicAgent:
87
+ def agent_loop(self, question, file_url):
88
+
89
+ memory = ""
90
+
91
+ for step in range(5):
92
+
93
+ prompt = f"""
94
+ You are a GAIA solving agent.
95
+
96
+ Available tools:
97
+
98
+ 1. read_excel
99
+ 2. read_image
100
+ 3. scrape_page
101
+ 4. calculator
102
+ 5. wiki_search
103
+
104
+ Question:
105
+ {question}
106
+
107
+ Previous steps:
108
+ {memory}
109
+
110
+ Decide next action.
111
+
112
+ Format:
113
+
114
+ TOOL: tool_name
115
+ INPUT: tool_input
116
+
117
+ OR
118
+
119
+ FINAL: answer
120
+ """
121
+
122
+ response = self.client.chat.completions.create(
123
+ model="gpt-4o-mini",
124
+ temperature=0,
125
+ messages=[{"role": "user", "content": prompt}]
126
+ )
127
+
128
+ action = response.choices[0].message.content
129
+
130
+ print("Agent step:", action)
131
+
132
+ # FINAL ANSWER
133
+ if "FINAL:" in action:
134
+
135
+ return action.split("FINAL:")[-1].strip()
136
+
137
+ # TOOL CALL
138
+ if "TOOL:" in action:
139
+
140
+ tool = action.split("TOOL:")[1].split("\n")[0].strip()
141
+
142
+ input_data = action.split("INPUT:")[-1].strip()
143
+
144
+ result = self.execute_tool(tool, input_data, file_url)
145
+
146
+ memory += f"\nTool {tool} result:\n{result}\n"
147
+
148
+ return "No answer found"
149
  def __init__(self):
150
  print("🚀 Super GAIA Agent initialized")
151
  self.client = OpenAI()
 
409
  # ------------------------------------------------
410
 
411
  def __call__(self, question, file_url=None):
412
+
413
  print("Question:", question)
414
+
415
+ answer = self.agent_loop(question, file_url)
416
+
417
+ print("Final:", answer)
418
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  return answer
420
 
421
  def run_and_submit_all( profile: gr.OAuthProfile | None):