Spaces:
Sleeping
Sleeping
| 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" | |
| ) | |
| def health(): | |
| return {"status": "running"} | |
| 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 | |
| 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 | |
| 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 |