backzone1 commited on
Commit
6339358
·
1 Parent(s): d4a2af3

Add application file

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -1,34 +1,28 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # โหลดโมเดล
5
  pipe = pipeline(
6
  "zero-shot-classification",
7
  model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
8
  )
9
 
10
- # ฟังก์ชันประมวลผลข้อความ
11
- def extract_fields(msg):
12
- prompt = f"""กรุณาสรุปข้อมูลจากข้อความด้านล่าง แล้วแสดงผลเป็นรายการ
13
- - วันที่ขึ้นของ
14
- - วันที่ส่งของ
15
- - ต้นทาง
16
- - ปลายทาง
 
 
 
17
 
18
- Message:
19
- {msg}
20
- [/INST]
21
- """
22
- result = pipe(prompt, max_new_tokens=300, do_sample=False, temperature=0.3)
23
- return result[0]["generated_text"]
24
-
25
- # UI ด้วย Gradio
26
  demo = gr.Interface(
27
- fn=extract_fields,
28
- inputs=gr.Textbox(lines=10, label="พิมพ์ข้อความจาก LINE"),
29
- outputs=gr.Textbox(label="ข้อมูลที่สรุปได้"),
30
- title="สรุปข้อมูลจากข้อความ LINE",
31
- description="ระบบจะดึงข้อมูล วันที่ขึ้นของ, วันที่ส่งของ, ต้นทาง, ปลายทาง จากข้อความที่ได้รับ"
32
  )
33
 
34
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  pipe = pipeline(
5
  "zero-shot-classification",
6
  model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
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()