backzone1 commited on
Commit
b2b7084
·
1 Parent(s): b211096

Add application file

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -2,27 +2,23 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  pipe = pipeline(
5
- "zero-shot-classification",
6
- model="backzone1/FI-Chat-Classify"
 
7
  )
8
 
9
  def classify_message(msg):
10
- labels = ["เป็นงาน", "ไม่ใช่งาน"]
11
- result = pipe(
12
- msg,
13
- candidate_labels=labels,
14
- hypothesis_template="ข้อความนี้เป็น {}"
15
- )
16
- best = result["labels"][0]
17
- score = result["scores"][0]
18
- return f"ผลลัพธ์: {best} (ความมั่นใจ {score:.2f})"
19
 
20
  demo = gr.Interface(
21
  fn=classify_message,
22
  inputs=gr.Textbox(lines=5, label="พิมพ์ข้อความจาก LINE"),
23
  outputs=gr.Textbox(label="ผลลัพธ์"),
24
  title="จำแนกข้อความว่าเป็นงานหรือไม่",
25
- description="ใช้โมเดล zero-shot classification ที่เทรนแล้วเพื่อวิเคราะห์ข้อความ"
26
  )
27
 
28
  demo.launch()
 
2
  from transformers import pipeline
3
 
4
  pipe = pipeline(
5
+ "text-classification",
6
+ model="backzone1/FI-Chat-Classify", # โมเดลที่คุณเทรนเองและอัปโหลด
7
+ tokenizer="backzone1/FI-Chat-Classify" # ให้ใช้ tokenizer จากโมเดลเดียวกัน
8
  )
9
 
10
  def classify_message(msg):
11
+ result = pipe(msg)[0]
12
+ label = result["label"]
13
+ score = result["score"]
14
+ return f"ผลลัพธ์: {label} (ความมั่นใจ {score:.2f})"
 
 
 
 
 
15
 
16
  demo = gr.Interface(
17
  fn=classify_message,
18
  inputs=gr.Textbox(lines=5, label="พิมพ์ข้อความจาก LINE"),
19
  outputs=gr.Textbox(label="ผลลัพธ์"),
20
  title="จำแนกข้อความว่าเป็นงานหรือไม่",
21
+ description="ใช้โมเดลที่ฝึกเองเพื่อจำแนกข้อความ"
22
  )
23
 
24
  demo.launch()