Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,40 @@ import datetime
|
|
| 3 |
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 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import requests
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
+
API_KEY = "bf727f5fb71ae77125fca1bf22199e5f"
|
| 12 |
+
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
| 15 |
+
def convert_currency(from_currency:str, amount:float, to_currency:str)-> str: #it's import to specify the return type
|
| 16 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 17 |
+
"""Converts the value of a currency to another using ExchangeRate-API
|
| 18 |
Args:
|
| 19 |
+
from_currency: the coin of origin
|
| 20 |
+
amount: origin value
|
| 21 |
+
to_currency: target coin
|
| 22 |
"""
|
| 23 |
+
try:
|
| 24 |
+
url=f"https://v6.exchangerate-api.com/v6/{API_KEY}/latest/{from_currency}"
|
| 25 |
+
response = requests.get(url)
|
| 26 |
+
data = response.json()
|
| 27 |
+
|
| 28 |
+
if response.status_code==200:
|
| 29 |
+
exchange_rate = data['conversion_rates'].get(to_currency)
|
| 30 |
+
|
| 31 |
+
if exchange_rate:
|
| 32 |
+
converted_amount = amount * exchange_rate
|
| 33 |
+
return f"{amount} {from_currency} is {converted_amount:.2f} {to_currency}"
|
| 34 |
+
else:
|
| 35 |
+
return f"Erro: target coin {to_currency} not found"
|
| 36 |
+
else:
|
| 37 |
+
return f"Erro ao obter taxas de câmbio: {data.get('error-type', 'Desconhecido')}"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return f"Erro ao fazer a conversão: {str(e)}"
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def get_current_time_in_timezone(timezone: str) -> str:
|