Spaces:
Sleeping
Sleeping
Added avatar facebook tool
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -7,16 +7,34 @@ 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
|
| 13 |
-
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -47,9 +65,6 @@ custom_role_conversions=None,
|
|
| 47 |
)
|
| 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 |
|
|
|
|
| 1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, AgentImage
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Import tool from Hub
|
| 11 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
+
def make_facebook_avatar(request: str)-> AgentImage:
|
| 17 |
+
|
| 18 |
+
"""A tool that make a facebook avatar in the size of 1024 * 1024 based on a prompt, which is a text description
|
| 19 |
Args:
|
| 20 |
+
request: the request of user, in string
|
|
|
|
| 21 |
"""
|
| 22 |
+
try:
|
| 23 |
+
# Import tool from Hub
|
| 24 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 25 |
+
|
| 26 |
+
# Enhance the prompt to specify the desired image size
|
| 27 |
+
prompt = f"{request}, optimized for a 1024x1024 Facebook avatar"
|
| 28 |
+
|
| 29 |
+
# generate the avatar
|
| 30 |
+
generated_image = image_generation_tool(prompt)
|
| 31 |
+
|
| 32 |
+
if isinstance(generated_image, Image.Image):
|
| 33 |
+
return AgentImage(generated_image)
|
| 34 |
+
|
| 35 |
+
except:
|
| 36 |
+
raise ValueError("Cannot generate image as you want")
|
| 37 |
+
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
with open("prompts.yaml", 'r') as stream:
|
| 69 |
prompt_templates = yaml.safe_load(stream)
|
| 70 |
|