Spaces:
Sleeping
Sleeping
Update app.py to try to render the image
Browse files
app.py
CHANGED
|
@@ -5,12 +5,13 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from PIL import Image
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
-
def generate_image_by_description(image_description:str)->
|
| 14 |
"""A tool that generates an image based on the image_description variable
|
| 15 |
Args:
|
| 16 |
image_description: the description of the image to be generated
|
|
@@ -21,9 +22,17 @@ def generate_image_by_description(image_description:str)-> Image.Image: #it's im
|
|
| 21 |
|
| 22 |
image = image_generation_tool(image_description)
|
| 23 |
|
| 24 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
@tool
|
| 29 |
def display_image(image:Image.Image)-> None: #it's import to specify the return type
|
|
@@ -68,7 +77,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
-
tools=[final_answer, generate_image_by_description
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from PIL import Image
|
| 8 |
+
from io import BytesIO
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
+
def generate_image_by_description(image_description:str)-> BytesIO: #it's import to specify the return type
|
| 15 |
"""A tool that generates an image based on the image_description variable
|
| 16 |
Args:
|
| 17 |
image_description: the description of the image to be generated
|
|
|
|
| 22 |
|
| 23 |
image = image_generation_tool(image_description)
|
| 24 |
|
| 25 |
+
# Normalize
|
| 26 |
+
if isinstance(image, list):
|
| 27 |
+
image = image[0]
|
| 28 |
+
elif isinstance(image, dict) and "images" in image:
|
| 29 |
+
image = image["images"][0]
|
| 30 |
|
| 31 |
+
buffer = BytesIO()
|
| 32 |
+
image.save(buffer, format="PNG")
|
| 33 |
+
buffer.seek(0)
|
| 34 |
+
|
| 35 |
+
return buffer
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def display_image(image:Image.Image)-> None: #it's import to specify the return type
|
|
|
|
| 77 |
|
| 78 |
agent = CodeAgent(
|
| 79 |
model=model,
|
| 80 |
+
tools=[final_answer, generate_image_by_description], ## add your tools here (don't remove final answer)
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|
| 83 |
grammar=None,
|