Update app.py
Browse files
app.py
CHANGED
|
@@ -17,29 +17,26 @@ except Exception as e:
|
|
| 17 |
pipeline = None
|
| 18 |
|
| 19 |
def predict(context_str, prediction_length):
|
| 20 |
-
if pipeline is None:
|
| 21 |
-
return "Error: Model yüklenemedi."
|
| 22 |
|
| 23 |
try:
|
| 24 |
-
# DÜZELTME: Artık '|' ile ayrılmış karmaşık veri beklemiyoruz.
|
| 25 |
-
# Sadece virgülle ayrılmış Fiyat verisi alacağız.
|
| 26 |
-
|
| 27 |
clean_s = context_str.strip()
|
| 28 |
if not clean_s: return "Error: Veri boş."
|
| 29 |
|
| 30 |
data_list = [float(x) for x in clean_s.split(',')]
|
| 31 |
-
|
| 32 |
-
# Tensor Oluştur (Batch=1, Series=1, Time=Len)
|
| 33 |
-
# (1, 1, 200) -> En saf ve hatasız format budur.
|
| 34 |
context_tensor = torch.tensor(data_list).unsqueeze(0).unsqueeze(0)
|
| 35 |
|
| 36 |
# Tahmin Yap
|
| 37 |
forecast = pipeline.predict(context_tensor, int(prediction_length))
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error: {str(e)}"
|
|
|
|
| 17 |
pipeline = None
|
| 18 |
|
| 19 |
def predict(context_str, prediction_length):
|
| 20 |
+
if pipeline is None: return "Error: Model yüklenemedi."
|
|
|
|
| 21 |
|
| 22 |
try:
|
|
|
|
|
|
|
|
|
|
| 23 |
clean_s = context_str.strip()
|
| 24 |
if not clean_s: return "Error: Veri boş."
|
| 25 |
|
| 26 |
data_list = [float(x) for x in clean_s.split(',')]
|
|
|
|
|
|
|
|
|
|
| 27 |
context_tensor = torch.tensor(data_list).unsqueeze(0).unsqueeze(0)
|
| 28 |
|
| 29 |
# Tahmin Yap
|
| 30 |
forecast = pipeline.predict(context_tensor, int(prediction_length))
|
| 31 |
|
| 32 |
+
# 1. MEDYAN (Beklenen Değer) - 0.5
|
| 33 |
+
median_price = forecast[0].quantile(0.5).item()
|
| 34 |
+
|
| 35 |
+
# 2. ALT SINIR (Kötü Senaryo) - 0.1 (%10'luk dilim)
|
| 36 |
+
lower_price = forecast[0].quantile(0.1).item()
|
| 37 |
|
| 38 |
+
# İkisini '|' ile birleştirip gönder
|
| 39 |
+
return f"{median_price}|{lower_price}"
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
return f"Error: {str(e)}"
|