Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,46 @@ 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 does nothing yet
|
| 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 get_joke_or_quote(category: str) -> str:
|
| 13 |
+
"""Fetches a random joke or an inspirational quote.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
category: What to fetch — either 'joke' for a random joke,
|
| 16 |
+
or 'quote' for an inspirational quote.
|
| 17 |
"""
|
| 18 |
+
category = category.strip().lower()
|
| 19 |
+
|
| 20 |
+
if category == "joke":
|
| 21 |
+
try:
|
| 22 |
+
response = requests.get(
|
| 23 |
+
"https://v2.jokeapi.dev/joke/Any",
|
| 24 |
+
params={"blacklistFlags": "nsfw,racist,sexist", "type": "twopart,single"},
|
| 25 |
+
timeout=5,
|
| 26 |
+
)
|
| 27 |
+
data = response.json()
|
| 28 |
+
if data.get("type") == "twopart":
|
| 29 |
+
return f"😄 {data['setup']}\n\n👉 {data['delivery']}"
|
| 30 |
+
else:
|
| 31 |
+
return f"😄 {data['joke']}"
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Couldn't fetch a joke right now: {e}"
|
| 34 |
+
|
| 35 |
+
elif category == "quote":
|
| 36 |
+
try:
|
| 37 |
+
response = requests.get(
|
| 38 |
+
"https://zenquotes.io/api/random",
|
| 39 |
+
timeout=5,
|
| 40 |
+
)
|
| 41 |
+
data = response.json()[0]
|
| 42 |
+
return f'💬 "{data["q"]}"\n\n— {data["a"]}'
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Couldn't fetch a quote right now: {e}"
|
| 45 |
+
|
| 46 |
+
else:
|
| 47 |
+
return (
|
| 48 |
+
"Unknown category. Please use 'joke' for a random joke "
|
| 49 |
+
"or 'quote' for an inspirational quote."
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
|
| 53 |
@tool
|
| 54 |
def get_current_time_in_timezone(timezone: str) -> str:
|