Update app.py
Browse files
app.py
CHANGED
|
@@ -21,39 +21,23 @@ def predict(context_str, prediction_length):
|
|
| 21 |
return "Error: Model yüklenemedi."
|
| 22 |
|
| 23 |
try:
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
tensor_list = []
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
data_list = [float(x) for x in clean_s.split(',')]
|
| 33 |
-
tensor_list.append(data_list)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
# Örn: (1, 5, 200)
|
| 39 |
-
context_tensor = torch.tensor(tensor_list).unsqueeze(0)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
# Eğer veri çok büyük veya çok küçükse (Outlier), model sapıtabilir.
|
| 43 |
-
# Fiyat verisi (ilk seri) 0 olmamalı.
|
| 44 |
-
if context_tensor[0, 0, -1] == 0:
|
| 45 |
-
return "Error: Son fiyat 0 olamaz."
|
| 46 |
-
|
| 47 |
-
# 3. Tahmin Yap
|
| 48 |
forecast = pipeline.predict(context_tensor, int(prediction_length))
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
# Bizim hedefimiz FİYAT (0. indeks)
|
| 53 |
-
price_forecast = forecast[0] # İlk seri (Fiyat)
|
| 54 |
-
|
| 55 |
-
# Medyanı al
|
| 56 |
-
future_price = price_forecast.quantile(0.5).item()
|
| 57 |
|
| 58 |
return str(future_price)
|
| 59 |
|
|
|
|
| 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 |
+
# Sonucu Al
|
| 40 |
+
future_price = forecast[0].quantile(0.5).item()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
return str(future_price)
|
| 43 |
|