sent2547's picture
Update app.py
9e66cf0 verified
raw
history blame
1.09 kB
import gradio as gr
from transformers import pipeline
model_name = "ZombitX64/Thai-sentiment-e5" # เปลี่ยนเป็นชื่อโมเดลของคุณ
nlp = pipeline("sentiment-analysis", model=model_name)
# สร้าง dict แม็ป label เป็นเลข
label_map = {
"negative": 0,
"neutral": 1,
"positive": 2
}
def analyze_text(text):
result = nlp(text)[0]
label = result['label'].lower() # แปลงเป็น lowercase เผื่อโมเดลให้แบบนี้
score = result['score']
code = label_map.get(label, -1) # ถ้า label ไม่อยู่ใน dict ให้เป็น -1
return f"ผลวิเคราะห์: {label} (รหัส: {code}) ความมั่นใจ {score:.2f}"
demo = gr.Interface(
fn=analyze_text,
inputs=gr.Textbox(lines=3, placeholder="พิมพ์ข้อความที่นี่..."),
outputs="text",
title="แอปวิเคราะห์ข้อความภาษาไทย"
)
demo.launch()