Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -373,7 +373,8 @@ def mutate_agent(symbol, timeframe, success=True):
|
|
| 373 |
except Exception as e: print(f"🧬 Erreur Mutation : {e}")
|
| 374 |
|
| 375 |
# --- 🧠 TRAINING ENGINE ---
|
| 376 |
-
|
|
|
|
| 377 |
try:
|
| 378 |
print(f"⚙️ Tentative d'entraînement pour {symbol}...")
|
| 379 |
memory_guard()
|
|
@@ -384,15 +385,51 @@ def trigger_training(symbol="SOL/USD"):
|
|
| 384 |
df_final = prepare_features_sync(symbol, '1h', limit_bars=1000)
|
| 385 |
if df_final.empty or len(df_final) < 100: return f"❌ Données vides après indicateurs."
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
global ml_model, time_model
|
| 392 |
ml_model, time_model = joblib.load("ml_model_v9.pkl"), joblib.load("time_model.pkl")
|
| 393 |
gc.collect()
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
| 396 |
|
| 397 |
# --- 🚀 MOTEUR AUTO-PILOTE & DREAM MODE ---
|
| 398 |
AUTO_SYMBOLS = ["BTC/USD", "ETH/USD"]
|
|
|
|
| 373 |
except Exception as e: print(f"🧬 Erreur Mutation : {e}")
|
| 374 |
|
| 375 |
# --- 🧠 TRAINING ENGINE ---
|
| 376 |
+
# --- 🧠 TRAINING ENGINE ---
|
| 377 |
+
def trigger_training(symbol="BTC/USD"):
|
| 378 |
try:
|
| 379 |
print(f"⚙️ Tentative d'entraînement pour {symbol}...")
|
| 380 |
memory_guard()
|
|
|
|
| 385 |
df_final = prepare_features_sync(symbol, '1h', limit_bars=1000)
|
| 386 |
if df_final.empty or len(df_final) < 100: return f"❌ Données vides après indicateurs."
|
| 387 |
|
| 388 |
+
# 1. Entraînement des vieux modèles (Fallback de sécurité)
|
| 389 |
+
try:
|
| 390 |
+
from ml_model import train_model as train_ml
|
| 391 |
+
from time_model import train_time_model as train_time
|
| 392 |
+
train_ml(df_final); train_time(df_final)
|
| 393 |
+
except Exception as e: print(f"⚠️ Erreur Classique: {e}")
|
| 394 |
+
|
| 395 |
+
# 2. 🦖 ENTRAÎNEMENT DU DINOSAURE (LightGBM)
|
| 396 |
+
if LGBM_AVAILABLE:
|
| 397 |
+
print("🦖 [V30] Forgeage du Cerveau LightGBM en cours...")
|
| 398 |
+
ml_cols = ["RSI", "Dist_High_24h", "Dist_Low_24h", "EMA_dist", "EMA_slope", "ATR_ratio", "VOL_ratio"]
|
| 399 |
+
|
| 400 |
+
# On crée la cible (la prochaine bougie sera-t-elle verte ?)
|
| 401 |
+
df_final['Target'] = (df_final['close'].shift(-1) > df_final['close']).astype(int)
|
| 402 |
+
df_train = df_final.dropna(subset=ml_cols + ['Target'])
|
| 403 |
+
|
| 404 |
+
X = df_train[ml_cols]
|
| 405 |
+
y = df_train['Target']
|
| 406 |
+
|
| 407 |
+
params = {
|
| 408 |
+
'objective': 'binary',
|
| 409 |
+
'metric': 'binary_logloss',
|
| 410 |
+
'boosting_type': 'gbdt',
|
| 411 |
+
'learning_rate': 0.05,
|
| 412 |
+
'num_leaves': 31,
|
| 413 |
+
'verbose': -1
|
| 414 |
+
}
|
| 415 |
+
dtrain = lgb.Dataset(X, label=y)
|
| 416 |
+
|
| 417 |
+
# Entraînement ultra-rapide
|
| 418 |
+
model = lgb.train(params, dtrain, 100)
|
| 419 |
+
model.save_model('dino_lgbm_model.txt')
|
| 420 |
+
|
| 421 |
+
global dino_brain
|
| 422 |
+
dino_brain = lgb.Booster(model_file='dino_lgbm_model.txt')
|
| 423 |
+
print("✅ [V30] Cerveau LightGBM créé, sauvegardé et injecté !")
|
| 424 |
+
|
| 425 |
+
# Rechargement des vieux modèles en mémoire globale
|
| 426 |
global ml_model, time_model
|
| 427 |
ml_model, time_model = joblib.load("ml_model_v9.pkl"), joblib.load("time_model.pkl")
|
| 428 |
gc.collect()
|
| 429 |
+
|
| 430 |
+
return f"✅ IA ré-entraînée avec succès (T-Rex en ligne !)."
|
| 431 |
+
except Exception as e:
|
| 432 |
+
return f"❌ Erreur Training : {e}"
|
| 433 |
|
| 434 |
# --- 🚀 MOTEUR AUTO-PILOTE & DREAM MODE ---
|
| 435 |
AUTO_SYMBOLS = ["BTC/USD", "ETH/USD"]
|