| import gradio as gr | |
| from transformers import pipeline | |
| # Load the pre-trained model | |
| classifier = pipeline('sentiment-analysis') | |
| # Define the prediction function | |
| def predict_sentiment(text): | |
| results = classifier(text) | |
| return results[0]['label'], results[0]['score'] | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs="text", | |
| outputs=["text", "number"], | |
| title="Sentiment Analysis", | |
| description="Enter text to classify its sentiment as positive or negative." | |
| ) | |
| # Launch the interface | |
| iface.launch() |