Spaces:
Paused
Paused
File size: 2,678 Bytes
6a9fb3f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import streamlit as st
import requests
import pandas as pd
# The URL where your FastAPI is running inside the Space
API_URL = "http://localhost:7860"
st.set_page_config(layout="wide")
st.title("π ProfitBook Trading Analysis Engine")
# --- Status Check ---
st.header("API Status")
if st.button("Check API Status"):
try:
response = requests.get(API_URL)
if response.status_code == 200:
st.success("API is operational.")
st.json(response.json())
else:
st.error(f"API returned status code: {response.status_code}")
st.text(response.text)
except requests.exceptions.ConnectionError as e:
st.error(f"Failed to connect to the API. Is it running? Error: {e}")
st.divider()
# --- Prediction Endpoint ---
st.header("Get Trading Signal")
symbol = st.text_input("Enter a stock symbol (e.g., NVDA, SPY, QQQ)", "NVDA").upper()
timeframe = st.selectbox("Select a timeframe", ["1m", "5m", "15m", "1h"], index=2)
strategy = st.selectbox("Select a strategy", ["momentum", "scalp", "gap"], index=0)
if st.button("Analyze Symbol"):
with st.spinner(f"Running full-stack AI analysis for {symbol}..."):
try:
# The endpoint URL for prediction
predict_url = f"{API_URL}/predict/enhanced/"
params = {
"symbol": symbol,
"timeframe": timeframe,
"strategy_mode": strategy
}
response = requests.post(predict_url, params=params)
if response.status_code == 200:
data = response.json()
st.subheader(f"Signal for {data['symbol']}: {data['signal']}")
col1, col2, col3 = st.columns(3)
col1.metric("Confidence", f"{data['confidence']:.0f}%")
col2.metric("Position Size", f"{data['position_size']:.2f}")
col3.metric("Hold Time", data['expected_hold_time'])
with st.expander("Reasoning and Strategy Details"):
st.write("**Reasoning:**", data['reasoning'])
st.write("**Suggested Options Strategy:**")
st.json(data['options_strategy'])
with st.expander("Full Analysis Data"):
st.json(data)
else:
st.error(f"API Error: Status {response.status_code}")
st.json(response.json())
except requests.exceptions.ConnectionError:
st.error("Failed to connect to the API.")
except Exception as e:
st.error(f"An unexpected error occurred: {e}") |