Spaces:
Sleeping
Sleeping
2nd try with the image generation tool
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -32,7 +33,19 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +68,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
+
from tool import TextToImageTool
|
| 3 |
import datetime
|
| 4 |
import requests
|
| 5 |
import pytz
|
|
|
|
| 33 |
return f"The current local time in {timezone} is: {local_time}"
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
+
def image_generation_tool(text: str) -> str:
|
| 37 |
+
"""A tool that fetches generates an image from a text
|
| 38 |
+
Args:
|
| 39 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 40 |
+
"""
|
| 41 |
+
try:
|
| 42 |
+
# Create timezone object
|
| 43 |
+
image_generation_tool_obj = image_generation_tool.
|
| 44 |
+
# Get current time in that timezone
|
| 45 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 46 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 49 |
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
|
|
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
+
tools=[TextToImageTool,final_answer], ## add your tools here (don't remove final answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|