Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,16 @@
|
|
1 |
import os
|
2 |
import requests
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
from audio_transcriber import AudioTranscriptionTool
|
5 |
from image_analyzer import ImageAnalysisTool
|
6 |
from wikipedia_searcher import WikipediaSearcher
|
7 |
-
from openai import OpenAI
|
8 |
-
from dotenv import load_dotenv
|
9 |
-
|
10 |
-
load_dotenv()
|
11 |
-
|
12 |
-
# Tools
|
13 |
-
audio_tool = AudioTranscriptionTool()
|
14 |
-
image_tool = ImageAnalysisTool()
|
15 |
-
wiki_tool = WikipediaSearcher()
|
16 |
|
17 |
-
# Static system prompt
|
18 |
-
|
19 |
-
return f"""You are an agent solving the GAIA benchmark and you are required to provide exact answers.
|
20 |
Rules to follow:
|
21 |
1. Return only the exact requested answer: no explanation and no reasoning.
|
22 |
2. For yes/no questions, return exactly "Yes" or "No".
|
@@ -30,52 +24,45 @@ Examples of good responses:
|
|
30 |
- "October 5, 2001"
|
31 |
- "Buenos Aires"
|
32 |
Never include phrases like "the answer is..." or "Based on my research".
|
33 |
-
Only return the exact answer.
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
class GAIAAgent:
|
41 |
def __init__(self):
|
42 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def __call__(self, task: dict) -> str:
|
45 |
question = task.get("question", "")
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
question += f"\n\nAttached Python file content:\n{code_text}"
|
62 |
-
except Exception as e:
|
63 |
-
return f"Error retrieving Python file: {e}"
|
64 |
-
|
65 |
-
# Wikipedia queries (if task type or instruction indicates)
|
66 |
-
if "wikipedia" in question.lower():
|
67 |
-
return wiki_tool.search(question)
|
68 |
-
|
69 |
-
# Build prompt
|
70 |
-
prompt = build_prompt(question)
|
71 |
-
|
72 |
-
# Run model
|
73 |
-
response = self.llm.chat.completions.create(
|
74 |
-
messages=[{"role": "system", "content": prompt}],
|
75 |
-
model="gpt-4-turbo"
|
76 |
-
)
|
77 |
-
|
78 |
-
return response.choices[0].message.content.strip()
|
79 |
|
80 |
|
81 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool
|
6 |
+
from smolagents.models import OpenAIServerModel
|
7 |
+
|
8 |
from audio_transcriber import AudioTranscriptionTool
|
9 |
from image_analyzer import ImageAnalysisTool
|
10 |
from wikipedia_searcher import WikipediaSearcher
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Static system prompt for all completions
|
13 |
+
SYSTEM_PROMPT = """You are an agent solving the GAIA benchmark and you are required to provide exact answers.
|
|
|
14 |
Rules to follow:
|
15 |
1. Return only the exact requested answer: no explanation and no reasoning.
|
16 |
2. For yes/no questions, return exactly "Yes" or "No".
|
|
|
24 |
- "October 5, 2001"
|
25 |
- "Buenos Aires"
|
26 |
Never include phrases like "the answer is..." or "Based on my research".
|
27 |
+
Only return the exact answer."""
|
28 |
|
29 |
+
class PatchedOpenAIServerModel(OpenAIServerModel):
|
30 |
+
def generate(self, messages, stop_sequences=None, **kwargs):
|
31 |
+
if isinstance(messages, list):
|
32 |
+
if not any(m["role"] == "system" for m in messages):
|
33 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}] + messages
|
34 |
+
return super().generate(messages=messages, stop_sequences=stop_sequences, **kwargs)
|
35 |
|
36 |
+
class MyAgent:
|
|
|
37 |
def __init__(self):
|
38 |
+
self.model = PatchedOpenAIServerModel(model_id="gpt-4-turbo")
|
39 |
+
self.agent = CodeAgent(
|
40 |
+
tools=[
|
41 |
+
DuckDuckGoSearchTool(),
|
42 |
+
WikipediaSearcher(),
|
43 |
+
AudioTranscriptionTool(),
|
44 |
+
ImageAnalysisTool()
|
45 |
+
],
|
46 |
+
model=self.model
|
47 |
+
)
|
48 |
|
49 |
def __call__(self, task: dict) -> str:
|
50 |
question = task.get("question", "")
|
51 |
+
attachment = task.get("attachment")
|
52 |
+
|
53 |
+
if attachment:
|
54 |
+
if attachment.endswith((".mp3", ".wav")):
|
55 |
+
question += f"\n\nAudio file: {attachment}"
|
56 |
+
elif attachment.endswith((".jpg", ".jpeg", ".png")):
|
57 |
+
question += f"\n\nImage file: {attachment}"
|
58 |
+
elif attachment.endswith(".py"):
|
59 |
+
try:
|
60 |
+
content = requests.get(attachment).text
|
61 |
+
question += f"\n\nPython code:\n{content}"
|
62 |
+
except Exception as e:
|
63 |
+
question += f"\n\nError loading code: {e}"
|
64 |
+
|
65 |
+
return self.agent.run(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|