Spaces:
Sleeping
Sleeping
File size: 1,135 Bytes
db65b8b 3c52de2 db65b8b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 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 |