Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -7,7 +7,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 my_custom_tool(currency: str = "usd", amount: float = 1.0) -> str:
|
| 13 |
"""A tool that fetches the current Bitcoin price and calculates conversion
|
|
@@ -16,6 +15,7 @@ def my_custom_tool(currency: str = "usd", amount: float = 1.0) -> str:
|
|
| 16 |
amount: The amount of Bitcoin to convert (default: 1.0)
|
| 17 |
"""
|
| 18 |
try:
|
|
|
|
| 19 |
# CoinGecko API endpoint for Bitcoin price
|
| 20 |
url = f"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies={currency.lower()}"
|
| 21 |
response = requests.get(url)
|
|
@@ -25,11 +25,17 @@ def my_custom_tool(currency: str = "usd", amount: float = 1.0) -> str:
|
|
| 25 |
btc_price = response.json()['bitcoin'][currency.lower()]
|
| 26 |
converted_amount = btc_price * amount
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
except requests.RequestException as e:
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
except (KeyError, ValueError) as e:
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
@tool
|
| 35 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -48,15 +54,11 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 48 |
|
| 49 |
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
-
|
| 52 |
-
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 53 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 54 |
-
|
| 55 |
model = HfApiModel(
|
| 56 |
-
max_tokens=2096,
|
| 57 |
-
temperature=0.5,
|
| 58 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 59 |
-
custom_role_conversions=None,
|
| 60 |
)
|
| 61 |
|
| 62 |
|
|
@@ -68,7 +70,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
-
tools=[final_answer
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|
|
@@ -78,5 +80,4 @@ agent = CodeAgent(
|
|
| 78 |
prompt_templates=prompt_templates
|
| 79 |
)
|
| 80 |
|
| 81 |
-
|
| 82 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
def my_custom_tool(currency: str = "usd", amount: float = 1.0) -> str:
|
| 12 |
"""A tool that fetches the current Bitcoin price and calculates conversion
|
|
|
|
| 15 |
amount: The amount of Bitcoin to convert (default: 1.0)
|
| 16 |
"""
|
| 17 |
try:
|
| 18 |
+
print(f"Fetching Bitcoin price for {amount} BTC in {currency}") # Debug log
|
| 19 |
# CoinGecko API endpoint for Bitcoin price
|
| 20 |
url = f"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies={currency.lower()}"
|
| 21 |
response = requests.get(url)
|
|
|
|
| 25 |
btc_price = response.json()['bitcoin'][currency.lower()]
|
| 26 |
converted_amount = btc_price * amount
|
| 27 |
|
| 28 |
+
result = f"{amount} Bitcoin = {converted_amount:,.2f} {currency.upper()} (Current BTC rate: {btc_price:,.2f} {currency.upper()})"
|
| 29 |
+
print(f"Result: {result}") # Debug log
|
| 30 |
+
return result
|
| 31 |
except requests.RequestException as e:
|
| 32 |
+
error_msg = f"Error fetching Bitcoin rate: {str(e)}"
|
| 33 |
+
print(f"Error: {error_msg}") # Debug log
|
| 34 |
+
return error_msg
|
| 35 |
except (KeyError, ValueError) as e:
|
| 36 |
+
error_msg = f"Error processing Bitcoin rate: {str(e)}"
|
| 37 |
+
print(f"Error: {error_msg}") # Debug log
|
| 38 |
+
return error_msg
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
model = HfApiModel(
|
| 58 |
+
max_tokens=2096,
|
| 59 |
+
temperature=0.5,
|
| 60 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 61 |
+
custom_role_conversions=None,
|
| 62 |
)
|
| 63 |
|
| 64 |
|
|
|
|
| 70 |
|
| 71 |
agent = CodeAgent(
|
| 72 |
model=model,
|
| 73 |
+
tools=[final_answer, my_custom_tool, get_current_time_in_timezone, image_generation_tool],
|
| 74 |
max_steps=6,
|
| 75 |
verbosity_level=1,
|
| 76 |
grammar=None,
|
|
|
|
| 80 |
prompt_templates=prompt_templates
|
| 81 |
)
|
| 82 |
|
|
|
|
| 83 |
GradioUI(agent).launch()
|