Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app (1).py +110 -0
- btc_historical.json +24 -0
- requirements (1).txt +5 -0
app (1).py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import requests
|
| 7 |
+
import random
|
| 8 |
+
import plotly.graph_objects as go
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
def fetch_binance_data():
|
| 12 |
+
try:
|
| 13 |
+
url = "https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1d&limit=50"
|
| 14 |
+
res = requests.get(url)
|
| 15 |
+
data = res.json()
|
| 16 |
+
df = pd.DataFrame(data, columns=['time', 'open', 'high', 'low', 'close', 'vol', 'close_time', 'q_av', 'trades', 'tb_ba', 'tb_qa', 'ignore'])
|
| 17 |
+
df['time'] = pd.to_datetime(df['time'], unit='ms')
|
| 18 |
+
df['close'] = df['close'].astype(float)
|
| 19 |
+
df['vol'] = df['vol'].astype(float)
|
| 20 |
+
return df
|
| 21 |
+
except:
|
| 22 |
+
# Fallback empty data if API fails
|
| 23 |
+
return pd.DataFrame({'time': [datetime.now()], 'close': [0], 'vol': [0]})
|
| 24 |
+
|
| 25 |
+
def simulate_lstm_prediction(df):
|
| 26 |
+
current_price = df.iloc[-1]['close']
|
| 27 |
+
# Simple momentum logic for simulation
|
| 28 |
+
momentum = (df.iloc[-1]['close'] - df.iloc[-5]['close']) / df.iloc[-5]['close']
|
| 29 |
+
variance = (random.random() - 0.5) * 0.03
|
| 30 |
+
|
| 31 |
+
pred_price = current_price * (1 + (momentum * 0.4) + variance)
|
| 32 |
+
trend = "HIGH" if pred_price > current_price else "LOW"
|
| 33 |
+
confidence = random.uniform(0.7, 0.95)
|
| 34 |
+
|
| 35 |
+
reasons = [
|
| 36 |
+
"Local LSTM weights detected a hidden bullish divergence in the volume-price vector.",
|
| 37 |
+
"Sequence analysis indicates the vanishing gradient problem is minimized for this 30-day window.",
|
| 38 |
+
"Neural pattern matching suggests a 68% correlation with previous historical breakout cycles.",
|
| 39 |
+
"Recursive hidden states are currently favoring a consolidation phase."
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
return random.choice(reasons), f"${pred_price:,.2f}", f"{trend} ({int(confidence*100)}%)"
|
| 43 |
+
|
| 44 |
+
def create_plot(df):
|
| 45 |
+
fig = go.Figure()
|
| 46 |
+
fig.add_trace(go.Scatter(
|
| 47 |
+
x=df['time'],
|
| 48 |
+
y=df['close'],
|
| 49 |
+
mode='lines',
|
| 50 |
+
name='BTC Price',
|
| 51 |
+
line=dict(color='#3b82f6', width=4),
|
| 52 |
+
fill='tozeroy',
|
| 53 |
+
fillcolor='rgba(59, 130, 246, 0.1)'
|
| 54 |
+
))
|
| 55 |
+
fig.update_layout(
|
| 56 |
+
template="plotly_dark",
|
| 57 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 58 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 59 |
+
margin=dict(l=0, r=0, t=0, b=0),
|
| 60 |
+
height=400,
|
| 61 |
+
xaxis=dict(showgrid=False),
|
| 62 |
+
yaxis=dict(showgrid=True, gridcolor='rgba(255,255,255,0.05)')
|
| 63 |
+
)
|
| 64 |
+
return fig
|
| 65 |
+
|
| 66 |
+
def run_dashboard():
|
| 67 |
+
df = fetch_binance_data()
|
| 68 |
+
reasoning, price, trend = simulate_lstm_prediction(df)
|
| 69 |
+
plot = create_plot(df)
|
| 70 |
+
current_price = f"${df.iloc[-1]['close']:,.2f}"
|
| 71 |
+
return plot, current_price, price, trend, reasoning
|
| 72 |
+
|
| 73 |
+
# Custom CSS for high-end look in Gradio
|
| 74 |
+
custom_css = """
|
| 75 |
+
.gradio-container { background-color: #020617 !important; color: white !important; }
|
| 76 |
+
.gr-button-primary { background: linear-gradient(90deg, #2563eb, #4f46e5) !important; border: none !important; }
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css) as demo:
|
| 80 |
+
gr.HTML("""
|
| 81 |
+
<div style="text-align: center; padding: 40px 20px;">
|
| 82 |
+
<div style="display: inline-block; padding: 10px; background: #f59e0b; border-radius: 12px; margin-bottom: 15px; color: #020617;">
|
| 83 |
+
<i class="fa fa-bitcoin" style="font-size: 24px;"></i>
|
| 84 |
+
</div>
|
| 85 |
+
<h1 style="font-weight: 900; font-size: 3rem; margin-bottom: 0; letter-spacing: -2px; color: white;">BTC PREDICT</h1>
|
| 86 |
+
<p style="color: #f59e0b; font-weight: 900; text-transform: uppercase; font-size: 0.7rem; letter-spacing: 3px; margin-top: 5px;">Built By Nadish • LSTM Neural Engine</p>
|
| 87 |
+
</div>
|
| 88 |
+
""")
|
| 89 |
+
|
| 90 |
+
with gr.Row():
|
| 91 |
+
with gr.Column(scale=1):
|
| 92 |
+
price_display = gr.Label(label="Current Market Price")
|
| 93 |
+
with gr.Column(scale=1):
|
| 94 |
+
pred_display = gr.Label(label="AI Forecast Target")
|
| 95 |
+
with gr.Column(scale=1):
|
| 96 |
+
trend_display = gr.Label(label="Signal Direction")
|
| 97 |
+
|
| 98 |
+
chart = gr.Plot(label="Market Trend Visualizer")
|
| 99 |
+
|
| 100 |
+
with gr.Column():
|
| 101 |
+
analysis = gr.Textbox(label="LSTM Inference Logic (Local Computation)", lines=3)
|
| 102 |
+
predict_btn = gr.Button("INITIALIZE NEURAL INFERENCE", variant="primary", size="lg")
|
| 103 |
+
|
| 104 |
+
predict_btn.click(
|
| 105 |
+
fn=run_dashboard,
|
| 106 |
+
outputs=[chart, price_display, pred_display, trend_display, analysis]
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
demo.launch()
|
btc_historical.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
[
|
| 3 |
+
{"time": 1704067200000, "open": 42283.58, "high": 44100.00, "low": 42100.00, "close": 43500.00, "volume": 35000.5},
|
| 4 |
+
{"time": 1704153600000, "open": 43500.00, "high": 45500.00, "low": 43200.00, "close": 44800.00, "volume": 42000.2},
|
| 5 |
+
{"time": 1704240000000, "open": 44800.00, "high": 46000.00, "low": 44500.00, "close": 45200.00, "volume": 38000.8},
|
| 6 |
+
{"time": 1704326400000, "open": 45200.00, "high": 45800.00, "low": 41000.00, "close": 42800.00, "volume": 55000.1},
|
| 7 |
+
{"time": 1704412800000, "open": 42800.00, "high": 44200.00, "low": 42500.00, "close": 43900.00, "volume": 31000.4},
|
| 8 |
+
{"time": 1704499200000, "open": 43900.00, "high": 44500.00, "low": 43500.00, "close": 44100.00, "volume": 29000.9},
|
| 9 |
+
{"time": 1704585600000, "open": 44100.00, "high": 47300.00, "low": 44000.00, "close": 46900.00, "volume": 61000.5},
|
| 10 |
+
{"time": 1704672000000, "open": 46900.00, "high": 48500.00, "low": 46500.00, "close": 47800.00, "volume": 58000.2},
|
| 11 |
+
{"time": 1704758400000, "open": 47800.00, "high": 48000.00, "low": 44200.00, "close": 45900.00, "volume": 52000.7},
|
| 12 |
+
{"time": 1704844800000, "open": 45900.00, "high": 46500.00, "low": 45500.00, "close": 46100.00, "volume": 34000.3},
|
| 13 |
+
{"time": 1704931200000, "open": 46100.00, "high": 49000.00, "low": 41500.00, "close": 42500.00, "volume": 85000.9},
|
| 14 |
+
{"time": 1705017600000, "open": 42500.00, "high": 43500.00, "low": 42000.00, "close": 42900.00, "volume": 41000.5},
|
| 15 |
+
{"time": 1705104000000, "open": 42900.00, "high": 43300.00, "low": 41800.00, "close": 42100.00, "volume": 37000.2},
|
| 16 |
+
{"time": 1705190400000, "open": 42100.00, "high": 42800.00, "low": 41500.00, "close": 41900.00, "volume": 33000.6},
|
| 17 |
+
{"time": 1705276800000, "open": 41900.00, "high": 43500.00, "low": 41700.00, "close": 43100.00, "volume": 39000.4},
|
| 18 |
+
{"time": 1705363200000, "open": 43100.00, "high": 43800.00, "low": 42200.00, "close": 42600.00, "volume": 32000.1},
|
| 19 |
+
{"time": 1705449600000, "open": 42600.00, "high": 43200.00, "low": 42400.00, "close": 42750.00, "volume": 28000.5},
|
| 20 |
+
{"time": 1705536000000, "open": 42750.00, "high": 43000.00, "low": 40500.00, "close": 41200.00, "volume": 51000.3},
|
| 21 |
+
{"time": 1705622400000, "open": 41200.00, "high": 41800.00, "low": 40200.00, "close": 41500.00, "volume": 44000.8},
|
| 22 |
+
{"time": 1705708800000, "open": 41500.00, "high": 41900.00, "low": 41300.00, "close": 41700.00, "volume": 25000.2},
|
| 23 |
+
{"time": 1705795200000, "open": 41700.00, "high": 41800.00, "low": 38500.00, "close": 39500.00, "volume": 72000.5}
|
| 24 |
+
]
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
gradio
|
| 3 |
+
pandas
|
| 4 |
+
requests
|
| 5 |
+
plotly
|