gugukaka commited on
Commit
87ffcdd
·
verified ·
1 Parent(s): 63519e7

Update tools/final_answer.py

Browse files
Files changed (1) hide show
  1. tools/final_answer.py +10 -1
tools/final_answer.py CHANGED
@@ -8,7 +8,16 @@ class FinalAnswerTool(Tool):
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
 
8
  output_type = "any"
9
 
10
  def forward(self, answer: Any) -> Any:
11
+ from PIL import Image
12
+ import io
13
+
14
+ # If it's a PIL Image, convert to bytes so Gradio can render it
15
+ if isinstance(answer, Image.Image):
16
+ buf = io.BytesIO()
17
+ answer.save(buf, format="PNG")
18
+ buf.seek(0)
19
+ return buf.getvalue()
20
 
21
+ return answer
22
  def __init__(self, *args, **kwargs):
23
  self.is_initialized = False