Update app.py
Browse filesImplemented image_generator tool.
app.py
CHANGED
|
@@ -7,6 +7,9 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -33,6 +36,24 @@ 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 |
|
|
@@ -43,8 +64,8 @@ model = HfApiModel(
|
|
| 43 |
max_tokens=2096,
|
| 44 |
temperature=0.5,
|
| 45 |
#model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 46 |
-
|
| 47 |
-
model_id='bk1832004/an-image-generator',
|
| 48 |
custom_role_conversions=None,
|
| 49 |
)
|
| 50 |
|
|
@@ -57,7 +78,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 57 |
|
| 58 |
agent = CodeAgent(
|
| 59 |
model=model,
|
| 60 |
-
tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 61 |
max_steps=6,
|
| 62 |
verbosity_level=1,
|
| 63 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from diffusers import StableDiffusionPipeline
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
| 15 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
|
| 39 |
+
@tool
|
| 40 |
+
def image_generator(prompt: str, model_id="runwayml/stable-diffusion-v1-5", image_path="generated_image.png"):
|
| 41 |
+
"""A tool that generates an image.
|
| 42 |
+
Args:
|
| 43 |
+
prompt: A string representing a description if the image.
|
| 44 |
+
"""
|
| 45 |
+
# Load the Stable Diffusion model
|
| 46 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
| 47 |
+
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 48 |
+
|
| 49 |
+
# Generate the image
|
| 50 |
+
image = pipe(prompt).images[0]
|
| 51 |
+
|
| 52 |
+
return image
|
| 53 |
+
# Save the image
|
| 54 |
+
#image.save(image_path)
|
| 55 |
+
#return image_path # Returns the path to the generated image
|
| 56 |
+
|
| 57 |
|
| 58 |
final_answer = FinalAnswerTool()
|
| 59 |
|
|
|
|
| 64 |
max_tokens=2096,
|
| 65 |
temperature=0.5,
|
| 66 |
#model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 67 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud', # this works
|
| 68 |
+
#model_id='bk1832004/an-image-generator', #doesn't work or too slow
|
| 69 |
custom_role_conversions=None,
|
| 70 |
)
|
| 71 |
|
|
|
|
| 78 |
|
| 79 |
agent = CodeAgent(
|
| 80 |
model=model,
|
| 81 |
+
tools=[final_answer, get_current_time_in_timezone, image_generator], ## add your tools here (don't remove final answer)
|
| 82 |
max_steps=6,
|
| 83 |
verbosity_level=1,
|
| 84 |
grammar=None,
|