github-actions
commited on
Commit
Β·
55122fc
1
Parent(s):
62a93be
Update model artifacts
Browse files- app.py +21 -18
- vectorizer.joblib +1 -1
app.py
CHANGED
|
@@ -2,40 +2,43 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
import joblib
|
| 4 |
import json
|
|
|
|
| 5 |
from src.preprocessing import clean_text
|
| 6 |
|
| 7 |
-
model = joblib.load("
|
| 8 |
-
vectorizer = joblib.load("
|
| 9 |
|
| 10 |
def predict(text):
|
| 11 |
clean = clean_text(text)
|
| 12 |
vec = vectorizer.transform([clean])
|
| 13 |
pred = model.predict(vec)[0]
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def load_metrics():
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
return json.load(f)
|
| 20 |
-
|
| 21 |
-
return {"error": "Metrics not available. Run evaluation first."}
|
| 22 |
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
with gr.Tab("Inference"):
|
| 25 |
-
gr.
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
outputs="text",
|
| 29 |
-
title="Deteksi Komentar Judi Online"
|
| 30 |
-
)
|
| 31 |
|
| 32 |
with gr.Tab("Monitoring"):
|
| 33 |
-
gr.Markdown("### π Model Performance Metrics")
|
| 34 |
metrics = load_metrics()
|
| 35 |
-
if
|
| 36 |
-
gr.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
gr.Image("model/confusion_matrix.png", label="Confusion Matrix")
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import joblib
|
| 4 |
import json
|
| 5 |
+
import os
|
| 6 |
from src.preprocessing import clean_text
|
| 7 |
|
| 8 |
+
model = joblib.load("saved_model.joblib")
|
| 9 |
+
vectorizer = joblib.load("vectorizer.joblib")
|
| 10 |
|
| 11 |
def predict(text):
|
| 12 |
clean = clean_text(text)
|
| 13 |
vec = vectorizer.transform([clean])
|
| 14 |
pred = model.predict(vec)[0]
|
| 15 |
+
proba = None
|
| 16 |
+
if hasattr(model, "predict_proba"):
|
| 17 |
+
proba = model.predict_proba(vec)[0]
|
| 18 |
+
proba = { "Aman": round(proba[0]*100, 2), "Judi": round(proba[1]*100, 2) }
|
| 19 |
+
|
| 20 |
+
label = "π« Judi Online" if pred == "judi" or pred == 1 else "β
Aman"
|
| 21 |
+
return {"Prediksi": label, "Probabilitas (%)": proba}
|
| 22 |
|
| 23 |
def load_metrics():
|
| 24 |
+
path = "model/metrics_summary.json"
|
| 25 |
+
if os.path.exists(path):
|
| 26 |
+
with open(path) as f:
|
| 27 |
return json.load(f)
|
| 28 |
+
return {}
|
|
|
|
| 29 |
|
| 30 |
with gr.Blocks() as demo:
|
| 31 |
with gr.Tab("Inference"):
|
| 32 |
+
inp = gr.Textbox(lines=3, placeholder="Masukkan komentar...")
|
| 33 |
+
out = gr.JSON()
|
| 34 |
+
gr.Button("Prediksi").click(fn=predict, inputs=inp, outputs=out)
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
with gr.Tab("Monitoring"):
|
|
|
|
| 37 |
metrics = load_metrics()
|
| 38 |
+
if metrics:
|
| 39 |
+
gr.Markdown("### π Model Performance")
|
| 40 |
+
gr.JSON(metrics)
|
| 41 |
+
if os.path.exists("model/confusion_matrix.png"):
|
| 42 |
gr.Image("model/confusion_matrix.png", label="Confusion Matrix")
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
vectorizer.joblib
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 2966
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9c0b2299214b99b6449d835a050b80c9b9470ed2fae73f287c08c9391c44288e
|
| 3 |
size 2966
|