Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,36 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
|
|
|
| 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:
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
import requests
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
| 14 |
+
"""A tool that converts one currency to another based on real-time exchange rates.
|
|
|
|
| 15 |
Args:
|
| 16 |
+
amount: The amount of money to convert.
|
| 17 |
+
from_currency: The currency code of the input currency (e.g., 'USD').
|
| 18 |
+
to_currency: The currency code of the target currency (e.g., 'EUR').
|
| 19 |
+
Returns:
|
| 20 |
+
A string indicating the converted amount.
|
| 21 |
"""
|
| 22 |
+
try:
|
| 23 |
+
# Fetch real-time exchange rates from a free API
|
| 24 |
+
url = f"https://api.exchangerate-api.com/v4/latest/{from_currency}"
|
| 25 |
+
response = requests.get(url).json()
|
| 26 |
+
|
| 27 |
+
if 'error' in response:
|
| 28 |
+
return f"Error fetching exchange rates for {from_currency}."
|
| 29 |
+
|
| 30 |
+
exchange_rate = response['rates'].get(to_currency)
|
| 31 |
+
if exchange_rate:
|
| 32 |
+
converted_amount = amount * exchange_rate
|
| 33 |
+
return f"{amount} {from_currency} = {converted_amount:.2f} {to_currency}"
|
| 34 |
+
else:
|
| 35 |
+
return f"Currency conversion from {from_currency} to {to_currency} not supported."
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error converting currency: {str(e)}"
|
| 39 |
+
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def get_current_time_in_timezone(timezone: str) -> str:
|