Commit ·
aa3f563
1
Parent(s): e7269d4
initial commit
Browse filesFiles changed (5)
- DockerfileAdded+13
- app.pyAdded+84
- requirements.txtAdded+6
- severity_model.pklAdded+3
- vectorizer.pklAdded+3
12345678910111213FROM python:3.10
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import pickleimport osfrom fastapi import FastAPIfrom pydantic import BaseModel
# -----------------------------# FastAPI initialization# -----------------------------app = FastAPI( title="RTL Log Severity Classifier", description="Machine learning API that predicts severity of RTL verification logs.", version="1.0")
# -----------------------------# Model paths# -----------------------------VECTORIZER_PATH = "vectorizer.pkl"MODEL_PATH = "severity_model.pkl"
# -----------------------------# Severity mapping# -----------------------------REVERSE_MAP = { 0: "INFO", 1: "WARNING", 2: "ERROR", 3: "CRITICAL"}
# -----------------------------# Load artifacts safely# -----------------------------if not os.path.exists(VECTORIZER_PATH): raise RuntimeError("vectorizer.pkl not found")
if not os.path.exists(MODEL_PATH): raise RuntimeError("severity_model.pkl not found")
with open(VECTORIZER_PATH, "rb") as f: vectorizer = pickle.load(f)
with open(MODEL_PATH, "rb") as f: model = pickle.load(f)
# -----------------------------# Request schema# -----------------------------class LogRequest(BaseModel): module: str message: str
# -----------------------------# Health check# -----------------------------@app.get("/")def health_check(): return { "status": "running", "model": "RTL Severity Classifier", "classes": ["INFO", "WARNING", "ERROR", "CRITICAL"] }
# -----------------------------# Prediction endpoint# -----------------------------@app.post("/predict")def predict_severity(request: LogRequest):
text = request.module + " " + request.message
vector = vectorizer.transform([text])
pred = model.predict(vector)[0]
severity = REVERSE_MAP[pred]
return { "module": request.module, "message": request.message, "predicted_severity": severity }123456fastapiuvicornscikit-learnpandasnumpypydantic123version https://git-lfs.github.com/spec/v1oid sha256:bf37966b8f9f795dc7a81828f1151498019f76807b58a76b9bc03f9856c02d8fsize 320785123version https://git-lfs.github.com/spec/v1oid sha256:cf04a2c840257e4a158b1be2a77f01b356fde06f27b1b65d6cceac08d45de11dsize 428212DockerfileAdded+13
app.pyAdded+84
requirements.txtAdded+6
severity_model.pklAdded+3
vectorizer.pklAdded+3