Spaces:
Sleeping
Sleeping
Zanqi commited on
Commit ·
04da702
1
Parent(s): 57125e8
Revert "Add image handling in FinalAnswerTool to support saving and validating AgentImage instances"
Browse filesThis reverts commit c495e4a6ed50bb0bd0714c597e9df74fbb5df094.
Files changed (2)
12345markdownifysmolagentsrequestsddgspandas12345markdownifysmolagents==1.13.0requestsddgspandas
12345672 unmodified lines1011121314151617181920212223242526272829303132333435from typing import Anyfrom smolagents.tools import Toolfrom smolagents.agent_types import AgentImageimport tempfileclass FinalAnswerTool(Tool):name = "final_answer"2 unmodified linesoutput_type = "any"def forward(self, answer: Any) -> Any:# Handle PIL Images by converting them to AgentImage with saved fileif hasattr(answer, 'save') and hasattr(answer, 'mode'): # PIL Image# Create a temporary file to save the imagewith tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:answer.save(tmp_file.name, format='PNG')# Create AgentImage from the saved filereturn AgentImage(tmp_file.name)# If it's already an AgentImage, ensure it has valid dataif isinstance(answer, AgentImage):# If the AgentImage doesn't have a valid path, try to save itif not hasattr(answer, '_path') or not answer._path:if hasattr(answer, '_value') and answer._value is not None:with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:answer._value.save(tmp_file.name, format='PNG')answer._path = tmp_file.namereturn answerreturn answerdef __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)self.is_initialized = False123452 unmodified lines891011121314from typing import Any, Optionalfrom smolagents.tools import Toolclass FinalAnswerTool(Tool):name = "final_answer"2 unmodified linesoutput_type = "any"def forward(self, answer: Any) -> Any:return answerdef __init__(self, *args, **kwargs):self.is_initialized = False
requirements.txt+1-1
tools/final_answer.py+1-22