File size: 1,172 Bytes
0f63899 3f7bb16 0f63899 |
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 27 28 29 30 31 |
import gradio as gr
from transformers import pipeline
sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
def analyze_sentiment(text):
result = sentiment_analyzer(text)[0]
score = result['label']
return score
interface = gr.Interface(
fn=analyze_sentiment,
inputs=[
gr.Textbox(label="Enter your text here", placeholder="Type a sentence or paragraph...", lines=5),
],
outputs=gr.Label(label="Predicted Sentiment (1-5 stars)"),
examples=[
["I love this product! It's amazing!"],
["This was the worst experience I've ever had."],
["The movie was okay, not great but not bad either."],
["Absolutely fantastic! I would recommend it to everyone."],
["I'm very disappointed with the customer service."],
["The concert was fantastic, I had an amazing time!"],
["I regret buying this product, it's terrible."]
],
title="Sentiment Analysis App",
description="This app analyzes the sentiment of the text you provide, showing a score from 1 to 5 stars, where 1 is negative and 5 is positive."
)
interface.launch()
|