import mlflow import joblib import pandas as pd from fastapi import FastAPI MLFLOW_URI = "https://remdev-ai-projet-06-mlops-mlflow.hf.space" RUN_ID = "f669674a10e84d1199134ab88d64be9b" mlflow.set_tracking_uri(MLFLOW_URI) # Télécharger les fichiers model_path = mlflow.artifacts.download_artifacts( run_id=RUN_ID, artifact_path="credit_model.joblib" ) threshold_path = mlflow.artifacts.download_artifacts( run_id=RUN_ID, artifact_path="optimal_threshold.txt" ) # Charger model = joblib.load(model_path) with open(threshold_path) as f: threshold = float(f.read()) app = FastAPI() @app.post("/predict") def predict(payload: dict): df = pd.DataFrame([payload]) proba = model.predict_proba(df)[0,1] decision = int(proba >= threshold) return { "probability_default": float(proba), "threshold": threshold, "decision": decision }