import gradio as gr from transformers import pipeline model = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") def sentiment(text): analysis = model(text) return analysis[0]['label'] with gr.Blocks() as app: gr.Markdown("# Sentiment Analysis") text_input = gr.Textbox(label="Enter a sentence or paragraph:", lines=10) analyze_button = gr.Button("Analyze Sentiment") output_text = gr.Textbox(label="Predicted Sentiment (1 to 5 stars):", interactive=False) analyze_button.click(sentiment, inputs=text_input, outputs=output_text) examples = [ "I love this product! It's amazing!", "This was the worst experience I've ever had." ] gr.Examples( examples=examples, inputs=text_input, label="Try these examples" ) app.launch()