Spaces:
Runtime error
Runtime error
Ramadhiana commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,32 +2,14 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
# Ganti dengan model kamu di Hugging Face
|
| 5 |
-
|
| 6 |
|
| 7 |
def respond(message, history, hf_token: gr.OAuthToken):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
client = InferenceClient(token=hf_token.token, model=MODEL_ID)
|
| 14 |
-
|
| 15 |
-
# Panggil model klasifikasi
|
| 16 |
-
result = client.text_classification(message)
|
| 17 |
-
|
| 18 |
-
# Ambil prediksi terbaik
|
| 19 |
-
best = max(result, key=lambda x: x["score"])
|
| 20 |
-
label = best["label"]
|
| 21 |
-
score = round(best["score"] * 100, 2)
|
| 22 |
-
|
| 23 |
-
# Mapping label
|
| 24 |
-
if label in ["LABEL_0", "0", "Non-TIK"]:
|
| 25 |
-
label_out = "Non-TIK (0)"
|
| 26 |
-
else:
|
| 27 |
-
label_out = "TIK (1)"
|
| 28 |
-
|
| 29 |
-
reply = f"📌 Prediksi: **{label_out}**\n Confidence: {score}%"
|
| 30 |
-
return reply
|
| 31 |
|
| 32 |
# === UI ===
|
| 33 |
with gr.Blocks() as demo:
|
|
@@ -35,9 +17,7 @@ with gr.Blocks() as demo:
|
|
| 35 |
gr.Markdown("Masukkan deskripsi pekerjaan, sistem akan mengklasifikasikan apakah pekerjaan tersebut termasuk **Non-TIK (0)** atau **TIK (1)**.")
|
| 36 |
|
| 37 |
with gr.Row():
|
| 38 |
-
|
| 39 |
-
gr.LoginButton() # login HuggingFace
|
| 40 |
-
with gr.Column(scale=5):
|
| 41 |
chatbot = gr.ChatInterface(
|
| 42 |
respond,
|
| 43 |
type="messages",
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
# Ganti dengan model kamu di Hugging Face
|
| 5 |
+
pipe = pipeline("text-classification", model="Ranti0603/job_classifier_model_v2")
|
| 6 |
|
| 7 |
def respond(message, history, hf_token: gr.OAuthToken):
|
| 8 |
+
result = pipe(message, truncation=True)[0]
|
| 9 |
+
label = result["label"]
|
| 10 |
+
score = round(result["score"] * 100, 2)
|
| 11 |
+
response = f"Pekerjaan ini dikategorikan sebagai **{label}** dengan confidence {score}%"
|
| 12 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# === UI ===
|
| 15 |
with gr.Blocks() as demo:
|
|
|
|
| 17 |
gr.Markdown("Masukkan deskripsi pekerjaan, sistem akan mengklasifikasikan apakah pekerjaan tersebut termasuk **Non-TIK (0)** atau **TIK (1)**.")
|
| 18 |
|
| 19 |
with gr.Row():
|
| 20 |
+
with gr.Column(scale=5):
|
|
|
|
|
|
|
| 21 |
chatbot = gr.ChatInterface(
|
| 22 |
respond,
|
| 23 |
type="messages",
|