Zanqi commited on
Commit
04da702
·
1 Parent(s): 57125e8

Revert "Add image handling in FinalAnswerTool to support saving and validating AgentImage instances"

Browse files

This reverts commit c495e4a6ed50bb0bd0714c597e9df74fbb5df094.

Files changed (2) hide show
  1. requirements.txt +1 -1
  2. tools/final_answer.py +1 -22
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  markdownify
2
- smolagents
3
  requests
4
  ddgs
5
  pandas
 
1
  markdownify
2
+ smolagents==1.13.0
3
  requests
4
  ddgs
5
  pandas
tools/final_answer.py CHANGED
@@ -1,7 +1,5 @@
1
- from typing import Any
2
  from smolagents.tools import Tool
3
- from smolagents.agent_types import AgentImage
4
- import tempfile
5
 
6
  class FinalAnswerTool(Tool):
7
  name = "final_answer"
@@ -10,26 +8,7 @@ class FinalAnswerTool(Tool):
10
  output_type = "any"
11
 
12
  def forward(self, answer: Any) -> Any:
13
- # Handle PIL Images by converting them to AgentImage with saved file
14
- if hasattr(answer, 'save') and hasattr(answer, 'mode'): # PIL Image
15
- # Create a temporary file to save the image
16
- with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:
17
- answer.save(tmp_file.name, format='PNG')
18
- # Create AgentImage from the saved file
19
- return AgentImage(tmp_file.name)
20
-
21
- # If it's already an AgentImage, ensure it has valid data
22
- if isinstance(answer, AgentImage):
23
- # If the AgentImage doesn't have a valid path, try to save it
24
- if not hasattr(answer, '_path') or not answer._path:
25
- if hasattr(answer, '_value') and answer._value is not None:
26
- with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:
27
- answer._value.save(tmp_file.name, format='PNG')
28
- answer._path = tmp_file.name
29
- return answer
30
-
31
  return answer
32
 
33
  def __init__(self, *args, **kwargs):
34
- super().__init__(*args, **kwargs)
35
  self.is_initialized = False
 
1
+ from typing import Any, Optional
2
  from smolagents.tools import Tool
 
 
3
 
4
  class FinalAnswerTool(Tool):
5
  name = "final_answer"
 
8
  output_type = "any"
9
 
10
  def forward(self, answer: Any) -> Any:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  return answer
12
 
13
  def __init__(self, *args, **kwargs):
 
14
  self.is_initialized = False