Spaces:
Sleeping
Sleeping
File size: 811 Bytes
df19fbb 4f6cd08 df19fbb 4f6cd08 e62be04 df19fbb e62be04 6306b41 df19fbb e62be04 df19fbb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import pipeline
# โหลดโมเดลที่ฝึกแล้ว หรือโมเดล pretrained
clf = pipeline("text-classification", model="distilbert-base-uncased")
def classify_text(text):
result = clf(text)[0]
label = result['label']
score = round(result['score'], 2)
# เปลี่ยนชื่อ label ให้เข้าใจง่าย
if label == "LABEL_1":
label_name = "ความคิดเห็นเชิงบวก 😀"
else:
label_name = "ความคิดเห็นเชิงลบ 😞"
return f"{label_name} (ความมั่นใจ: {score})"
demo = gr.Interface(fn=classify_text, inputs="text", outputs="text", title="Text Classifier")
demo.launch()
|