Add application file
Browse files
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 |
-
|
| 12 |
-
|
| 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=
|
| 28 |
-
inputs=gr.Textbox(lines=
|
| 29 |
-
outputs=gr.Textbox(label="
|
| 30 |
-
title="
|
| 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()
|