Spaces:
Runtime error
Runtime error
Ramadhiana
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
#
|
| 5 |
MODEL_ID = "Ranti0603/job-classifier-xlm-roberta-v2"
|
| 6 |
|
| 7 |
def respond(message, history, hf_token: gr.OAuthToken):
|
|
@@ -12,38 +12,37 @@ def respond(message, history, hf_token: gr.OAuthToken):
|
|
| 12 |
"""
|
| 13 |
client = InferenceClient(token=hf_token.token, model=MODEL_ID)
|
| 14 |
|
| 15 |
-
# Panggil model
|
| 16 |
result = client.text_classification(message)
|
| 17 |
|
| 18 |
-
# Ambil
|
| 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 |
-
# ===
|
| 33 |
-
chatbot = gr.ChatInterface(
|
| 34 |
-
fn=respond,
|
| 35 |
-
type="messages",
|
| 36 |
-
chatbot=gr.Chatbot(height=500),
|
| 37 |
-
title="Job Classification Chatbot",
|
| 38 |
-
description="Masukkan deskripsi pekerjaan, sistem akan mengklasifikasikan apakah pekerjaan tersebut termasuk **Non-TIK (0)** atau **TIK (1)**."
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column(scale=1):
|
| 44 |
-
gr.LoginButton() # login
|
| 45 |
with gr.Column(scale=5):
|
| 46 |
-
chatbot.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Ganti dengan model kamu di Hugging Face
|
| 5 |
MODEL_ID = "Ranti0603/job-classifier-xlm-roberta-v2"
|
| 6 |
|
| 7 |
def respond(message, history, hf_token: gr.OAuthToken):
|
|
|
|
| 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:
|
| 34 |
+
gr.Markdown("# Job Classification Chatbot")
|
| 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 |
with gr.Column(scale=1):
|
| 39 |
+
gr.LoginButton() # login HuggingFace
|
| 40 |
with gr.Column(scale=5):
|
| 41 |
+
chatbot = gr.ChatInterface(
|
| 42 |
+
respond,
|
| 43 |
+
type="messages",
|
| 44 |
+
chatbot=gr.Chatbot(height=400),
|
| 45 |
+
)
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
demo.launch()
|