import streamlit as st import numpy as np import plotly.graph_objects as go from app import SMCPredictionEngine # ── Page Config ─────────────────────────────────────────────────────────────── st.set_page_config(page_title="AI-Powered SMC Suite", layout="wide") # ── Lazy model loader (cached across reruns, NOT at module import time) ─────── @st.cache_resource(show_spinner="Loading AI engine — this may take ~30 s on first run…") def load_ai_engine(): return SMCPredictionEngine() # ── Sidebar ─────────────────────────────────────────────────────────────────── st.sidebar.header("🎯 System Parameters") trading_pair = st.sidebar.selectbox( "Market Asset Profile", ["BTC/USDT", "ETH/USDT", "SOL/USDT"] ) timeframe = st.sidebar.selectbox( "Multi-Timeframe Horizon", ["5-Minute", "10-Minute", "1-Hour"] ) prediction_horizon = st.sidebar.slider( "AI Forward Forecast Horizon (Candles)", 4, 24, 12 ) st.sidebar.markdown("---") st.sidebar.header("🕹️ Generation Control") market_condition = st.sidebar.radio( "Simulate Market Bias", [ "Bullish Inflow (Order Block Expansion)", "Bearish Liquidity Sweep Collapse", "Ranging / Volatile Consolidation", ], ) # ── Generate synthetic historical price data ────────────────────────────────── np.random.seed(101) base_price = ( 65000 if trading_pair == "BTC/USDT" else (3500 if trading_pair == "ETH/USDT" else 150) ) steps = 100 if market_condition == "Bullish Inflow (Order Block Expansion)": noise = np.random.normal(5, 20, steps) trend = np.linspace(0, 400, steps) elif market_condition == "Bearish Liquidity Sweep Collapse": noise = np.random.normal(-5, 20, steps) trend = np.linspace(0, -400, steps) else: noise = np.random.normal(0, 35, steps) trend = np.zeros(steps) historical_prices = base_price + trend + np.cumsum(noise) # ── Header ──────────────────────────────────────────────────────────────────── st.title("🎛️ SMC Trading Suite — Version 4.0 AI Layer") st.caption("Connected to Hugging Face Engine: Amazon Chronos-Bolt-Base") st.markdown("---") # ── Load model & run inference ──────────────────────────────────────────────── ai_brain = load_ai_engine() # triggers spinner only on first load with st.spinner("Executing time-series transformer inference…"): results = ai_brain.calculate_forecast(historical_prices, prediction_horizon) # ── Metrics row ─────────────────────────────────────────────────────────────── col1, col2, col3 = st.columns(3) with col1: st.metric("Latest Ticking Price", f"${historical_prices[-1]:,.2f}") with col2: pct = results["projected_change_pct"] st.metric( label="AI Projected Momentum Drift", value=f"{pct:.2f}%", delta=f"{pct:.2f}% Directional Path", ) with col3: score = ( "HIGH PROBABILITY ENTRY" if abs(results["projected_change_pct"]) > 0.5 else "REJECTED / LOW VOLUMETRIC MOMENTUM" ) st.info(f"Signal Optimizer Output: **{score}**") # ── Plotly chart ────────────────────────────────────────────────────────────── st.subheader("📊 Architectural Vector Forecast Visualization") history_idx = list(range(len(historical_prices))) future_idx = list(range(len(historical_prices), len(historical_prices) + prediction_horizon)) fig = go.Figure() fig.add_trace(go.Scatter( x=history_idx, y=historical_prices, mode="lines", name="Cleaned Candle Data Stream", line=dict(color="#1f77b4", width=2), )) fig.add_trace(go.Scatter( x=future_idx, y=results["median"], mode="lines+markers", name="AI Median Structural Path", line=dict(color="#e377c2", width=2, dash="dash"), )) # Upper boundary (invisible line — acts as ceiling for fill) fig.add_trace(go.Scatter( x=future_idx, y=results["high"], mode="lines", line=dict(width=0), showlegend=False, name="Upper Volatility Boundary", )) # Lower boundary filled back to upper → confidence band fig.add_trace(go.Scatter( x=future_idx, y=results["low"], mode="lines", line=dict(width=0), fill="tonexty", fillcolor="rgba(227, 119, 194, 0.2)", showlegend=True, name="80% Structural Risk Envelope", )) fig.update_layout( template="plotly_dark", xaxis_title="Historical & Predicted Timeline Sequence", yaxis_title="Asset Value Index ($)", margin=dict(l=20, r=20, t=20, b=20), height=550, legend=dict(yanchor="top", y=0.99, xanchor="left", x=0.01), ) st.plotly_chart(fig, use_container_width=True)