Spaces:
Sleeping
Sleeping
File size: 831 Bytes
f44a133 |
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 26 |
import gradio as gr
from transformers import pipeline
classifier = pipeline('sentiment-analysis', model='distilbert/distilbert-base-uncased-finetuned-sst-2-english')
def analyze_sentiment(text):
result = classifier(text)
# The result is a list of dictionaries, e.g., [{'label': 'POSITIVE', 'score': 0.9998}]
# We extract the label and score for better presentation.
sentiment_label = result[0]['label']
sentiment_score = result[0]['score']
return f"Sentiment: {sentiment_label}, Score: {sentiment_score:.2f}"
# Create and launch the Gradio interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs='text',
outputs='text',
title='Sentiment Analysis Application',
description='Enter text to get its sentiment (positive/negative) and score.'
)
# Launch the interface
iface.launch() |