Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from smolagents import (
|
|
| 5 |
DuckDuckGoSearchTool,
|
| 6 |
load_tool,
|
| 7 |
tool,
|
| 8 |
-
HfApiModel, #
|
| 9 |
)
|
| 10 |
import datetime
|
| 11 |
import re
|
|
@@ -20,12 +20,18 @@ from Gradio_UI import GradioUI
|
|
| 20 |
|
| 21 |
# ---- Custom Tools ----
|
| 22 |
|
| 23 |
-
|
| 24 |
@tool
|
| 25 |
def get_current_time_in_timezone(
|
| 26 |
timezone: Annotated[str, "IANA timezone like 'America/Los_Angeles'"]
|
| 27 |
) -> str:
|
| 28 |
-
"""Return the current local time for the given timezone.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
try:
|
| 30 |
tz = pytz.timezone(timezone)
|
| 31 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
|
@@ -38,7 +44,14 @@ def get_current_time_in_timezone(
|
|
| 38 |
def fetch_page_title(
|
| 39 |
url: Annotated[str, "An http/https URL to fetch"]
|
| 40 |
) -> str:
|
| 41 |
-
"""Fetch the page and return its <title> text.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
try:
|
| 43 |
resp = requests.get(url, timeout=10)
|
| 44 |
resp.raise_for_status()
|
|
@@ -53,12 +66,18 @@ def fetch_page_title(
|
|
| 53 |
def echo_and_length(
|
| 54 |
text: Annotated[str, "Any text to echo back"]
|
| 55 |
) -> str:
|
| 56 |
-
"""Echo the text and report its character length.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
t = text.strip()
|
| 58 |
return f"Echo: {t}\nLength: {len(t)}"
|
| 59 |
|
| 60 |
|
| 61 |
-
|
| 62 |
# ---- Model & Tools wiring ----
|
| 63 |
|
| 64 |
final_answer = FinalAnswerTool()
|
|
@@ -89,7 +108,7 @@ agent = CodeAgent(
|
|
| 89 |
verbosity_level=1,
|
| 90 |
grammar=None,
|
| 91 |
planning_interval=None,
|
| 92 |
-
name="my_first_smolagents_agent",
|
| 93 |
description="A tiny agent that can search, fetch titles, tell time, and generate images.",
|
| 94 |
prompt_templates=prompt_templates,
|
| 95 |
)
|
|
|
|
| 5 |
DuckDuckGoSearchTool,
|
| 6 |
load_tool,
|
| 7 |
tool,
|
| 8 |
+
HfApiModel, # replacement for InferenceClientModel
|
| 9 |
)
|
| 10 |
import datetime
|
| 11 |
import re
|
|
|
|
| 20 |
|
| 21 |
# ---- Custom Tools ----
|
| 22 |
|
|
|
|
| 23 |
@tool
|
| 24 |
def get_current_time_in_timezone(
|
| 25 |
timezone: Annotated[str, "IANA timezone like 'America/Los_Angeles'"]
|
| 26 |
) -> str:
|
| 27 |
+
"""Return the current local time for the given timezone.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
timezone (str): IANA timezone name, e.g., 'America/Los_Angeles' or 'Asia/Tokyo'.
|
| 31 |
+
|
| 32 |
+
Returns:
|
| 33 |
+
str: A human-readable string with the local time in the requested timezone.
|
| 34 |
+
"""
|
| 35 |
try:
|
| 36 |
tz = pytz.timezone(timezone)
|
| 37 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
| 44 |
def fetch_page_title(
|
| 45 |
url: Annotated[str, "An http/https URL to fetch"]
|
| 46 |
) -> str:
|
| 47 |
+
"""Fetch the page and return its <title> text.
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
url (str): A valid HTTP/HTTPS URL to retrieve.
|
| 51 |
+
|
| 52 |
+
Returns:
|
| 53 |
+
str: The page title, or an error message if fetching/parsing fails.
|
| 54 |
+
"""
|
| 55 |
try:
|
| 56 |
resp = requests.get(url, timeout=10)
|
| 57 |
resp.raise_for_status()
|
|
|
|
| 66 |
def echo_and_length(
|
| 67 |
text: Annotated[str, "Any text to echo back"]
|
| 68 |
) -> str:
|
| 69 |
+
"""Echo the text and report its character length.
|
| 70 |
+
|
| 71 |
+
Args:
|
| 72 |
+
text (str): The text to echo back.
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
str: The echoed text and its character count.
|
| 76 |
+
"""
|
| 77 |
t = text.strip()
|
| 78 |
return f"Echo: {t}\nLength: {len(t)}"
|
| 79 |
|
| 80 |
|
|
|
|
| 81 |
# ---- Model & Tools wiring ----
|
| 82 |
|
| 83 |
final_answer = FinalAnswerTool()
|
|
|
|
| 108 |
verbosity_level=1,
|
| 109 |
grammar=None,
|
| 110 |
planning_interval=None,
|
| 111 |
+
name="my_first_smolagents_agent",
|
| 112 |
description="A tiny agent that can search, fetch titles, tell time, and generate images.",
|
| 113 |
prompt_templates=prompt_templates,
|
| 114 |
)
|