Spaces:
Sleeping
Sleeping
Download app/routers/predict.py from Caner7/pegos-data: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/spaces/Caner7/pegos-data/resolve/main/app/routers/predict.py
- Command line
-
hf download hf://spaces/Caner7/pegos-data/app/routers/predict.py
-
curl -L -o predict.py https://huggingface.co/spaces/Caner7/pegos-data/resolve/main/app/routers/predict.py
2.29 kB
| # ===================================================== | |
| # app/routers/predict.py | |
| # Belirli bir güne ait tahmin verilerini döndürür (AI Model Tahmini dahil) | |
| # ===================================================== | |
| from fastapi import APIRouter, HTTPException, Query | |
| from datetime import datetime | |
| import numpy as np | |
| from app.core.hf_client import load_predict, get_latest_timestamp | |
| router = APIRouter() | |
| def predict_data( | |
| day: str = Query(None, description="YYYY-MM-DD formatında gün seç (boşsa bugünkü veriler)") | |
| ): | |
| """ | |
| Belirli bir güne veya bugüne ait tahmin verilerini döndürür. | |
| - Model yönü (📈/📉) | |
| - Güven yüzdesi | |
| - AI Model Tahmini (%) ve yön bilgisi | |
| """ | |
| try: | |
| df = load_predict() | |
| if df.empty: | |
| return {"count": 0, "items": []} | |
| # Gün filtresi | |
| if day: | |
| df = df[df["prediction_day"] == day] | |
| else: | |
| today = datetime.utcnow().strftime("%Y-%m-%d") | |
| df = df[df["prediction_day"] == today] | |
| if df.empty: | |
| return {"count": 0, "message": f"{day or today} için veri yok", "items": []} | |
| # Tahmin etiketleri | |
| if "pred_label" in df.columns: | |
| df["Tahmin"] = df["pred_label"].map({1: "📈 YÜKSELİŞ", 0: "📉 DÜŞÜŞ"}) | |
| if "pred_proba" in df.columns: | |
| df["Güven (%)"] = (df["pred_proba"] * 100).round(2) | |
| # AI Model Tahmini (%) hesapla | |
| if "AI_Model_Tahmini (%)" not in df.columns and "pred_diff" in df.columns: | |
| df["AI_Model_Tahmini (%)"] = (df["pred_diff"] * 100).round(2) | |
| # AI Model yönü | |
| if "AI_Model_Yonu" not in df.columns: | |
| df["AI_Model_Yonu"] = np.where( | |
| df["pred_diff"] > 0, | |
| "📈 Artış Bekleniyor", | |
| np.where(df["pred_diff"] < 0, "📉 Düşüş Bekleniyor", "⚖️ Değişim Yok") | |
| ) | |
| # 🚫 Artık limit yok — tüm satırları döndür | |
| return { | |
| "count": len(df), | |
| "day": day or today, | |
| "updated_at": get_latest_timestamp(), | |
| "items": df.to_dict(orient="records"), | |
| } | |
| except Exception as e: | |
| raise HTTPException(500, f"Tahmin verileri alınamadı: {e}") |