Ramadhiana commited on
Commit
f37b117
·
verified ·
1 Parent(s): d3f5dfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -1,7 +1,7 @@
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):
@@ -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 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()
 
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()