Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import datetime
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
import uuid
|
|
|
|
| 6 |
|
| 7 |
from smolagents.agent_types import AgentImage
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
|
@@ -10,13 +11,16 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
|
| 12 |
@tool
|
| 13 |
-
def
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@tool
|
|
@@ -41,21 +45,6 @@ model = HfApiModel(
|
|
| 41 |
custom_role_conversions=None,
|
| 42 |
)
|
| 43 |
|
| 44 |
-
# Load the low-level image tool (keep this private)
|
| 45 |
-
_image_generator = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 46 |
-
|
| 47 |
-
# Expose a UI-friendly wrapper tool that returns AgentImage
|
| 48 |
-
@tool
|
| 49 |
-
def generate_image(prompt: str) -> AgentImage:
|
| 50 |
-
"""Generate an image from a text prompt and return it as an AgentImage for Gradio rendering.
|
| 51 |
-
Args:
|
| 52 |
-
prompt: The text description of the image to generate.
|
| 53 |
-
"""
|
| 54 |
-
pil_img = _image_generator(prompt=prompt) # PIL image
|
| 55 |
-
return AgentImage(pil_img) # ✅ wrap the PIL object, not a filepath
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
|
| 61 |
with open("prompts.yaml", "r") as stream:
|
|
@@ -65,9 +54,8 @@ agent = CodeAgent(
|
|
| 65 |
model=model,
|
| 66 |
tools=[
|
| 67 |
final_answer,
|
| 68 |
-
|
| 69 |
get_current_time_in_timezone,
|
| 70 |
-
my_custom_tool,
|
| 71 |
],
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
import uuid
|
| 6 |
+
import urllib.parse
|
| 7 |
|
| 8 |
from smolagents.agent_types import AgentImage
|
| 9 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
@tool
|
| 14 |
+
def wikipedia_url(query: str) -> str:
|
| 15 |
+
"""A tool that provides the URL to the wikipedia article for a query.
|
| 16 |
Args:
|
| 17 |
+
query: Topic to search on Wikipedia.
|
|
|
|
| 18 |
"""
|
| 19 |
+
try:
|
| 20 |
+
q = query.strip()
|
| 21 |
+
if not q:
|
| 22 |
+
return "Please provide a non-empty query."
|
| 23 |
+
return "https://en.wikipedia.org/wiki/Special:Search?search=" + urllib.parse.quote(q)
|
| 24 |
|
| 25 |
|
| 26 |
@tool
|
|
|
|
| 45 |
custom_role_conversions=None,
|
| 46 |
)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
final_answer = FinalAnswerTool()
|
| 49 |
|
| 50 |
with open("prompts.yaml", "r") as stream:
|
|
|
|
| 54 |
model=model,
|
| 55 |
tools=[
|
| 56 |
final_answer,
|
| 57 |
+
wikipedia_url,
|
| 58 |
get_current_time_in_timezone,
|
|
|
|
| 59 |
],
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|