Spaces:
Runtime error
Runtime error
Ramadhiana
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,11 +5,33 @@ from transformers import pipeline
|
|
| 5 |
# Ganti dengan model kamu di Hugging Face
|
| 6 |
pipe = pipeline("text-classification", model="Ranti0603/job_classifier_model_v2")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def respond(message, history):
|
| 9 |
result = pipe(message, truncation=True)[0]
|
| 10 |
-
label = result
|
| 11 |
-
score = round(result
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
return response
|
| 14 |
|
| 15 |
# === UI ===
|
|
|
|
| 5 |
# Ganti dengan model kamu di Hugging Face
|
| 6 |
pipe = pipeline("text-classification", model="Ranti0603/job_classifier_model_v2")
|
| 7 |
|
| 8 |
+
FALLBACK_MAP = {
|
| 9 |
+
"LABEL_0": "Non-TIK (0)",
|
| 10 |
+
"LABEL_1": "TIK (1)"
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
INDEX_MAP = {
|
| 14 |
+
0 : "Non-TIK (0)",
|
| 15 |
+
1 : "TIK (1)"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def map_label_from_pipeline(pipe, raw_label):
|
| 19 |
+
id2label = getattr(pipe.model.config, "id2label", None)
|
| 20 |
+
if isinstance(id2label, dict):
|
| 21 |
+
inv = {v: int(k) for k, v in id2label.items()}
|
| 22 |
+
if raw_label in inv:
|
| 23 |
+
idx = inv[raw_label]
|
| 24 |
+
return INDEX_MAP.get(idx, f"{raw_label} ({idx})")
|
| 25 |
+
return FALLBACK_MAP.get(raw_label, raw_label)
|
| 26 |
+
|
| 27 |
def respond(message, history):
|
| 28 |
result = pipe(message, truncation=True)[0]
|
| 29 |
+
label = result.get("label","")
|
| 30 |
+
score = round(result.get("score", 0.0) * 100, 2)
|
| 31 |
+
|
| 32 |
+
human_label = map_label_from_pipeline(pipe, label)
|
| 33 |
+
|
| 34 |
+
response = f"Pekerjaan ini dikategorikan sebagai **{human_label}** dengan confidence {score}%"
|
| 35 |
return response
|
| 36 |
|
| 37 |
# === UI ===
|