Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
|
@@ -9,6 +12,9 @@ from io import BytesIO
|
|
| 9 |
from tools.final_answer import FinalAnswerTool
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
# Weather Tool (using wttr.in API, no API key needed)
|
| 13 |
@tool
|
| 14 |
def get_weather(city: str) -> str:
|
|
@@ -50,7 +56,10 @@ def generate_image(prompt: str) -> str:
|
|
| 50 |
Args:
|
| 51 |
prompt: A description of the image to generate.
|
| 52 |
"""
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Timezone Tool (already in your code)
|
| 56 |
@tool
|
|
|
|
| 1 |
+
import micropip
|
| 2 |
+
await micropip.install(["smolagents", "requests", "pytz", "pyyaml", "beautifulsoup4", "pillow"])
|
| 3 |
+
|
| 4 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 5 |
import datetime
|
| 6 |
import requests
|
|
|
|
| 12 |
from tools.final_answer import FinalAnswerTool
|
| 13 |
from Gradio_UI import GradioUI
|
| 14 |
|
| 15 |
+
# Load image generation tool
|
| 16 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 17 |
+
|
| 18 |
# Weather Tool (using wttr.in API, no API key needed)
|
| 19 |
@tool
|
| 20 |
def get_weather(city: str) -> str:
|
|
|
|
| 56 |
Args:
|
| 57 |
prompt: A description of the image to generate.
|
| 58 |
"""
|
| 59 |
+
try:
|
| 60 |
+
return image_generation_tool.run(prompt)
|
| 61 |
+
except Exception as e:
|
| 62 |
+
return f"Error generating image: {str(e)}"
|
| 63 |
|
| 64 |
# Timezone Tool (already in your code)
|
| 65 |
@tool
|