Spaces:
Sleeping
Sleeping
added the custom tool
Browse files
app.py
CHANGED
|
@@ -9,14 +9,49 @@ 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(
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(current_time: int) -> str:
|
| 13 |
+
"""
|
| 14 |
+
A tool that checks how many minutes ago the latest eruption
|
| 15 |
+
of Old Faithful occurred using the GeyserTimes API.
|
| 16 |
+
|
| 17 |
Args:
|
| 18 |
+
current_time: current Unix epoch time (seconds)
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
Human-readable string with elapsed minutes.
|
| 22 |
"""
|
| 23 |
+
|
| 24 |
+
url = "https://www.geysertimes.org/api/v5/entries_latest/old+faithful?iso=1"
|
| 25 |
+
|
| 26 |
+
response = requests.get(url, timeout=10)
|
| 27 |
+
data = response.json()
|
| 28 |
+
|
| 29 |
+
if not data or "entries" not in data or not data["entries"]:
|
| 30 |
+
raise Exception("Problem retrieving eruption data")
|
| 31 |
+
|
| 32 |
+
first_entry = data["entries"][0]
|
| 33 |
+
|
| 34 |
+
eruption_time_str = first_entry.get("time")
|
| 35 |
+
|
| 36 |
+
if eruption_time_str is None:
|
| 37 |
+
raise Exception("No eruption time found")
|
| 38 |
+
|
| 39 |
+
# Parse API ISO datetime
|
| 40 |
+
eruption_dt = datetime.datetime.fromisoformat(eruption_time_str)
|
| 41 |
+
|
| 42 |
+
# Ensure timezone-aware
|
| 43 |
+
if eruption_dt.tzinfo is None:
|
| 44 |
+
eruption_dt = pytz.UTC.localize(eruption_dt)
|
| 45 |
+
|
| 46 |
+
# Convert current_time into datetime
|
| 47 |
+
current_dt = datetime.datetime.fromtimestamp(current_time, tz=pytz.UTC)
|
| 48 |
+
|
| 49 |
+
# Difference
|
| 50 |
+
delta = current_dt - eruption_dt
|
| 51 |
+
|
| 52 |
+
minutes_ago = int(delta.total_seconds() // 60)
|
| 53 |
+
|
| 54 |
+
return f"Old Faithful last erupted {minutes_ago} minutes ago."
|
| 55 |
|
| 56 |
@tool
|
| 57 |
def get_current_time_in_timezone(timezone: str) -> str:
|