Spaces:
Sleeping
Sleeping
Update app/core/hf_client.py
Browse files1233456781 unmodified line1011121314151617183 unmodified lines222324252627282930313233343536373839404130424344454647484950515253545556573858596061626364656667686970717273467475767778798081828384858687# =====================================================# app/core/hf_client.py# Hugging Face dataset erişimi (günlük ve geçmiş için)# Pegos - Hugging Face dataset erişimi (predict, latest, dataset)# =====================================================
import pandas as pdimport numpy as npfrom datetime import datetime1 unmodified linefrom app.core.config import settingsfrom app.core.cache import get_cache, set_cache
def _load_csv(path: str) -> pd.DataFrame: """CSV dosyasını indirip normalize eder.""" local = hf_hub_download( repo_id=settings.HF_DATASET_REPO, filename=path,3 unmodified lines ) df = pd.read_csv(local, encoding="utf-8-sig") df = df.replace([np.inf, -np.inf], np.nan).fillna(0)
if "time" in df.columns: df["time"] = pd.to_datetime(df["time"], errors="coerce", utc=True)
if "prediction_day" in df.columns: df["prediction_day"] = df["prediction_day"].astype(str) else: df["prediction_day"] = datetime.utcnow().strftime("%Y-%m-%d")
return df
def load_predict() -> pd.DataFrame: """predict.csv (geçmiş + bugünkü tahminler)""" cached = get_cache() if cached and "predict" in cached: return cached["predict"] df = _load_csv(settings.PATH_PREDICT)
try: df = _load_csv("data/predict.csv") except Exception as e: print(f"⚠️ predict.csv indirilemedi: {e}") df = pd.DataFrame()
set_cache({"predict": df}) return df
def load_latest() -> pd.DataFrame: """latest.csv (ham tweet verileri)""" cached = get_cache() if cached and "latest" in cached: return cached["latest"] df = _load_csv(settings.PATH_LATEST)
try: df = _load_csv("data/latest.csv") except Exception as e: print(f"⚠️ latest.csv indirilemedi: {e}") df = pd.DataFrame()
set_cache({"latest": df}) return df
def load_dataset() -> pd.DataFrame: """pegos_final_dataset.csv (işlenmiş birleşik veri)""" cached = get_cache() if cached and "dataset" in cached: return cached["dataset"] df = _load_csv(settings.PATH_DATASET)
try: df = _load_csv("data/pegos_final_dataset.csv") except Exception as e: print(f"⚠️ dataset indirilemedi: {e}") df = pd.DataFrame()
set_cache({"dataset": df}) return df
def get_latest_timestamp() -> str: """Son güncelleme zamanını UTC formatında döndürür.""" return datetime.utcnow().replace(microsecond=0).isoformat() + "Z"app/core/hf_client.py+40-4