Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
|
| 2 |
import datetime
|
| 3 |
import os
|
| 4 |
import io
|
|
@@ -11,6 +12,16 @@ from tools.final_answer import FinalAnswerTool
|
|
| 11 |
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
def my_custom_tool(text:str, size:int = 200)-> str: #it's import to specify the return type
|
|
@@ -73,7 +84,13 @@ custom_role_conversions=None,
|
|
| 73 |
|
| 74 |
|
| 75 |
# Import tool from Hub
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
search_tool = DuckDuckGoSearchTool()
|
| 79 |
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
+
from PIL import Image
|
| 3 |
import datetime
|
| 4 |
import os
|
| 5 |
import io
|
|
|
|
| 12 |
|
| 13 |
from Gradio_UI import GradioUI
|
| 14 |
|
| 15 |
+
def image_path_to_markdown(path: str) -> str:
|
| 16 |
+
try:
|
| 17 |
+
with open(path, "rb") as f:
|
| 18 |
+
img_bytes = f.read()
|
| 19 |
+
img_base64 = base64.b64encode(img_bytes).decode("utf-8")
|
| 20 |
+
return f""
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Image saved at: {path} (Failed to embed image: {str(e)})"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 26 |
@tool
|
| 27 |
def my_custom_tool(text:str, size:int = 200)-> str: #it's import to specify the return type
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
# Import tool from Hub
|
| 87 |
+
original_image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 88 |
+
|
| 89 |
+
@tool
|
| 90 |
+
def image_generation_tool(prompt: str) -> str:
|
| 91 |
+
"""Generates an image from a prompt and embeds it as base64 in markdown."""
|
| 92 |
+
path = original_image_generation_tool(prompt)
|
| 93 |
+
return image_path_to_markdown(path)
|
| 94 |
|
| 95 |
search_tool = DuckDuckGoSearchTool()
|
| 96 |
|