Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
|
@@ -33,6 +35,16 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
search_tool = DuckDuckGoSearchTool()
|
|
@@ -47,9 +59,6 @@ model = HfApiModel(
|
|
| 47 |
custom_role_conversions=None,
|
| 48 |
)
|
| 49 |
|
| 50 |
-
# Import tool from Hub
|
| 51 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
-
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
|
|
@@ -60,7 +69,7 @@ agent = CodeAgent(
|
|
| 60 |
search_tool,
|
| 61 |
get_weather,
|
| 62 |
get_current_time_in_timezone,
|
| 63 |
-
|
| 64 |
],
|
| 65 |
max_steps=6,
|
| 66 |
verbosity_level=1,
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
from PIL import Image
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
+
@tool
|
| 39 |
+
def generate_image(prompt: str) -> Image.Image:
|
| 40 |
+
"""Generates an image from a text prompt using a text-to-image model.
|
| 41 |
+
Args:
|
| 42 |
+
prompt: A description of the image to generate.
|
| 43 |
+
"""
|
| 44 |
+
client = InferenceClient()
|
| 45 |
+
image = client.text_to_image(prompt, model="black-forest-labs/FLUX.1-schnell")
|
| 46 |
+
return image
|
| 47 |
+
|
| 48 |
|
| 49 |
final_answer = FinalAnswerTool()
|
| 50 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
| 59 |
custom_role_conversions=None,
|
| 60 |
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
with open("prompts.yaml", 'r') as stream:
|
| 63 |
prompt_templates = yaml.safe_load(stream)
|
| 64 |
|
|
|
|
| 69 |
search_tool,
|
| 70 |
get_weather,
|
| 71 |
get_current_time_in_timezone,
|
| 72 |
+
generate_image,
|
| 73 |
],
|
| 74 |
max_steps=6,
|
| 75 |
verbosity_level=1,
|