Spaces:
Sleeping
Sleeping
File size: 755 Bytes
38ccb65 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import gradio as gr
from transformers import pipeline
# Tải model phân tích cảm xúc từ Hugging Face Hub
sentiment_model = pipeline("sentiment-analysis")
# Hàm xử lý đầu vào
def analyze_sentiment(text):
result = sentiment_model(text)[0]
label = result['label']
score = round(result['score'] * 100, 2)
return f"Kết quả: {label} ({score}%)"
# Giao diện Gradio
interface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Nhập câu của bạn..."),
outputs="text",
title="Phân tích cảm xúc",
description="Nhập một câu tiếng Anh để phân tích cảm xúc (tích cực / tiêu cực)."
)
# Chạy ứng dụng
interface.launch()
|