Spaces:
Running
Running
| 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) βββββββ | |
| 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) |