Add application file
Browse files
app.py
CHANGED
|
@@ -2,27 +2,23 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
pipe = pipeline(
|
| 5 |
-
"
|
| 6 |
-
model="backzone1/FI-Chat-Classify"
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
def classify_message(msg):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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="
|
| 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()
|