Spaces:
Sleeping
Sleeping
Updated app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,81 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
#
|
11 |
@tool
|
12 |
-
def
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# My first tool !
|
11 |
@tool
|
12 |
+
def coin_predictor_tool()-> str: #it's import to specify the return type
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
+
!pip install -q llama-index requests
|
15 |
+
|
16 |
+
# Step 2: Define the Agent Tool
|
17 |
+
from llama_index.core.tools import FunctionTool
|
18 |
+
import requests
|
19 |
+
from datetime import datetime
|
20 |
+
|
21 |
+
def coin_predictor_tool() -> str:
|
22 |
"""
|
23 |
+
Predicts Bitcoin's price for today (March 10, 2025) based on available data or trends.
|
24 |
+
Returns a formatted string with the predicted price and reasoning.
|
25 |
+
"""
|
26 |
+
# Simulate current date
|
27 |
+
today = datetime(2025, 3, 10)
|
28 |
+
current_date_str = today.strftime('%Y-%m-%d')
|
29 |
+
|
30 |
+
# Placeholder for real data (replace with API call in practice)
|
31 |
+
# Example: Fetch last 7 days of BTC prices from an API
|
32 |
+
try:
|
33 |
+
# Hypothetical API call (e.g., CoinGecko)
|
34 |
+
url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart"
|
35 |
+
params = {
|
36 |
+
"vs_currency": "usd",
|
37 |
+
"days": "7", # Last 7 days
|
38 |
+
"interval": "daily"
|
39 |
+
}
|
40 |
+
response = requests.get(url, params=params, timeout=10)
|
41 |
+
response.raise_for_status()
|
42 |
+
data = response.json()
|
43 |
+
|
44 |
+
# Extract prices (simulated here; replace with real data)
|
45 |
+
prices = data.get("prices", []) # [[timestamp, price], ...]
|
46 |
+
if not prices:
|
47 |
+
raise ValueError("No price data available")
|
48 |
+
|
49 |
+
# Simple prediction: Average of last 7 days + trend adjustment
|
50 |
+
recent_prices = [price[1] for price in prices[-7:]] # Last 7 days' closing prices
|
51 |
+
avg_price = sum(recent_prices) / len(recent_prices)
|
52 |
+
|
53 |
+
# Assume a trend (e.g., based on last day's change)
|
54 |
+
last_change = recent_prices[-1] - recent_prices[-2]
|
55 |
+
trend_factor = 1 + (last_change / recent_prices[-2]) # % change applied
|
56 |
+
predicted_price = avg_price * trend_factor
|
57 |
+
|
58 |
+
except Exception as e:
|
59 |
+
# Fallback simulation if API fails or for demo purposes
|
60 |
+
print(f"API error: {e}. Using simulated data.")
|
61 |
+
# Simulated data based on recent trends (e.g., from your provided context)
|
62 |
+
avg_price = 91981 # From Web ID 5, March 10, 2025 price
|
63 |
+
trend_factor = 1.0418 # +4.18% from Web ID 7's 24h change
|
64 |
+
predicted_price = avg_price * trend_factor
|
65 |
+
|
66 |
+
# Format the output
|
67 |
+
output = (
|
68 |
+
f"Bitcoin Price Prediction for {current_date_str}:\n"
|
69 |
+
f"Predicted Price: ${predicted_price:,.2f} USD\n"
|
70 |
+
f"Reasoning: Based on a 7-day average of ${avg_price:,.2f} with a "
|
71 |
+
f"{(trend_factor-1)*100:.2f}% trend adjustment from recent data."
|
72 |
+
)
|
73 |
+
return output
|
74 |
+
|
75 |
+
# Create the tool
|
76 |
+
bitcoin_price_tool = FunctionTool.from_defaults(
|
77 |
+
fn=coin_predictor_tool,
|
78 |
+
name="bitcoin_price_predictor",
|
79 |
+
description="Predicts Bitcoin's price for today (March 10, 2025) using recent trends or API data."
|
80 |
+
)
|
81 |
+
|
82 |
+
# Step 3: Test the tool standalone
|
83 |
+
print(bitcoin_price_tool())
|
84 |
+
|
85 |
|
86 |
@tool
|
87 |
def get_current_time_in_timezone(timezone: str) -> str:
|