Spaces:
Running
Running
import gradio as gr | |
from transformers import pipeline | |
model_name = "ZombitX64/Thai-sentiment-e5" | |
nlp = pipeline("sentiment-analysis", model=model_name) | |
label_map = { | |
"LABEL_0": 0, | |
"LABEL_1": 1, | |
"LABEL_2": 2 | |
} | |
label_name_map = { | |
"LABEL_0": "negative", | |
"LABEL_1": "neutral", | |
"LABEL_2": "positive" | |
} | |
def analyze_text(text): | |
result = nlp(text)[0] | |
label = result['label'] | |
score = result['score'] | |
code = label_map.get(label, -1) | |
label_name = label_name_map.get(label, label) | |
return f"ผลวิเคราะห์: {label_name} (รหัส: {code}) ความมั่นใจ {score:.2f}" | |
demo = gr.Interface( | |
fn=analyze_text, | |
inputs=gr.Textbox(lines=3, placeholder="พิมพ์ข้อความที่นี่..."), | |
outputs="text", | |
title="แอปวิเคราะห์ข้อความภาษาไทย" | |
) | |
demo.launch() | |