Spaces:
Sleeping
Sleeping
Download src/app.py from wasawat07/AIMasterFX: direct link, hf CLI and curl.
- Browser
- Download file 14.5 kB
-
https://huggingface.co/spaces/wasawat07/AIMasterFX/resolve/main/src/app.py
- Command line
-
hf download hf://spaces/wasawat07/AIMasterFX/src/app.py
-
curl -L -o app.py https://huggingface.co/spaces/wasawat07/AIMasterFX/resolve/main/src/app.py
14.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; | |
| } | |
| /* ตัวละครและการจัดโมเดลโต๊ะคอมพิวเตอร์พิกเซล */ | |
| .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. APP STATE SIMULATION (ระบบจำลองค่าพลังในพอร์ต) | |
| # ===================================================================== | |
| 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 | |
| # สุ่มขยับราคาเล็กน้อยทุกครั้งที่กด Refresh เพื่อให้หน้าจอไม่นิ่งค้าง | |
| st.session_state.live_equity += random.uniform(-5.5, 7.5) | |
| st.session_state.spread_val += random.uniform(-0.02, 0.02) | |
| # ===================================================================== | |
| # 3. 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;'>BRENTOIL / WTI</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`") | |
| # ===================================================================== | |
| # 4. 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) | |
| # ===================================================================== | |
| # 5. MAIN CAFE CANVAS WORKSPACE (โซนห้องกาแฟเอเจ้นท์สั่งการ) | |
| # ===================================================================== | |
| # เริ่มต้นวาดกล่อง Canvas พื้นหลังร้านกาแฟสีอบอุ่นโทนไม้ | |
| 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(""" | |
| <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">Quant_3Zone_v2.6</span></div> | |
| <div class="status-line"><span>Mid Spread:</span> <span>3.485</span></div> | |
| <div class="status-line"><span>Current / Target:</span> <span>82.8% / 93.3%</span></div> | |
| <div class="status-line"><span>Trade:</span> <span style="color:#4ade80;">WAIT / In Range</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">CRO_Firewall_v3.1</span></div> | |
| <div class="status-line"><span>Risk Load:</span> <span>1.15% (Max 2%)</span></div> | |
| <div class="status-line"><span>Account Equity:</span> <span style="color:#4ade80;">Secure</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) | |
| # ปิดกล่อง Cafe Container คุมพื้นที่ทั้งหมด | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # ===================================================================== | |
| # 6. 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("📟 *ระบบแดชบอร์ดดึงความละเอียดพิกเซลอัตโนมัติจากไฟล์ประมวลผลบอทหลัก v2.6 และ v3.1 รองรับการโฮสต์บน Hugging Face Spaces 24 ชม.*") |