Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,6 +29,35 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 29 |
return f"Image generated successfully: {result}"
|
| 30 |
except Exception as e:
|
| 31 |
return f"Failed to generate image from prompt '{arg1}': {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
@tool
|
| 34 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 29 |
return f"Image generated successfully: {result}"
|
| 30 |
except Exception as e:
|
| 31 |
return f"Failed to generate image from prompt '{arg1}': {str(e)}"
|
| 32 |
+
from smolagents import tool
|
| 33 |
+
|
| 34 |
+
# Assuming this is already loaded earlier
|
| 35 |
+
# image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 36 |
+
|
| 37 |
+
@tool
|
| 38 |
+
def image_generator(arg1: str) -> str:
|
| 39 |
+
"""
|
| 40 |
+
A tool that generates an image based on a text prompt.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
arg1: A description or prompt for the image to be generated.
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
A string containing the result or URL of the generated image.
|
| 47 |
+
"""
|
| 48 |
+
try:
|
| 49 |
+
result = image_generation_tool(prompt=arg1)
|
| 50 |
+
|
| 51 |
+
# Handle different possible return types from the tool
|
| 52 |
+
if isinstance(result, str):
|
| 53 |
+
return f"Generated image: {result}"
|
| 54 |
+
elif isinstance(result, dict) and "image_url" in result:
|
| 55 |
+
return f"Generated image URL: {result['image_url']}"
|
| 56 |
+
else:
|
| 57 |
+
return f"Image generated successfully: {result}"
|
| 58 |
+
except Exception as e:
|
| 59 |
+
return f"Error generating image from prompt '{arg1}': {str(e)}"
|
| 60 |
+
|
| 61 |
|
| 62 |
@tool
|
| 63 |
def get_current_time_in_timezone(timezone: str) -> str:
|