import gradio as gr import torch import numpy as np from chronos import Chronos2Pipeline # --- MODELİ YÜKLE --- print("🚀 Chronos-2 Modeli Yükleniyor...") try: pipeline = Chronos2Pipeline.from_pretrained( "amazon/chronos-2", device_map="cpu", dtype=torch.float32, ) print("✅ Model Başarıyla Yüklendi!") except Exception as e: print(f"❌ Model Yükleme Hatası: {e}") pipeline = None def predict(context_str, prediction_length): if pipeline is None: return "Error: Model yüklenemedi." try: clean_s = context_str.strip() if not clean_s: return "Error: Veri boş." data_list = [float(x) for x in clean_s.split(',')] # Tensor Oluştur context_tensor = torch.tensor(data_list).unsqueeze(0).unsqueeze(0) # Tahmin Yap forecast = pipeline.predict(context_tensor, int(prediction_length)) # --- ÇIKTI FORMATI: Medyan | Alt Sınır | Üst Sınır --- # 0.5: Medyan (Beklenen) # 0.1: Alt Sınır (Kötü Senaryo) # 0.9: Üst Sınır (İyi Senaryo) median_price = forecast[0].quantile(0.5).item() lower_price = forecast[0].quantile(0.1).item() upper_price = forecast[0].quantile(0.9).item() return f"{median_price}|{lower_price}|{upper_price}" except Exception as e: return f"Error: {str(e)}" iface = gr.Interface(fn=predict, inputs=["text", "number"], outputs="text") iface.launch()