Spaces:
Runtime error
Runtime error
Ramadhiana
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
# ID model di Hugging Face Hub
|
| 5 |
MODEL_ID = "Ranti0603/job-classifier-xlm-roberta-v2"
|
| 6 |
|
| 7 |
def respond(message, history, hf_token: gr.OAuthToken):
|
| 8 |
"""
|
| 9 |
-
Chatbot
|
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
client = InferenceClient(token=hf_token.token, model=MODEL_ID)
|
| 12 |
|
| 13 |
-
# Panggil model untuk klasifikasi
|
| 14 |
result = client.text_classification(message)
|
| 15 |
|
| 16 |
-
# Ambil hasil
|
| 17 |
best = max(result, key=lambda x: x["score"])
|
| 18 |
label = best["label"]
|
| 19 |
score = round(best["score"] * 100, 2)
|
| 20 |
|
| 21 |
-
# Mapping label
|
| 22 |
if label in ["LABEL_0", "0", "Non-TIK"]:
|
| 23 |
label_out = "Non-TIK (0)"
|
| 24 |
else:
|
| 25 |
label_out = "TIK (1)"
|
| 26 |
|
| 27 |
-
reply = f"Prediksi: **{label_out}**\n
|
| 28 |
return reply
|
| 29 |
|
| 30 |
-
# === Gradio Chatbot
|
| 31 |
chatbot = gr.ChatInterface(
|
| 32 |
-
fn=respond,
|
| 33 |
-
chatbot=gr.Chatbot(height=400),
|
| 34 |
type="messages",
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
-
with gr.
|
| 39 |
-
gr.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
chatbot.render()
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# ID model klasifikasi yang sudah kamu upload di Hugging Face Hub
|
| 5 |
MODEL_ID = "Ranti0603/job-classifier-xlm-roberta-v2"
|
| 6 |
|
| 7 |
def respond(message, history, hf_token: gr.OAuthToken):
|
| 8 |
"""
|
| 9 |
+
Chatbot klasifikasi pekerjaan:
|
| 10 |
+
Input: Deskripsi pekerjaan
|
| 11 |
+
Output: Prediksi label + confidence
|
| 12 |
"""
|
| 13 |
client = InferenceClient(token=hf_token.token, model=MODEL_ID)
|
| 14 |
|
| 15 |
+
# Panggil model untuk klasifikasi teks
|
| 16 |
result = client.text_classification(message)
|
| 17 |
|
| 18 |
+
# Ambil hasil prediksi
|
| 19 |
best = max(result, key=lambda x: x["score"])
|
| 20 |
label = best["label"]
|
| 21 |
score = round(best["score"] * 100, 2)
|
| 22 |
|
| 23 |
+
# Mapping label ke format readable
|
| 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 |
+
# === Gradio Chatbot ===
|
| 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 HF
|
| 45 |
+
with gr.Column(scale=5):
|
| 46 |
+
chatbot.render()
|
|
|
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
demo.launch()
|