Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,23 @@ from smolagents import CodeAgent, HfApiModel, tool
|
|
| 2 |
import requests
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
| 5 |
-
import nltk
|
| 6 |
-
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
# Modified tool with proper parameter documentation
|
| 12 |
@tool
|
| 13 |
def get_btc_confidence_conseils(price: str) -> str:
|
| 14 |
-
"""Analyzes Bitcoin market confidence using price data
|
| 15 |
|
| 16 |
Args:
|
| 17 |
price (str): The current Bitcoin price in USD format (e.g., "$50,000.00")
|
|
@@ -19,37 +26,14 @@ def get_btc_confidence_conseils(price: str) -> str:
|
|
| 19 |
Returns:
|
| 20 |
str: Market analysis and trading advice based on current conditions
|
| 21 |
"""
|
| 22 |
-
sia = SentimentIntensityAnalyzer()
|
| 23 |
numeric_price = float(price.replace("$", "").replace(",", ""))
|
| 24 |
|
| 25 |
-
# Add your analysis logic here
|
| 26 |
if numeric_price > 50000:
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
else:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
return f"Market analysis ({price}): {sentiment.capitalize()} trend detected. Consider dollar-cost averaging."
|
| 32 |
-
|
| 33 |
-
# Tool for fetching Bitcoin price (updated with parameter docs)
|
| 34 |
-
@tool
|
| 35 |
-
def get_btc_price(crypto: str) -> str:
|
| 36 |
-
"""Fetches the current Bitcoin price in USD using the CoinGecko API.
|
| 37 |
-
|
| 38 |
-
Args:
|
| 39 |
-
crypto (str): Cryptocurrency symbol (e.g., 'bitcoin')
|
| 40 |
-
|
| 41 |
-
Returns:
|
| 42 |
-
str: Formatted price string or error message
|
| 43 |
-
"""
|
| 44 |
-
url = f"https://api.coingecko.com/api/v3/simple/price?ids={crypto}&vs_currencies=usd"
|
| 45 |
-
response = requests.get(url)
|
| 46 |
-
if response.status_code != 200:
|
| 47 |
-
return '{"error": "Failed to fetch Bitcoin price"}'
|
| 48 |
-
data = response.json()
|
| 49 |
-
price = data.get(crypto, {}).get('usd')
|
| 50 |
-
if price is None:
|
| 51 |
-
return '{"error": "Bitcoin price not found"}'
|
| 52 |
-
return f"The current Bitcoin price is ${price:,.2f} USD."
|
| 53 |
|
| 54 |
# Initialize the agent with all tools
|
| 55 |
agent = CodeAgent(
|
|
@@ -64,4 +48,4 @@ agent = CodeAgent(
|
|
| 64 |
)
|
| 65 |
|
| 66 |
# Launch the Gradio interface
|
| 67 |
-
GradioUI(agent).launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
@tool
|
| 7 |
+
def get_btc_price() -> str:
|
| 8 |
+
"""Fetches the current Bitcoin price in USD using the CoinGecko API."""
|
| 9 |
+
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
|
| 10 |
+
response = requests.get(url)
|
| 11 |
+
if response.status_code != 200:
|
| 12 |
+
return '{"error": "Failed to fetch Bitcoin price"}'
|
| 13 |
+
data = response.json()
|
| 14 |
+
price = data.get('bitcoin', {}).get('usd')
|
| 15 |
+
if price is None:
|
| 16 |
+
return '{"error": "Bitcoin price not found"}'
|
| 17 |
+
return f"The current Bitcoin price is ${price:,.2f} USD."
|
| 18 |
|
|
|
|
| 19 |
@tool
|
| 20 |
def get_btc_confidence_conseils(price: str) -> str:
|
| 21 |
+
"""Analyzes Bitcoin market confidence using price data.
|
| 22 |
|
| 23 |
Args:
|
| 24 |
price (str): The current Bitcoin price in USD format (e.g., "$50,000.00")
|
|
|
|
| 26 |
Returns:
|
| 27 |
str: Market analysis and trading advice based on current conditions
|
| 28 |
"""
|
|
|
|
| 29 |
numeric_price = float(price.replace("$", "").replace(",", ""))
|
| 30 |
|
|
|
|
| 31 |
if numeric_price > 50000:
|
| 32 |
+
return f"Market analysis ({price}): Bullish trend detected. Consider buying."
|
| 33 |
+
elif numeric_price > 30000:
|
| 34 |
+
return f"Market analysis ({price}): Neutral trend detected. Consider holding."
|
| 35 |
else:
|
| 36 |
+
return f"Market analysis ({price}): Bearish trend detected. Consider selling."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Initialize the agent with all tools
|
| 39 |
agent = CodeAgent(
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
# Launch the Gradio interface
|
| 51 |
+
GradioUI(agent).launch()
|