Riy777 commited on
Commit
0ffe2c1
·
verified ·
1 Parent(s): d408c93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # ==============================================================================
2
- # 🚀 app.py (V38.0 - GEM-Architect: Diagnostic Matrix Integration)
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 V38.0 - Diagnostics)...")
194
  try:
195
  # 1. الخدمات الأساسية
196
  r2 = R2Service()
@@ -536,7 +536,6 @@ async def reset_diagnostics_handler():
536
  # 🔥 زر تصفير إحصائيات الحراس
537
  async def reset_guardians_handler():
538
  await r2.reset_guardian_stats_async()
539
- # تحديث الذاكرة المحلية لمدير التجارة لتنعكس التغييرات فوراً
540
  if trade_manager:
541
  trade_manager.ai_stats = await r2.get_guardian_stats_async()
542
  return "✅ Guardian Stats Reset."
@@ -551,7 +550,7 @@ async def run_cycle_from_gradio():
551
  return "🚀 Launched."
552
 
553
  # ------------------------------------------------------------------------------
554
- # UI Updates (Updated for Diagnostics)
555
  # ------------------------------------------------------------------------------
556
  async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
557
  empty_chart = go.Figure()
@@ -743,18 +742,24 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
743
  </div>
744
  """
745
 
746
- # 🔥 جلب بيانات مصفوفة التشخيص (Diagnostic Matrix)
747
  diag_data = await r2.get_diagnostic_stats_async()
748
  diag_list = []
749
  ordered_models = ["Titan", "Patterns", "Oracle", "Sniper", "MonteCarlo_L", "MonteCarlo_A", "Governance"]
750
 
751
  for m in ordered_models:
752
  stats = diag_data.get(m, {"wins": 0, "losses": 0, "pnl": 0.0})
 
 
 
 
 
 
753
  diag_list.append([
754
  m,
755
  stats['wins'],
756
  stats['losses'],
757
- f"${stats['pnl']:.2f}"
758
  ])
759
 
760
  diag_df = pd.DataFrame(diag_list, columns=["Model", "Wins", "Losses", "PnL (USD)"])
@@ -809,10 +814,10 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
809
  def create_gradio_ui():
810
  custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
811
 
812
- with gr.Blocks(title="Titan V38.0 (Neural Dashboard)") as demo:
813
  gr.HTML(f"<style>{custom_css}</style>")
814
 
815
- gr.Markdown("# 🚀 Titan V38.0 (Cybernetic: Neural Dashboard)")
816
 
817
  with gr.Row():
818
  with gr.Column(scale=3):
@@ -829,11 +834,11 @@ def create_gradio_ui():
829
  wallet_out = gr.HTML(label="Smart Wallet", elem_classes="html-box")
830
  neural_out = gr.HTML(label="Neural Cycles", elem_classes="html-box")
831
 
832
- # 🔥 إضافة مصفوفة التشخيص الجديدة
833
  gr.Markdown("### 🕵️ Diagnostic Matrix")
834
  diagnostic_out = gr.Dataframe(
835
  headers=["Model", "Wins", "Losses", "PnL (USD)"],
836
- datatype=["str", "number", "number", "str"],
837
  interactive=False,
838
  label="Model Performance"
839
  )
 
1
  # ==============================================================================
2
+ # 🚀 app.py (V38.1 - GEM-Architect: Colored Diagnostics)
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 V38.1 - Colored Diagnostics)...")
194
  try:
195
  # 1. الخدمات الأساسية
196
  r2 = R2Service()
 
536
  # 🔥 زر تصفير إحصائيات الحراس
537
  async def reset_guardians_handler():
538
  await r2.reset_guardian_stats_async()
 
539
  if trade_manager:
540
  trade_manager.ai_stats = await r2.get_guardian_stats_async()
541
  return "✅ Guardian Stats Reset."
 
550
  return "🚀 Launched."
551
 
552
  # ------------------------------------------------------------------------------
553
+ # UI Updates (Updated for Diagnostics Coloring)
554
  # ------------------------------------------------------------------------------
555
  async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
556
  empty_chart = go.Figure()
 
742
  </div>
743
  """
744
 
745
+ # 🔥 جلب بيانات مصفوفة التشخيص وتلوينها
746
  diag_data = await r2.get_diagnostic_stats_async()
747
  diag_list = []
748
  ordered_models = ["Titan", "Patterns", "Oracle", "Sniper", "MonteCarlo_L", "MonteCarlo_A", "Governance"]
749
 
750
  for m in ordered_models:
751
  stats = diag_data.get(m, {"wins": 0, "losses": 0, "pnl": 0.0})
752
+ pnl_val = stats['pnl']
753
+
754
+ # 🎨 التلوين: أخضر للربح، أحمر للخسارة
755
+ color = "#00ff00" if pnl_val >= 0 else "#ff0000"
756
+ pnl_str = f"<span style='color: {color}; font-weight: bold;'>${pnl_val:+.2f}</span>"
757
+
758
  diag_list.append([
759
  m,
760
  stats['wins'],
761
  stats['losses'],
762
+ pnl_str
763
  ])
764
 
765
  diag_df = pd.DataFrame(diag_list, columns=["Model", "Wins", "Losses", "PnL (USD)"])
 
814
  def create_gradio_ui():
815
  custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
816
 
817
+ with gr.Blocks(title="Titan V38.1 (Neural Dashboard)") as demo:
818
  gr.HTML(f"<style>{custom_css}</style>")
819
 
820
+ gr.Markdown("# 🚀 Titan V38.1 (Cybernetic: Neural Dashboard)")
821
 
822
  with gr.Row():
823
  with gr.Column(scale=3):
 
834
  wallet_out = gr.HTML(label="Smart Wallet", elem_classes="html-box")
835
  neural_out = gr.HTML(label="Neural Cycles", elem_classes="html-box")
836
 
837
+ # 🔥 إضافة مصفوفة التشخيص الجديدة مع دعم HTML للألوان
838
  gr.Markdown("### 🕵️ Diagnostic Matrix")
839
  diagnostic_out = gr.Dataframe(
840
  headers=["Model", "Wins", "Losses", "PnL (USD)"],
841
+ datatype=["str", "number", "number", "html"], # ✅ html لتفعيل الألوان
842
  interactive=False,
843
  label="Model Performance"
844
  )