Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from wasawat07/AIMasterFX: direct link, hf CLI and curl.
- Browser
- Download file 13.5 kB
-
https://huggingface.co/spaces/wasawat07/AIMasterFX/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/wasawat07/AIMasterFX/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/wasawat07/AIMasterFX/resolve/main/src/streamlit_app.py
13.5 kB
| import streamlit as st | |
| import pandas as pd | |
| from datetime import datetime | |
| import random | |
| # ===================================================================== | |
| # 1. PAGE INITIALIZATION & HIGH-FIDELITY RETRO STYLING | |
| # ===================================================================== | |
| st.set_page_config( | |
| page_title="Trading Office - Realtime Bot Command Center", | |
| page_icon="☕", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # บังคับโครงสร้างและโทนสีให้ตรงตามรูปภาพหน้าจอห้องทำงานร้านกาแฟพิกเซล | |
| st.markdown(""" | |
| <link rel="preconnect" href="https://fonts.googleapis.com"> | |
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | |
| <link href="https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;600&family=Press+Start+2P&display=swap" rel="stylesheet"> | |
| <style> | |
| /* ตั้งค่าฟอนต์หลักของระบบแยกตามโซน */ | |
| html, body, [data-testid="stAppViewContainer"], [data-testid="stSidebar"] { | |
| background-color: #0d0e12 !important; | |
| color: #ffffff !important; | |
| font-family: 'Chakra Petch', sans-serif !important; | |
| } | |
| /* ---- 1. SIDEBAR CUSTOMIZATION (แถบซ้ายสุดสีเข้ม) ---- */ | |
| [data-testid="stSidebar"] { | |
| background-color: #16181f !important; | |
| border-right: 1px solid #252932 !important; | |
| padding-top: 10px; | |
| } | |
| .sidebar-title { | |
| font-size: 16px; | |
| font-weight: 600; | |
| color: #00ffff; | |
| margin-bottom: 2px; | |
| } | |
| .sidebar-subtitle { | |
| font-size: 11px; | |
| color: #6b7280; | |
| margin-bottom: 20px; | |
| } | |
| .sidebar-section-title { | |
| font-size: 12px; | |
| font-weight: 600; | |
| color: #9ca3af; | |
| text-transform: uppercase; | |
| margin-top: 15px; | |
| margin-bottom: 8px; | |
| border-bottom: 1px solid #252932; | |
| padding-bottom: 4px; | |
| } | |
| .sidebar-metric-box { | |
| background-color: #1c1f26; | |
| border: 1px solid #2c313d; | |
| border-radius: 6px; | |
| padding: 10px; | |
| margin-bottom: 8px; | |
| } | |
| .sidebar-metric-label { | |
| font-size: 11px; | |
| color: #9ca3af; | |
| } | |
| .sidebar-metric-value { | |
| font-size: 18px; | |
| font-weight: 600; | |
| color: #00ff66; | |
| } | |
| /* ---- 2. TOP BAR CONTROLS (แถบควบคุมด้านบน) ---- */ | |
| .top-navbar { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| background-color: #16181f; | |
| border: 1px solid #252932; | |
| border-radius: 6px; | |
| padding: 8px 16px; | |
| margin-bottom: 15px; | |
| } | |
| .top-nav-tabs { | |
| display: flex; | |
| gap: 15px; | |
| } | |
| .top-nav-tab { | |
| font-size: 12px; | |
| font-weight: 600; | |
| color: #9ca3af; | |
| padding: 6px 12px; | |
| cursor: pointer; | |
| text-transform: uppercase; | |
| } | |
| .top-nav-tab.active { | |
| color: #00ffff; | |
| border-bottom: 2px solid #00ffff; | |
| } | |
| /* ---- 3. MAIN COZY CAFE CANVAS (ห้องทำงานร้านกาแฟตรงกลาง) ---- */ | |
| .cafe-container { | |
| background: linear-gradient(180deg, #3a221d 0%, #1f110e 100%); | |
| border: 4px solid #4a322c; | |
| border-radius: 12px; | |
| min-height: 480px; | |
| position: relative; | |
| padding: 25px; | |
| box-shadow: inset 0 0 40px rgba(0,0,0,0.8); | |
| overflow: hidden; | |
| } | |
| .cafe-window { | |
| position: absolute; | |
| top: 20px; | |
| left: 30px; | |
| width: 140px; | |
| height: 180px; | |
| background: linear-gradient(0deg, #519075 0%, #a2d2bb 100%); | |
| border: 6px solid #5a3d35; | |
| box-shadow: 0 0 15px rgba(162,210,187,0.4); | |
| display: flex; | |
| align-items: flex-end; | |
| justify-content: center; | |
| font-size: 24px; | |
| } | |
| .coffee-shelf { | |
| position: absolute; | |
| top: 30px; | |
| right: 40px; | |
| width: 280px; | |
| height: 80px; | |
| background-color: #2a1612; | |
| border-bottom: 4px solid #5a3d35; | |
| display: flex; | |
| justify-content: space-around; | |
| align-items: center; | |
| font-size: 20px; | |
| padding: 0 10px; | |
| } | |
| .workstation-wrapper { | |
| display: flex; | |
| justify-content: space-around; | |
| margin-top: 160px; | |
| gap: 20px; | |
| } | |
| .agent-workstation { | |
| background-color: rgba(40, 25, 22, 0.85); | |
| border: 3px solid #6b4c42; | |
| border-radius: 8px; | |
| padding: 15px; | |
| width: 42%; | |
| position: relative; | |
| box-shadow: 0 10px 20px rgba(0,0,0,0.5); | |
| } | |
| .floating-status-card { | |
| background-color: #0b0c10; | |
| border: 1px solid #22c55e; | |
| border-radius: 4px; | |
| padding: 8px 12px; | |
| margin-bottom: 15px; | |
| box-shadow: 0 0 10px rgba(34, 197, 94, 0.2); | |
| } | |
| .status-badge { | |
| background-color: #166534; | |
| color: #4ade80; | |
| font-size: 9px; | |
| padding: 2px 6px; | |
| border-radius: 3px; | |
| font-family: 'Press Start 2P', monospace; | |
| display: inline-block; | |
| margin-bottom: 6px; | |
| } | |
| .status-line { | |
| font-size: 11px; | |
| color: #9ca3af; | |
| margin-bottom: 3px; | |
| display: flex; | |
| justify-content: space-between; | |
| } | |
| .status-value-highlight { | |
| color: #00ffff; | |
| font-weight: bold; | |
| } | |
| .text-green { | |
| color: #4ade80 !important; | |
| font-weight: bold; | |
| } | |
| .text-blue { | |
| color: #60a5fa !important; | |
| font-weight: bold; | |
| } | |
| .avatar-desk-area { | |
| text-align: center; | |
| padding: 10px 0; | |
| } | |
| .pixel-avatar { | |
| font-size: 42px; | |
| animation: pixel-bounce 1.2s infinite alternate; | |
| display: inline-block; | |
| } | |
| .pixel-desk { | |
| background-color: #5c3a21; | |
| border: 2px solid #3d2514; | |
| border-radius: 4px; | |
| padding: 6px; | |
| margin-top: 5px; | |
| color: #ffffff; | |
| font-size: 11px; | |
| font-weight: bold; | |
| } | |
| @keyframes pixel-bounce { | |
| 0% { transform: translateY(0); } | |
| 100% { transform: translateY(-6px); } | |
| } | |
| .room-cat { | |
| position: absolute; | |
| bottom: 15px; | |
| left: 45%; | |
| font-size: 26px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ===================================================================== | |
| # 2. SESSION STATE ENGINE (ระบบควบคุมหน่วยความจำพอร์ต) | |
| # ===================================================================== | |
| if "live_equity" not in st.session_state: | |
| st.session_state.live_equity = 20882.27 | |
| if "spread_val" not in st.session_state: | |
| st.session_state.spread_val = 3.502 | |
| st.session_state.live_equity += random.uniform(-4.5, 6.5) | |
| st.session_state.spread_val += random.uniform(-0.01, 0.01) | |
| # ===================================================================== | |
| # 3. DYNAMIC DATA INTEGRATION (ตัวแปรเก็บสถิติตลาด) | |
| # ===================================================================== | |
| agent_01_name = "Quant_3Zone_v2.7.2" | |
| agent_01_win_rate = 57.97 | |
| agent_01_target = 93.3 | |
| agent_01_status = "WAIT / In Range" | |
| agent_02_name = "CRO_Firewall_v3.1" | |
| agent_02_risk_load = 1.15 | |
| agent_02_status = "Secure" | |
| # ===================================================================== | |
| # 4. SIDEBAR IMPLEMENTATION (แถบควบคุมฝั่งซ้าย) | |
| # ===================================================================== | |
| with st.sidebar: | |
| st.markdown('<div class="sidebar-title">🌐 Trading Office</div>', unsafe_allow_html=True) | |
| st.markdown('<div class="sidebar-subtitle">Realtime bot command center</div>', unsafe_allow_html=True) | |
| st.markdown('<div class="sidebar-section-title">Active Project</div>', unsafe_allow_html=True) | |
| st.markdown("🟢 **Spread Grid** <br><span style='color:#6b7280; font-size:11px;'>XAUUSD / PURE-QUANT</span>", unsafe_allow_html=True) | |
| st.markdown('<div class="sidebar-section-title">Account Status</div>', unsafe_allow_html=True) | |
| st.markdown(f""" | |
| <div class="sidebar-metric-box"> | |
| <div class="sidebar-metric-label">Equity (ยอดเงินรวม)</div> | |
| <div class="sidebar-metric-value">${st.session_state.live_equity:,.2f}</div> | |
| </div> | |
| <div class="sidebar-metric-box"> | |
| <div class="sidebar-metric-label">Long Spread</div> | |
| <div class="sidebar-metric-value" style="color:#00ffff;">{st.session_state.spread_val:.3f}</div> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| st.markdown('<div class="sidebar-section-title">Active Services</div>', unsafe_allow_html=True) | |
| st.markdown("• 🛠️ **Trader:** `Order path only` <br>• 🗄️ **Recorder:** `Trade file connected`", unsafe_allow_html=True) | |
| st.markdown('<div class="sidebar-section-title">Monitored Symbols</div>', unsafe_allow_html=True) | |
| st.write("`XAUUSD.iux` | `BRENTOIL` | `WTI`") | |
| # ===================================================================== | |
| # 5. TOP NAVIGATION BAR (แถบเมนูส่วนบน) | |
| # ===================================================================== | |
| st.markdown(""" | |
| <div class="top-navbar"> | |
| <div class="top-nav-tabs"> | |
| <div class="top-nav-tab">Dashboard</div> | |
| <div class="top-nav-tab active">AI Agents</div> | |
| <div class="top-nav-tab">Trades</div> | |
| <div class="top-nav-tab">Analytics</div> | |
| <div class="top-nav-tab">Risk</div> | |
| </div> | |
| <div style="display: flex; gap: 10px; align-items: center;"> | |
| <span style="font-size: 11px; background-color: #14532d; color: #4ade80; padding: 4px 8px; border-radius: 4px;">● 2/2 Bots Running</span> | |
| </div> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # ===================================================================== | |
| # 6. MAIN CAFE CANVAS WORKSPACE (โซนห้องทำงานร้านกาแฟพิกเซล) | |
| # ===================================================================== | |
| st.markdown('<div class="cafe-container">', unsafe_allow_html=True) | |
| st.markdown('<div class="cafe-window">🌳</div>', unsafe_allow_html=True) | |
| st.markdown('<div class="coffee-shelf">☕ 🏺 ☕ ☕</div>', unsafe_allow_html=True) | |
| st.markdown(f""" | |
| <div class="workstation-wrapper"> | |
| <div class="agent-workstation"> | |
| <div class="floating-status-card"> | |
| <div class="status-badge">RUNNING</div> | |
| <div class="status-line"><span>Agent:</span> <span class="status-value-highlight">{agent_01_name}</span></div> | |
| <div class="status-line"><span>Mid Spread:</span> <span>{st.session_state.spread_val:.3f}</span></div> | |
| <div class="status-line"><span>Win Rate / Target:</span> <span>{agent_01_win_rate}% / {agent_01_target}%</span></div> | |
| <div class="status-line"><span>Trade:</span> <span class="text-green">{agent_01_status}</span></div> | |
| </div> | |
| <div class="avatar-desk-area"> | |
| <div class="pixel-avatar">👨💻</div> | |
| <div class="pixel-desk">🗲 WORKSTATION_01</div> | |
| </div> | |
| </div> | |
| <div class="agent-workstation"> | |
| <div class="floating-status-card" style="border-color: #00ffff;"> | |
| <div class="status-badge" style="background-color: #1e3a8a; color: #60a5fa;">MONITOR</div> | |
| <div class="status-line"><span>Agent:</span> <span class="status-value-highlight">{agent_02_name}</span></div> | |
| <div class="status-line"><span>Risk Lot Size:</span> <span>{agent_02_risk_load}% (Max 2%)</span></div> | |
| <div class="status-line"><span>Account Equity:</span> <span class="text-green">{agent_02_status}</span></div> | |
| <div class="status-line"><span>Last Update:</span> <span>Realtime</span></div> | |
| </div> | |
| <div class="avatar-desk-area"> | |
| <div class="pixel-avatar">👩💻</div> | |
| <div class="pixel-desk">🛡️ RISK_FIREWALL_02</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="room-cat">🐈</div> | |
| """, unsafe_allow_html=True) | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # ===================================================================== | |
| # 7. QUICK CONTROLLER MANUAL (แผงควบคุมระบบด้านล่างสุด) | |
| # ===================================================================== | |
| st.write("") | |
| control_col1, control_col2, control_col3 = st.columns([1, 1, 2]) | |
| with control_col1: | |
| if st.button("▶ START SYSTEM ALL BOTS"): | |
| st.toast("ส่งสัญญานวิทยุเปิดคอมพิวเตอร์ให้เอเจ้นท์เริ่มต้นรันไทม์!") | |
| with control_col2: | |
| if st.button("🛑 EMERGENCY SHUTDOWN"): | |
| st.toast("Risk Firewall สั่งตัดไฟพอร์ตและระเบิดสัญญาทั้งหมดชั่วคราวเพื่อเซฟวงเงินทุน!") | |
| with control_col3: | |
| st.caption("📟 *ระบบทำการเคลียร์ปีกกาหลอนและซ่อมรอยรั่วสไตล์ลิ่งหน้าจอเรียบร้อยแล้ว ปลอดภัยตามเกณฑ์มาตรฐาน Docker App*") |