Spaces:
Sleeping
Sleeping
File size: 1,102 Bytes
144a909 6a80b4e 144a909 6a80b4e 144a909 6a80b4e 144a909 6a80b4e 144a909 | 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 32 33 34 35 36 | 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)
sentiment = result[0]['label']
return sentiment
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."]
]
#Gradio
with gr.Blocks() as demo:
gr.Markdown("## Sentiment Analysis")
with gr.Row():
with gr.Column():
text_input = gr.Textbox(label="Enter Text", placeholder="Type a sentence or paragraph here ^^...")
with gr.Column():
output = gr.Textbox(label="Predicted Sentiment (1-5 stars)", interactive=False)
analyze_button = gr.Button("Analyze Sentiment", variant="primary")
gr.Examples(examples=examples, inputs=text_input)
analyze_button.click(analyze_sentiment, inputs=[text_input], outputs=output)
demo.launch()
|