abhinavvvvv commited on
Commit
aa3f563
·
1 Parent(s): e7269d4

initial commit

Browse files
Files changed (5) hide show
  1. Dockerfile +13 -0
  2. app.py +84 -0
  3. requirements.txt +6 -0
  4. severity_model.pkl +3 -0
  5. vectorizer.pkl +3 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY . .
10
+
11
+ EXPOSE 7860
12
+
13
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import os
3
+ from fastapi import FastAPI
4
+ from pydantic import BaseModel
5
+
6
+ # -----------------------------
7
+ # FastAPI initialization
8
+ # -----------------------------
9
+ app = FastAPI(
10
+ title="RTL Log Severity Classifier",
11
+ description="Machine learning API that predicts severity of RTL verification logs.",
12
+ version="1.0"
13
+ )
14
+
15
+ # -----------------------------
16
+ # Model paths
17
+ # -----------------------------
18
+ VECTORIZER_PATH = "vectorizer.pkl"
19
+ MODEL_PATH = "severity_model.pkl"
20
+
21
+ # -----------------------------
22
+ # Severity mapping
23
+ # -----------------------------
24
+ REVERSE_MAP = {
25
+ 0: "INFO",
26
+ 1: "WARNING",
27
+ 2: "ERROR",
28
+ 3: "CRITICAL"
29
+ }
30
+
31
+ # -----------------------------
32
+ # Load artifacts safely
33
+ # -----------------------------
34
+ if not os.path.exists(VECTORIZER_PATH):
35
+ raise RuntimeError("vectorizer.pkl not found")
36
+
37
+ if not os.path.exists(MODEL_PATH):
38
+ raise RuntimeError("severity_model.pkl not found")
39
+
40
+ with open(VECTORIZER_PATH, "rb") as f:
41
+ vectorizer = pickle.load(f)
42
+
43
+ with open(MODEL_PATH, "rb") as f:
44
+ model = pickle.load(f)
45
+
46
+ # -----------------------------
47
+ # Request schema
48
+ # -----------------------------
49
+ class LogRequest(BaseModel):
50
+ module: str
51
+ message: str
52
+
53
+
54
+ # -----------------------------
55
+ # Health check
56
+ # -----------------------------
57
+ @app.get("/")
58
+ def health_check():
59
+ return {
60
+ "status": "running",
61
+ "model": "RTL Severity Classifier",
62
+ "classes": ["INFO", "WARNING", "ERROR", "CRITICAL"]
63
+ }
64
+
65
+
66
+ # -----------------------------
67
+ # Prediction endpoint
68
+ # -----------------------------
69
+ @app.post("/predict")
70
+ def predict_severity(request: LogRequest):
71
+
72
+ text = request.module + " " + request.message
73
+
74
+ vector = vectorizer.transform([text])
75
+
76
+ pred = model.predict(vector)[0]
77
+
78
+ severity = REVERSE_MAP[pred]
79
+
80
+ return {
81
+ "module": request.module,
82
+ "message": request.message,
83
+ "predicted_severity": severity
84
+ }
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ scikit-learn
4
+ pandas
5
+ numpy
6
+ pydantic
severity_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bf37966b8f9f795dc7a81828f1151498019f76807b58a76b9bc03f9856c02d8f
3
+ size 320785
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf04a2c840257e4a158b1be2a77f01b356fde06f27b1b65d6cceac08d45de11d
3
+ size 428212