Mert99 commited on
Commit
9f79640
·
verified ·
1 Parent(s): b84b83c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -9,7 +9,7 @@ try:
9
  pipeline = Chronos2Pipeline.from_pretrained(
10
  "amazon/chronos-2",
11
  device_map="cpu",
12
- dtype=torch.float32,
13
  )
14
  print("✅ Model Başarıyla Yüklendi!")
15
  except Exception as e:
@@ -17,32 +17,30 @@ except Exception as 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
  data_list = [float(x) for x in clean_s.split(',')]
26
 
27
- # Tensor Oluştur
28
  context_tensor = torch.tensor(data_list).unsqueeze(0).unsqueeze(0)
29
 
30
  # Tahmin Yap
31
  forecast = pipeline.predict(context_tensor, int(prediction_length))
32
 
33
- # --- ÇIKTI FORMATI: Medyan | Alt Sınır | Üst Sınır ---
34
- # 0.5: Medyan (Beklenen)
35
- # 0.1: Alt Sınır (Kötü Senaryo)
36
- # 0.9: Üst Sınır (İyi Senaryo)
37
 
38
- median_price = forecast[0].quantile(0.5).item()
39
- lower_price = forecast[0].quantile(0.1).item()
40
- upper_price = forecast[0].quantile(0.9).item()
41
-
42
- return f"{median_price}|{lower_price}|{upper_price}"
43
 
44
  except Exception as e:
45
  return f"Error: {str(e)}"
46
 
 
 
47
  iface = gr.Interface(fn=predict, inputs=["text", "number"], outputs="text")
48
  iface.launch()
 
9
  pipeline = Chronos2Pipeline.from_pretrained(
10
  "amazon/chronos-2",
11
  device_map="cpu",
12
+ torch_dtype=torch.float32,
13
  )
14
  print("✅ Model Başarıyla Yüklendi!")
15
  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
  clean_s = context_str.strip()
25
  if not clean_s: return "Error: Veri boş."
26
+
27
  data_list = [float(x) for x in clean_s.split(',')]
28
 
29
+ # Tensor Oluştur (1, 1, Zaman)
30
  context_tensor = torch.tensor(data_list).unsqueeze(0).unsqueeze(0)
31
 
32
  # Tahmin Yap
33
  forecast = pipeline.predict(context_tensor, int(prediction_length))
34
 
35
+ # Sonucu Al (Medyan)
36
+ future_price = forecast[0].quantile(0.5).item()
 
 
37
 
38
+ return str(future_price)
 
 
 
 
39
 
40
  except Exception as e:
41
  return f"Error: {str(e)}"
42
 
43
+ # Arayüzü Başlat (API Name'i sabitlemek için api_name parametresi ekliyoruz)
44
+ # fn=predict fonksiyonuna api_name="/predict" atadık.
45
  iface = gr.Interface(fn=predict, inputs=["text", "number"], outputs="text")
46
  iface.launch()