Riy777 commited on
Commit
a488c30
·
verified ·
1 Parent(s): 09cd0b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # ==============================================================================
2
- # 🚀 app.py (V36.3 - GEM-Architect: Neural Dashboard)
3
  # ==============================================================================
4
 
5
  import os
@@ -190,7 +190,7 @@ async def auto_pilot_loop():
190
  async def lifespan(app: FastAPI):
191
  global r2, data_manager, ml_processor, adaptive_hub, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state, scheduler
192
 
193
- logger.info("\n🚀 [System] Startup Sequence (Titan V36.3 - Neural Dashboard)...")
194
  try:
195
  # 1. الخدمات الأساسية
196
  r2 = R2Service()
@@ -413,10 +413,11 @@ async def run_unified_cycle():
413
  f"{status_str}"
414
  )
415
 
416
- # LAYER 4: Sniper Execution
417
  if approved_signals:
418
  log_and_print("-" * 110)
419
- log_and_print(f" [4/5] 🎯 L4 Sniper & Portfolio Check ({len(approved_signals)} candidates)...")
 
420
  tm_log_buffer = StringIO()
421
 
422
  with redirect_stdout(tm_log_buffer), redirect_stderr(tm_log_buffer):
@@ -516,7 +517,7 @@ async def run_cycle_from_gradio():
516
  return "🚀 Launched."
517
 
518
  # ------------------------------------------------------------------------------
519
- # UI Updates
520
  # ------------------------------------------------------------------------------
521
  async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
522
  empty_chart = go.Figure()
@@ -547,20 +548,37 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
547
  tp_p = float(trade.get('tp_price', 0.0))
548
  sl_p = float(trade.get('sl_price', 0.0))
549
  trade_dur_str = calculate_duration_str(trade.get('entry_time'))
550
- sys_conf = trade.get('decision_data', {}).get('system_confidence', 0.0)
551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
  curr_p = await data_manager.get_latest_price_async(symbol)
553
  if curr_p > 0 and entry_p > 0:
554
  pnl_pct = ((curr_p - entry_p) / entry_p) * 100
555
  size = float(trade.get('entry_capital', 0.0))
556
  pnl_val_unrealized = size * (pnl_pct / 100)
557
-
 
558
  active_trade_info = f"""
 
 
 
559
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:5px;'>
560
- <span>{symbol}:</span> <span style='color: #ffff00;'>{trade_dur_str}</span>
561
  </div>
562
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:5px;'>
563
- <span>🔮 Conf:</span> <span style='color: #00e5ff;'>{sys_conf:.1%}</span>
564
  </div>
565
  """
566
 
@@ -582,7 +600,7 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
582
 
583
  wallet_md = f"""
584
  <div style='background-color: #1a1a1a; padding: 15px; border-radius: 8px; border: 1px solid #333; text-align:center;'>
585
- <h3 style='margin:0; color:#888; font-size:14px;'>💼 Smart Portfolio</h3>
586
  <div style='font-size: 24px; font-weight: bold; color: white; margin: 5px 0 0 0;'>${virtual_equity:,.2f}</div>
587
  <div style='font-size: 14px; color: {active_pnl_color}; margin-bottom: 5px;'>({active_trade_pnl_val:+,.2f} USD)</div>
588
 
@@ -595,7 +613,7 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
595
  <hr style='border-color:#444; margin: 10px 0;'>
596
 
597
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc;'>
598
- <span>🦅 Market:</span> <span style='color: white;'>{market_mood} ({fg_index})</span>
599
  </div>
600
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:3px;'>
601
  <span>🧬 Regime:</span> <span style='color: #00e5ff; font-weight:bold;'>{current_regime}</span>
@@ -640,7 +658,6 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
640
  </div>
641
  """
642
 
643
- # --- 🧠 Neural Cycles Status Construction ---
644
  fast_learn_prog = "0/100"
645
  if adaptive_hub:
646
  if hasattr(adaptive_hub, 'get_learning_progress'):
@@ -740,10 +757,10 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
740
  def create_gradio_ui():
741
  custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
742
 
743
- with gr.Blocks(title="Titan V36.3 (Neural Dashboard)") as demo:
744
  gr.HTML(f"<style>{custom_css}</style>")
745
 
746
- gr.Markdown("# 🚀 Titan V36.3 (Cybernetic: Neural Dashboard)")
747
 
748
  with gr.Row():
749
  with gr.Column(scale=3):
 
1
  # ==============================================================================
2
+ # 🚀 app.py (V37.0 - GEM-Architect: Neural Dashboard + Governance UI)
3
  # ==============================================================================
4
 
5
  import os
 
190
  async def lifespan(app: FastAPI):
191
  global r2, data_manager, ml_processor, adaptive_hub, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state, scheduler
192
 
193
+ logger.info("\n🚀 [System] Startup Sequence (Titan V37.0 - Neural Dashboard)...")
194
  try:
195
  # 1. الخدمات الأساسية
196
  r2 = R2Service()
 
413
  f"{status_str}"
414
  )
415
 
416
+ # LAYER 4: Sniper & Governance & Execution
417
  if approved_signals:
418
  log_and_print("-" * 110)
419
+ # تحديث النص ليعكس وجود الحوكمة
420
+ log_and_print(f" [4/5] 🎯 L4 Sniper -> 🏛️ Governance -> 💰 Portfolio ({len(approved_signals)} candidates)...")
421
  tm_log_buffer = StringIO()
422
 
423
  with redirect_stdout(tm_log_buffer), redirect_stderr(tm_log_buffer):
 
517
  return "🚀 Launched."
518
 
519
  # ------------------------------------------------------------------------------
520
+ # UI Updates (Modified for Governance)
521
  # ------------------------------------------------------------------------------
522
  async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
523
  empty_chart = go.Figure()
 
548
  tp_p = float(trade.get('tp_price', 0.0))
549
  sl_p = float(trade.get('sl_price', 0.0))
550
  trade_dur_str = calculate_duration_str(trade.get('entry_time'))
 
551
 
552
+ # ✅ استخراج بيانات الحوكمة والقرار
553
+ decision_data = trade.get('decision_data', {})
554
+ gov_grade = decision_data.get('governance_grade', 'N/A')
555
+ gov_score = decision_data.get('governance_score', 0.0)
556
+ sys_conf = decision_data.get('system_confidence', 0.0)
557
+
558
+ # تلوين الرتبة حسب الجودة
559
+ grade_color = "#ccc"
560
+ if gov_grade == "ULTRA": grade_color = "#ff00ff" # Magenta
561
+ elif gov_grade == "STRONG": grade_color = "#00ff00" # Green
562
+ elif gov_grade == "NORMAL": grade_color = "#00e5ff" # Cyan
563
+ elif gov_grade == "WEAK": grade_color = "#ffff00" # Yellow
564
+ elif gov_grade == "REJECT": grade_color = "#ff0000" # Red
565
+
566
  curr_p = await data_manager.get_latest_price_async(symbol)
567
  if curr_p > 0 and entry_p > 0:
568
  pnl_pct = ((curr_p - entry_p) / entry_p) * 100
569
  size = float(trade.get('entry_capital', 0.0))
570
  pnl_val_unrealized = size * (pnl_pct / 100)
571
+
572
+ # عرض البيانات الجديدة في الواجهة
573
  active_trade_info = f"""
574
+ <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:5px; border-top: 1px solid #333; padding-top: 5px;'>
575
+ <span>⏱️ Time:</span> <span style='color: #ffff00;'>{trade_dur_str}</span>
576
+ </div>
577
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:5px;'>
578
+ <span>🏛Gov Grade:</span> <span style='color: {grade_color}; font-weight:bold;'>{gov_grade} ({gov_score:.1f})</span>
579
  </div>
580
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:5px;'>
581
+ <span>🔮 System Conf:</span> <span style='color: #00e5ff;'>{sys_conf:.1%}</span>
582
  </div>
583
  """
584
 
 
600
 
601
  wallet_md = f"""
602
  <div style='background-color: #1a1a1a; padding: 15px; border-radius: 8px; border: 1px solid #333; text-align:center;'>
603
+ <h3 style='margin:0; color:#888; font-size:14px;'>💼 Institutional Portfolio</h3>
604
  <div style='font-size: 24px; font-weight: bold; color: white; margin: 5px 0 0 0;'>${virtual_equity:,.2f}</div>
605
  <div style='font-size: 14px; color: {active_pnl_color}; margin-bottom: 5px;'>({active_trade_pnl_val:+,.2f} USD)</div>
606
 
 
613
  <hr style='border-color:#444; margin: 10px 0;'>
614
 
615
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc;'>
616
+ <span>🦅 Mood:</span> <span style='color: white;'>{market_mood} ({fg_index})</span>
617
  </div>
618
  <div style='display: flex; justify-content: space-between; font-size: 12px; color: #ccc; margin-top:3px;'>
619
  <span>🧬 Regime:</span> <span style='color: #00e5ff; font-weight:bold;'>{current_regime}</span>
 
658
  </div>
659
  """
660
 
 
661
  fast_learn_prog = "0/100"
662
  if adaptive_hub:
663
  if hasattr(adaptive_hub, 'get_learning_progress'):
 
757
  def create_gradio_ui():
758
  custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
759
 
760
+ with gr.Blocks(title="Titan V37.0 (Neural Dashboard)") as demo:
761
  gr.HTML(f"<style>{custom_css}</style>")
762
 
763
+ gr.Markdown("# 🚀 Titan V37.0 (Cybernetic: Neural Dashboard)")
764
 
765
  with gr.Row():
766
  with gr.Column(scale=3):