Spaces:
Sleeping
Sleeping
File size: 900 Bytes
8667855 ff1c92f | 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 | import gradio as gr
from transformers import pipeline
# Load pipeline
sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
def analyze_sentiment(text):
result = sentiment_analyzer(text)[0]
return f"Predicted Sentiment: {result['label']} stars"
# gradio interface
demo = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(label="Enter text for sentiment analysis", lines=3, placeholder="Type text here..."),
outputs=gr.Textbox(label="Sentiment Result", lines=1),
title="Sentiment Analysis",
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."]
]
)
# Launch the app
if __name__ == "__main__":
demo.launch() |