Spaces:
Sleeping
Sleeping
Updane app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,111 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
|
8 |
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from art import text2art
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
11 |
@tool
|
12 |
+
def get_random_fun_fact() -> str:
|
13 |
+
"""Fetches a random fun fact from an API."""
|
14 |
+
|
15 |
+
try:
|
16 |
+
response = requests.get("https://uselessfacts.jsph.pl/random.json?language=en")
|
17 |
+
if response.status_code == 200:
|
18 |
+
fact = response.json().get("text", "No fun fact available.")
|
19 |
+
return f"Fun Fact: {fact}"
|
20 |
+
else:
|
21 |
+
return "Error fetching fun fact."
|
22 |
+
except Exception as e:
|
23 |
+
return f"Error: {str(e)}"
|
24 |
+
|
25 |
+
@tool
|
26 |
+
def generate_ascii_art(text: str) -> str:
|
27 |
+
"""Converts a given text into ASCII art.
|
28 |
+
|
29 |
+
Args:
|
30 |
+
text: The text to convert into ASCII art.
|
31 |
+
"""
|
32 |
+
|
33 |
+
try:
|
34 |
+
return text2art(text)
|
35 |
+
except Exception as e:
|
36 |
+
return f"Error generating ASCII art: {str(e)}"
|
37 |
+
|
38 |
+
|
39 |
+
@tool
|
40 |
+
def days_until_event(event_date: str) -> str:
|
41 |
+
"""Calculates the number of days until a given event.
|
42 |
+
|
43 |
+
Args:
|
44 |
+
event_date: The target date in YYYY-MM-DD format.
|
45 |
+
"""
|
46 |
+
|
47 |
+
try:
|
48 |
+
event_date_obj = datetime.datetime.strptime(event_date, "%Y-%m-%d")
|
49 |
+
today = datetime.datetime.today()
|
50 |
+
delta = event_date_obj - today
|
51 |
+
|
52 |
+
if delta.days < 0:
|
53 |
+
return f"The event on {event_date} has already passed!"
|
54 |
+
return f"There are {delta.days} days left until {event_date}."
|
55 |
+
except ValueError:
|
56 |
+
return "Invalid date format. Please use YYYY-MM-DD."
|
57 |
+
|
58 |
+
|
59 |
+
@tool
|
60 |
+
def get_country_info(country: str) -> str:
|
61 |
+
"""Retrieves basic information about a given country.
|
62 |
+
|
63 |
+
Args:
|
64 |
+
country: The name of the country (e.g., "France").
|
65 |
+
"""
|
66 |
+
|
67 |
+
try:
|
68 |
+
url = f"https://restcountries.com/v3.1/name/{country}"
|
69 |
+
response = requests.get(url)
|
70 |
+
if response.status_code == 200:
|
71 |
+
data = response.json()[0]
|
72 |
+
name = data.get("name", {}).get("common", "Unknown")
|
73 |
+
capital = data.get("capital", ["Unknown"])[0]
|
74 |
+
population = data.get("population", "Unknown")
|
75 |
+
currency = list(data.get("currencies", {}).keys())[0] if "currencies" in data else "Unknown"
|
76 |
+
|
77 |
+
return f"Country: {name}\nCapital: {capital}\nPopulation: {population}\nCurrency: {currency}"
|
78 |
+
else:
|
79 |
+
return "Error fetching country information."
|
80 |
+
except Exception as e:
|
81 |
+
return f"Error: {str(e)}"
|
82 |
+
|
83 |
+
|
84 |
+
@tool
|
85 |
+
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
86 |
+
"""Converts an amount from one currency to another.
|
87 |
+
|
88 |
Args:
|
89 |
+
amount: The amount to convert.
|
90 |
+
from_currency: The currency to convert from (e.g., "USD").
|
91 |
+
to_currency: The currency to convert to (e.g., "EUR").
|
92 |
"""
|
93 |
+
|
94 |
+
try:
|
95 |
+
url = f"https://api.exchangerate-api.com/v4/latest/{from_currency.upper()}"
|
96 |
+
response = requests.get(url)
|
97 |
+
if response.status_code == 200:
|
98 |
+
rates = response.json().get("rates", {})
|
99 |
+
conversion_rate = rates.get(to_currency.upper())
|
100 |
+
|
101 |
+
if conversion_rate:
|
102 |
+
converted_amount = amount * conversion_rate
|
103 |
+
return f"{amount} {from_currency.upper()} is equal to {converted_amount:.2f} {to_currency.upper()}."
|
104 |
+
else:
|
105 |
+
return "Currency not found."
|
106 |
+
else:
|
107 |
+
return "Error fetching exchange rates."
|
108 |
+
except Exception as e:
|
109 |
+
return f"Error: {str(e)}"
|
110 |
+
|
111 |
+
|
112 |
|
113 |
@tool
|
114 |
def get_current_time_in_timezone(timezone: str) -> str:
|