import torch import transformers from transformers import pipeline classifier = pipeline(task='sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment') examples = [ ["This is a Nice presentation "], ["This experience is not as much as i expected "], ["I love this product! It's amazing!"], ["I am very disappointed with the service."] ] import gradio as gr def analyze_sentiment(text): result = pipeline(text)[0] label = result["label"] score = result["score"].range(1,6) return f"Sentiment: {label}\nConfidence: {score}" # Create the Gradio interface iface = gr.Interface( fn=analyze_sentiment, inputs=gr.Textbox(placeholder="Enter text to analyze..."), outputs=[gr.Textbox(label="Sentiment"), gr.Number(label="Confidence"), ], title="Sentiment Analysis App", description="Enter a sentence to determine its sentiment (positive or negative).", examples=examples ) # Launch the app if __name__ == "__main__": iface.launch()