| import streamlit as st |
| import matplotlib.pyplot as plt |
| import numpy as np |
| import os |
| from stable_baselines3 import PPO |
|
|
| |
| st.set_page_config(page_title="FelipeCore v4 Quantum", page_icon="🌀", layout="wide") |
|
|
| st.markdown(""" |
| <style> |
| .main { background-color: #0e1117; } |
| h1 { color: #bc13fe; font-family: 'Courier New', Courier, monospace; } |
| .stMetric { background-color: #1a1c23; padding: 10px; border-radius: 10px; border: 1px solid #bc13fe; } |
| </style> |
| """, unsafe_allow_html=True) |
|
|
| |
| NOME_DO_MODELO = "ppo_felipecore_v4_quantum.zip" |
|
|
| @st.cache_resource |
| def load_quantum_model(): |
| if os.path.exists(NOME_DO_MODELO): |
| try: |
| return PPO.load(NOME_DO_MODELO, device="cpu") |
| except Exception as e: |
| st.error(f"Erro ao carregar o agente: {e}") |
| return None |
| return None |
|
|
| model = load_quantum_model() |
|
|
| st.title("🌀 FELIPECORE v4: Quantum Dashboard") |
|
|
| with st.sidebar: |
| if model: |
| st.success("✅ AGENTE ONLINE") |
| else: |
| st.error("❌ AGENTE OFFLINE") |
| |
| st.header("🛸 Command Center") |
| steps = st.slider("Analysis Steps", 20, 200, 100) |
| input_base = st.number_input("Quantum Input Base", value=1.0) |
| run_btn = st.button("EXECUTE NEURAL STREAM") |
|
|
| col1, col2 = st.columns([2, 1]) |
|
|
| if run_btn and model: |
| with col1: |
| st.write("🌌 *Injetando ruído quântico nos tensores...*") |
| results = [] |
| progress = st.progress(0) |
| |
| for i in range(steps): |
| try: |
| |
| |
| v1 = float(input_base + np.random.normal(0, 1.0)) |
| v2 = float(np.random.normal(0, 1.0)) |
| v3 = float(np.random.normal(0, 1.0)) |
| v4 = float(np.random.normal(0, 1.0)) |
| |
| obs = np.array([[v1, v2, v3, v4]], dtype=np.float32) |
| |
| |
| |
| action, _ = model.predict(obs, deterministic=False) |
| |
| |
| if hasattr(action, 'item'): |
| val = action.item() |
| else: |
| val = float(action[0]) if isinstance(action, (list, np.ndarray)) else float(action) |
| |
| results.append(val) |
| except Exception as e: |
| st.error(f"Erro técnico: {e}") |
| break |
| |
| progress.progress((i + 1) / steps) |
|
|
| if results: |
| plt.style.use('dark_background') |
| fig, ax = plt.subplots(figsize=(10, 4)) |
| |
| |
| ax.step(range(len(results)), results, color='#bc13fe', linewidth=2, where='post') |
| ax.fill_between(range(len(results)), results, color='#bc13fe', alpha=0.1, step='post') |
| |
| ax.set_title("Neural Decision Stream (Discrete 0/1)", color="#bc13fe") |
| ax.set_ylim(-0.2, 1.2) |
| ax.set_yticks([0, 1]) |
| ax.set_yticklabels(['LOW', 'HIGH']) |
| st.pyplot(fig) |
|
|
| with col2: |
| if results: |
| st.metric(label="Last Action", value="HIGH (1)" if results[-1] > 0.5 else "LOW (0)") |
| st.metric(label="Decision Variance", value=f"{np.std(results):.4f}") |
| |
| if np.std(results) > 0.1: |
| st.success("🔥 MODELO ATIVO: Mudando de estado!") |
| else: |
| st.warning("ℹ️ ESTADO ÚNICO: Tente mudar o Input Base.") |
|
|
| st.markdown("---") |
| st.caption("FelipeCore-v4-Quantum | Numpy 2.0 Scalar Fix") |
|
|