Mert99 commited on
Commit
612851f
·
verified ·
1 Parent(s): 2965e06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -28
app.py CHANGED
@@ -21,39 +21,23 @@ def predict(context_str, prediction_length):
21
  return "Error: Model yüklenemedi."
22
 
23
  try:
24
- # 1. Veriyi Parçala
25
- series_strings = context_str.split('|')
26
- tensor_list = []
27
 
28
- for s in series_strings:
29
- clean_s = s.strip()
30
- if not clean_s: continue
31
- # Veriyi listeye çevir
32
- data_list = [float(x) for x in clean_s.split(',')]
33
- tensor_list.append(data_list)
34
 
35
- if not tensor_list: return "Error: Veri boş."
36
-
37
- # 2. Tensor Oluştur (Batch, Variates, Time)
38
- # Örn: (1, 5, 200)
39
- context_tensor = torch.tensor(tensor_list).unsqueeze(0)
40
 
41
- # --- KRİTİK KONTROL ---
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
- # 4. Sonucu Al
51
- # Chronos-2 çok değişkenli tahminde, her değişken için tahmin üretebilir.
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