Spaces:
Runtime error
Runtime error
Commit ·
6584782
1
Parent(s): 5755fef
🚧 Move GaiaAgent to a module
Browse files- app.py +1 -55
- gaiaagent.py +43 -0
app.py
CHANGED
|
@@ -3,11 +3,8 @@ import os
|
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import requests
|
|
|
|
| 6 |
from smolagents import (
|
| 7 |
-
CodeAgent,
|
| 8 |
-
Tool,
|
| 9 |
-
Model,
|
| 10 |
-
PromptTemplates,
|
| 11 |
FinalAnswerTool,
|
| 12 |
HfApiModel,
|
| 13 |
DuckDuckGoSearchTool,
|
|
@@ -33,57 +30,6 @@ model = HfApiModel(
|
|
| 33 |
)
|
| 34 |
|
| 35 |
|
| 36 |
-
class GaiaAgent(CodeAgent):
|
| 37 |
-
def __init__(
|
| 38 |
-
self,
|
| 39 |
-
api_url: str,
|
| 40 |
-
tools: list[Tool],
|
| 41 |
-
model: Model,
|
| 42 |
-
prompt_templates: PromptTemplates | None = None,
|
| 43 |
-
additional_authorized_imports: list[str] | None = None,
|
| 44 |
-
planning_interval: int | None = None,
|
| 45 |
-
executor_type: str | None = "local",
|
| 46 |
-
executor_kwargs: dict[str, Any] | None = None,
|
| 47 |
-
max_print_outputs_length: int | None = None,
|
| 48 |
-
stream_outputs: bool = False,
|
| 49 |
-
use_structured_outputs_internally: bool = False,
|
| 50 |
-
grammar: dict[str, str] | None = None,
|
| 51 |
-
**kwargs,
|
| 52 |
-
):
|
| 53 |
-
super().__init__(
|
| 54 |
-
tools=tools,
|
| 55 |
-
model=model,
|
| 56 |
-
prompt_templates=prompt_templates,
|
| 57 |
-
additional_authorized_imports=additional_authorized_imports,
|
| 58 |
-
planning_interval=planning_interval,
|
| 59 |
-
executor_type=executor_type,
|
| 60 |
-
executor_kwargs=executor_kwargs,
|
| 61 |
-
max_print_outputs_length=max_print_outputs_length,
|
| 62 |
-
use_structured_outputs_internally=use_structured_outputs_internally,
|
| 63 |
-
grammar=grammar,
|
| 64 |
-
**kwargs,
|
| 65 |
-
)
|
| 66 |
-
self._files_base_url = f"{api_url}/files"
|
| 67 |
-
|
| 68 |
-
def __call__(self, item: dict) -> str:
|
| 69 |
-
question = item["question"]
|
| 70 |
-
task_id = item["task_id"]
|
| 71 |
-
file_name = item["file_name"]
|
| 72 |
-
if file_name:
|
| 73 |
-
url = f"{self._files_base_url}/{task_id}"
|
| 74 |
-
resp = requests.get(url, timeout=30)
|
| 75 |
-
resp.raise_for_status()
|
| 76 |
-
content = resp.content
|
| 77 |
-
return super().run(
|
| 78 |
-
question,
|
| 79 |
-
additional_args={
|
| 80 |
-
"file_content": content,
|
| 81 |
-
"file_name": file_name,
|
| 82 |
-
},
|
| 83 |
-
)
|
| 84 |
-
return super().run(question)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 88 |
"""
|
| 89 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import requests
|
| 6 |
+
from gaiaagent import GaiaAgent
|
| 7 |
from smolagents import (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
FinalAnswerTool,
|
| 9 |
HfApiModel,
|
| 10 |
DuckDuckGoSearchTool,
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 34 |
"""
|
| 35 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
gaiaagent.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
from smolagents import CodeAgent, PromptTemplates, Model, Tool
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class GaiaAgent(CodeAgent):
|
| 6 |
+
def __init__(
|
| 7 |
+
self,
|
| 8 |
+
tools: list[Tool],
|
| 9 |
+
model: Model,
|
| 10 |
+
prompt_templates: PromptTemplates | None = None,
|
| 11 |
+
additional_authorized_imports: list[str] | None = None,
|
| 12 |
+
planning_interval: int | None = None,
|
| 13 |
+
executor_type: str | None = "local",
|
| 14 |
+
executor_kwargs: dict[str, Any] | None = None,
|
| 15 |
+
max_print_outputs_length: int | None = None,
|
| 16 |
+
stream_outputs: bool = False,
|
| 17 |
+
use_structured_outputs_internally: bool = False,
|
| 18 |
+
grammar: dict[str, str] | None = None,
|
| 19 |
+
**kwargs,
|
| 20 |
+
):
|
| 21 |
+
super().__init__(
|
| 22 |
+
tools=tools,
|
| 23 |
+
model=model,
|
| 24 |
+
prompt_templates=prompt_templates,
|
| 25 |
+
additional_authorized_imports=additional_authorized_imports,
|
| 26 |
+
planning_interval=planning_interval,
|
| 27 |
+
executor_type=executor_type,
|
| 28 |
+
executor_kwargs=executor_kwargs,
|
| 29 |
+
max_print_outputs_length=max_print_outputs_length,
|
| 30 |
+
use_structured_outputs_internally=use_structured_outputs_internally,
|
| 31 |
+
grammar=grammar,
|
| 32 |
+
**kwargs,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
def __call__(self, question: str, filename: str) -> str:
|
| 36 |
+
if filename:
|
| 37 |
+
return super().run(
|
| 38 |
+
question,
|
| 39 |
+
additional_args={
|
| 40 |
+
"filename": filename,
|
| 41 |
+
},
|
| 42 |
+
)
|
| 43 |
+
return super().run(question)
|