Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,51 +19,22 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
-
def
|
| 23 |
-
"""A tool that
|
| 24 |
|
| 25 |
Args:
|
| 26 |
-
|
| 27 |
-
|
| 28 |
Returns:
|
| 29 |
-
str:
|
| 30 |
"""
|
| 31 |
-
import
|
| 32 |
-
|
| 33 |
try:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
"q": query,
|
| 37 |
-
"format": "json",
|
| 38 |
-
"no_html": 1,
|
| 39 |
-
"skip_disambig": 1,
|
| 40 |
-
}
|
| 41 |
-
response = requests.get(url, params=params)
|
| 42 |
-
if response.status_code != 200:
|
| 43 |
-
return f"Error: Received status code {response.status_code} from DuckDuckGo."
|
| 44 |
-
|
| 45 |
-
data = response.json()
|
| 46 |
-
abstract_text = data.get("AbstractText", "")
|
| 47 |
-
if abstract_text:
|
| 48 |
-
return f"Result: {abstract_text}"
|
| 49 |
-
|
| 50 |
-
# If no abstract is provided, try returning the first available related topic's text.
|
| 51 |
-
related_topics = data.get("RelatedTopics", [])
|
| 52 |
-
for topic in related_topics:
|
| 53 |
-
if isinstance(topic, dict):
|
| 54 |
-
if "Text" in topic:
|
| 55 |
-
return f"Result: {topic['Text']}"
|
| 56 |
-
if "Topics" in topic:
|
| 57 |
-
for subtopic in topic["Topics"]:
|
| 58 |
-
if "Text" in subtopic:
|
| 59 |
-
return f"Result: {subtopic['Text']}"
|
| 60 |
-
|
| 61 |
-
return "No results found."
|
| 62 |
-
|
| 63 |
except Exception as e:
|
| 64 |
-
return f"Error
|
| 65 |
|
| 66 |
-
|
| 67 |
@tool
|
| 68 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 69 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
+
def time_converter(time_str: str) -> str:
|
| 23 |
+
"""A tool that converts a time string from 12-hour format (with AM/PM) to 24-hour format.
|
| 24 |
|
| 25 |
Args:
|
| 26 |
+
time_str: A time string in 12-hour format (e.g., "02:30 PM").
|
| 27 |
+
|
| 28 |
Returns:
|
| 29 |
+
str: The time in 24-hour format (e.g., "14:30") or an error message.
|
| 30 |
"""
|
| 31 |
+
from datetime import datetime
|
|
|
|
| 32 |
try:
|
| 33 |
+
dt = datetime.strptime(time_str, "%I:%M %p")
|
| 34 |
+
return dt.strftime("%H:%M")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
+
return f"Error converting time: {str(e)}"
|
| 37 |
|
|
|
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 40 |
"""A tool that fetches the current local time in a specified timezone.
|