from fastapi import FastAPI, UploadFile, File import shutil import os from api.predictor import predict_logs from api.shap_explainer import explain_logs app = FastAPI( title="RTL Failure Prediction API", description="Predict RTL module failure risk from verification logs", version="1.0" ) @app.get("/") def health(): return {"status": "running"} @app.post("/predict_file") async def predict_file(file: UploadFile = File(...)): path = f"temp_{file.filename}" with open(path, "wb") as buffer: shutil.copyfileobj(file.file, buffer) result = predict_logs(path) os.remove(path) return result @app.post("/predict_single") def predict_single(log_line: str): path = "temp_single.txt" with open(path, "w") as f: f.write(log_line) result = predict_logs(path) os.remove(path) return result @app.post("/explain") async def explain(file: UploadFile = File(...)): path = f"temp_{file.filename}" with open(path, "wb") as buffer: shutil.copyfileobj(file.file, buffer) result = explain_logs(path) os.remove(path) return result