Spaces:
Sleeping
Sleeping
| 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() | |