Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,19 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 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
|
| 16 |
-
|
| 17 |
-
|
| 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:
|
|
@@ -76,7 +53,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
import requests
|
| 6 |
+
import random
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
|
|
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
+
def generate_random_number(start: int, end: int) -> int:
|
| 14 |
+
"""Gera um número aleatório entre start e end."""
|
| 15 |
+
return random.randint(start, end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
@tool
|
| 19 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 53 |
|
| 54 |
agent = CodeAgent(
|
| 55 |
model=model,
|
| 56 |
+
tools=[final_answer, generate_random_number], ## add your tools here (don't remove final answer)
|
| 57 |
max_steps=6,
|
| 58 |
verbosity_level=1,
|
| 59 |
grammar=None,
|