Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,35 @@ 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:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
| 13 |
+
"""
|
| 14 |
+
Converts an amount from one currency to another using a static exchange rate list.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
amount: The amount of money to convert.
|
| 18 |
+
from_currency: The currency code of the original amount.
|
| 19 |
+
to_currency: The currency code to convert to.
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
A string representing the converted amount or an error message if the currency is invalid.
|
| 23 |
"""
|
| 24 |
+
exchange_rates = {
|
| 25 |
+
"USD": 1.0,
|
| 26 |
+
"EUR": 0.92,
|
| 27 |
+
"GBP": 0.78,
|
| 28 |
+
"TRY": 32.0
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
if from_currency not in exchange_rates or to_currency not in exchange_rates:
|
| 33 |
+
return f"Error: Invalid currency '{from_currency}' or '{to_currency}'"
|
| 34 |
+
|
| 35 |
+
# Convert to USD first, then to target currency
|
| 36 |
+
amount_in_usd = amount / exchange_rates[from_currency]
|
| 37 |
+
converted_amount = amount_in_usd * exchange_rates[to_currency]
|
| 38 |
+
return f"{amount} {from_currency} = {round(converted_amount, 2)} {to_currency}"
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error converting currency: {str(e)}"
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|