Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,28 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
17 |
arg2: the second argument
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
|
|
|
|
|
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -51,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[final_answer, DuckDuckGoSearchTool(),
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
17 |
arg2: the second argument
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
+
|
21 |
+
from diffusers import StableDiffusionPipeline
|
22 |
+
import torch
|
23 |
|
24 |
+
@tool
|
25 |
+
def generate_image(prompt: str) -> str:
|
26 |
+
"""Generates an image from a text prompt using Stable Diffusion.
|
27 |
+
Args:
|
28 |
+
prompt: The text prompt describing the image.
|
29 |
+
Returns:
|
30 |
+
The filename of the generated image.
|
31 |
+
"""
|
32 |
+
model_id = "runwayml/stable-diffusion-v1-5" # Change to another model if needed
|
33 |
+
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
34 |
+
pipeline.to("cuda") # Move model to GPU for faster generation
|
35 |
+
|
36 |
+
image = pipeline(prompt).images[0]
|
37 |
+
filename = "generated_image.png"
|
38 |
+
image.save(filename)
|
39 |
+
|
40 |
+
return filename # Returns the file path of the generated image
|
41 |
+
|
42 |
@tool
|
43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
44 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
72 |
|
73 |
agent = CodeAgent(
|
74 |
model=model,
|
75 |
+
tools=[final_answer, DuckDuckGoSearchTool(), generate_image, my_cutom_tool], ## add your tools here (don't remove final answer)
|
76 |
max_steps=6,
|
77 |
verbosity_level=1,
|
78 |
grammar=None,
|