Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,16 @@ from Gradio_UI import GradioUI
|
|
| 11 |
@tool
|
| 12 |
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
| 13 |
"""
|
| 14 |
-
Convert amount from one currency to another using fixed exchange rates.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
-
# Mock exchange rates relative to USD
|
| 17 |
exchange_rates = {
|
| 18 |
"USD": 1.0,
|
| 19 |
"EUR": 0.91,
|
|
@@ -21,9 +28,21 @@ def convert_currency(amount: float, from_currency: str, to_currency: str) -> str
|
|
| 21 |
"JPY": 134.23,
|
| 22 |
"INR": 83.12,
|
| 23 |
"CNY": 7.25,
|
| 24 |
-
"AED": 3.
|
| 25 |
}
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
from_currency = from_currency.upper()
|
| 28 |
to_currency = to_currency.upper()
|
| 29 |
|
|
|
|
| 11 |
@tool
|
| 12 |
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
| 13 |
"""
|
| 14 |
+
Convert an amount from one currency to another using fixed exchange rates.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
amount (float): The amount of money to convert.
|
| 18 |
+
from_currency (str): The three-letter currency code to convert from (e.g., "USD").
|
| 19 |
+
to_currency (str): The three-letter currency code to convert to (e.g., "EUR").
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
str: A string describing the converted amount.
|
| 23 |
"""
|
|
|
|
| 24 |
exchange_rates = {
|
| 25 |
"USD": 1.0,
|
| 26 |
"EUR": 0.91,
|
|
|
|
| 28 |
"JPY": 134.23,
|
| 29 |
"INR": 83.12,
|
| 30 |
"CNY": 7.25,
|
| 31 |
+
"AED": 3.67
|
| 32 |
}
|
| 33 |
|
| 34 |
+
from_currency = from_currency.upper()
|
| 35 |
+
to_currency = to_currency.upper()
|
| 36 |
+
|
| 37 |
+
if from_currency not in exchange_rates or to_currency not in exchange_rates:
|
| 38 |
+
return f"Unsupported currency. Supported currencies: {', '.join(exchange_rates.keys())}"
|
| 39 |
+
|
| 40 |
+
amount_in_usd = amount / exchange_rates[from_currency]
|
| 41 |
+
converted_amount = amount_in_usd * exchange_rates[to_currency]
|
| 42 |
+
|
| 43 |
+
return f"{amount:.2f} {from_currency} = {converted_amount:.2f} {to_currency}"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
from_currency = from_currency.upper()
|
| 47 |
to_currency = to_currency.upper()
|
| 48 |
|