|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
sentiment_pipeline = pipeline("sentiment-analysis") |
|
|
|
|
|
|
|
|
def analyze_sentiment(text): |
|
|
result = sentiment_pipeline(text)[0] |
|
|
label = result['label'] |
|
|
score = round(result['score'], 2) |
|
|
return f"Sentiment: {label} (Confidence: {score})" |
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=analyze_sentiment, |
|
|
inputs=gr.Textbox(lines=3, placeholder="Enter your text here..."), |
|
|
outputs="text", |
|
|
title="Sentiment Analysis App", |
|
|
description="Enter a sentence to analyze its sentiment (positive or negative)." |
|
|
) |
|
|
|
|
|
|
|
|
interface.launch() |
|
|
|