Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,8 @@ from smolagents import tool
|
|
| 36 |
# Import tool from Hub
|
| 37 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 38 |
@tool
|
| 39 |
-
|
|
|
|
| 40 |
"""
|
| 41 |
A tool that generates an image based on a text prompt.
|
| 42 |
|
|
@@ -44,20 +45,23 @@ def image_generator(arg1: str) -> str:
|
|
| 44 |
arg1: A description or prompt for the image to be generated.
|
| 45 |
|
| 46 |
Returns:
|
| 47 |
-
A
|
| 48 |
"""
|
| 49 |
try:
|
| 50 |
result = image_generation_tool(prompt=arg1)
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
if
|
| 54 |
-
return
|
|
|
|
|
|
|
| 55 |
elif isinstance(result, dict) and "image_url" in result:
|
| 56 |
return f"Generated image URL: {result['image_url']}"
|
| 57 |
else:
|
| 58 |
-
return f"Image generated
|
| 59 |
except Exception as e:
|
| 60 |
-
return f"Error generating image
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
@tool
|
|
|
|
| 36 |
# Import tool from Hub
|
| 37 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 38 |
@tool
|
| 39 |
+
@tool
|
| 40 |
+
def image_generator(arg1: str):
|
| 41 |
"""
|
| 42 |
A tool that generates an image based on a text prompt.
|
| 43 |
|
|
|
|
| 45 |
arg1: A description or prompt for the image to be generated.
|
| 46 |
|
| 47 |
Returns:
|
| 48 |
+
A PIL.Image object which Gradio can display.
|
| 49 |
"""
|
| 50 |
try:
|
| 51 |
result = image_generation_tool(prompt=arg1)
|
| 52 |
|
| 53 |
+
# If result is a PIL image, return it directly
|
| 54 |
+
if hasattr(result, 'show') and callable(result.show):
|
| 55 |
+
return result # Gradio will display this automatically
|
| 56 |
+
elif isinstance(result, str):
|
| 57 |
+
return f"Generated image URL: {result}"
|
| 58 |
elif isinstance(result, dict) and "image_url" in result:
|
| 59 |
return f"Generated image URL: {result['image_url']}"
|
| 60 |
else:
|
| 61 |
+
return f"Image generated: {result}"
|
| 62 |
except Exception as e:
|
| 63 |
+
return f"Error generating image: {str(e)}"
|
| 64 |
+
|
| 65 |
|
| 66 |
|
| 67 |
@tool
|