Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -127,33 +127,34 @@ def predict_eurusd():
|
|
| 127 |
next_day_preds, ensemble_pred = predict_next_day(models, scaler, df, feature_cols)
|
| 128 |
|
| 129 |
# Mevcut fiyat
|
| 130 |
-
current_price = df['Close'].iloc[-1]
|
| 131 |
|
| 132 |
# Sonuçları hazırla
|
| 133 |
-
result = f"""
|
| 134 |
-
🔄 **GÜNCELLEME ZAMANI:** {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
| 135 |
|
| 136 |
-
📊
|
| 137 |
|
| 138 |
-
🎯
|
| 139 |
|
| 140 |
"""
|
| 141 |
|
| 142 |
for model_name, pred in next_day_preds.items():
|
| 143 |
-
|
|
|
|
| 144 |
arrow = "📈" if change > 0 else "📉"
|
| 145 |
-
result += f"{arrow}
|
| 146 |
|
| 147 |
-
|
|
|
|
| 148 |
ensemble_arrow = "📈" if ensemble_change > 0 else "📉"
|
| 149 |
|
| 150 |
-
result += f"\n{ensemble_arrow}
|
| 151 |
|
| 152 |
# Model performansları
|
| 153 |
-
result += f"\n\n📈
|
| 154 |
for i, (model_name, preds) in enumerate(test_predictions.items()):
|
| 155 |
-
mse = np.mean((preds - y_test) ** 2)
|
| 156 |
-
mae = np.mean(np.abs(preds - y_test))
|
| 157 |
result += f"• {model_name}: MAE={mae:.5f}, MSE={mse:.8f}\n"
|
| 158 |
|
| 159 |
# Grafik için veri hazırla
|
|
@@ -162,18 +163,19 @@ def predict_eurusd():
|
|
| 162 |
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10))
|
| 163 |
|
| 164 |
# Üst grafik: Fiyat geçmişi
|
| 165 |
-
|
|
|
|
| 166 |
ax1.axhline(y=current_price, color='gray', linestyle='--', alpha=0.5, label='Mevcut Fiyat')
|
| 167 |
-
ax1.axhline(y=
|
| 168 |
ax1.set_title('EUR/USD Son 30 Gün Fiyat Hareketi', fontsize=14, fontweight='bold')
|
| 169 |
-
ax1.set_xlabel('
|
| 170 |
ax1.set_ylabel('Fiyat')
|
| 171 |
ax1.legend()
|
| 172 |
ax1.grid(True, alpha=0.3)
|
| 173 |
|
| 174 |
# Alt grafik: Model tahminleri karşılaştırması
|
| 175 |
model_names = list(next_day_preds.keys())
|
| 176 |
-
model_values =
|
| 177 |
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8']
|
| 178 |
|
| 179 |
bars = ax2.barh(model_names, model_values, color=colors)
|
|
@@ -194,7 +196,9 @@ def predict_eurusd():
|
|
| 194 |
return result, fig
|
| 195 |
|
| 196 |
except Exception as e:
|
| 197 |
-
|
|
|
|
|
|
|
| 198 |
|
| 199 |
# Gradio arayüzü
|
| 200 |
with gr.Blocks(title="EUR/USD Fiyat Tahmini", theme=gr.themes.Soft()) as app:
|
|
@@ -234,4 +238,3 @@ with gr.Blocks(title="EUR/USD Fiyat Tahmini", theme=gr.themes.Soft()) as app:
|
|
| 234 |
|
| 235 |
if __name__ == "__main__":
|
| 236 |
app.launch()
|
| 237 |
-
|
|
|
|
| 127 |
next_day_preds, ensemble_pred = predict_next_day(models, scaler, df, feature_cols)
|
| 128 |
|
| 129 |
# Mevcut fiyat
|
| 130 |
+
current_price = float(df['Close'].iloc[-1])
|
| 131 |
|
| 132 |
# Sonuçları hazırla
|
| 133 |
+
result = f"""🔄 GÜNCELLEME ZAMANI: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
|
|
| 134 |
|
| 135 |
+
📊 MEVCUT EUR/USD FİYATI: {current_price:.5f}
|
| 136 |
|
| 137 |
+
🎯 ERTESİ GÜN TAHMİNLERİ:
|
| 138 |
|
| 139 |
"""
|
| 140 |
|
| 141 |
for model_name, pred in next_day_preds.items():
|
| 142 |
+
pred_value = float(pred)
|
| 143 |
+
change = ((pred_value - current_price) / current_price) * 100
|
| 144 |
arrow = "📈" if change > 0 else "📉"
|
| 145 |
+
result += f"{arrow} {model_name}: {pred_value:.5f} ({change:+.2f}%)\n"
|
| 146 |
|
| 147 |
+
ensemble_pred_value = float(ensemble_pred)
|
| 148 |
+
ensemble_change = ((ensemble_pred_value - current_price) / current_price) * 100
|
| 149 |
ensemble_arrow = "📈" if ensemble_change > 0 else "📉"
|
| 150 |
|
| 151 |
+
result += f"\n{ensemble_arrow} 🏆 ENSEMBLE ORTALAMA: {ensemble_pred_value:.5f} ({ensemble_change:+.2f}%)\n"
|
| 152 |
|
| 153 |
# Model performansları
|
| 154 |
+
result += f"\n\n📈 MODEL PERFORMANSLARI (Son 5 Gün):\n"
|
| 155 |
for i, (model_name, preds) in enumerate(test_predictions.items()):
|
| 156 |
+
mse = float(np.mean((preds - y_test) ** 2))
|
| 157 |
+
mae = float(np.mean(np.abs(preds - y_test)))
|
| 158 |
result += f"• {model_name}: MAE={mae:.5f}, MSE={mse:.8f}\n"
|
| 159 |
|
| 160 |
# Grafik için veri hazırla
|
|
|
|
| 163 |
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10))
|
| 164 |
|
| 165 |
# Üst grafik: Fiyat geçmişi
|
| 166 |
+
last_30_days = df.tail(30)
|
| 167 |
+
ax1.plot(range(len(last_30_days)), last_30_days['Close'].values, label='Gerçek Fiyat', linewidth=2)
|
| 168 |
ax1.axhline(y=current_price, color='gray', linestyle='--', alpha=0.5, label='Mevcut Fiyat')
|
| 169 |
+
ax1.axhline(y=ensemble_pred_value, color='red', linestyle='--', alpha=0.7, label='Tahmin')
|
| 170 |
ax1.set_title('EUR/USD Son 30 Gün Fiyat Hareketi', fontsize=14, fontweight='bold')
|
| 171 |
+
ax1.set_xlabel('Gün')
|
| 172 |
ax1.set_ylabel('Fiyat')
|
| 173 |
ax1.legend()
|
| 174 |
ax1.grid(True, alpha=0.3)
|
| 175 |
|
| 176 |
# Alt grafik: Model tahminleri karşılaştırması
|
| 177 |
model_names = list(next_day_preds.keys())
|
| 178 |
+
model_values = [float(v) for v in next_day_preds.values()]
|
| 179 |
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8']
|
| 180 |
|
| 181 |
bars = ax2.barh(model_names, model_values, color=colors)
|
|
|
|
| 196 |
return result, fig
|
| 197 |
|
| 198 |
except Exception as e:
|
| 199 |
+
import traceback
|
| 200 |
+
error_msg = f"❌ Hata oluştu: {str(e)}\n\n{traceback.format_exc()}"
|
| 201 |
+
return error_msg, None
|
| 202 |
|
| 203 |
# Gradio arayüzü
|
| 204 |
with gr.Blocks(title="EUR/USD Fiyat Tahmini", theme=gr.themes.Soft()) as app:
|
|
|
|
| 238 |
|
| 239 |
if __name__ == "__main__":
|
| 240 |
app.launch()
|
|
|