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()