from transformers import pipeline import gradio as gr # Load the sentiment analysis pipeline sentiment_model = pipeline("sentiment-analysis") # Function to use the model def analyze_sentiment(text): result = sentiment_model(text)[0] label = result['label'] score = result['score'] return f"Sentiment: {label}, Confidence: {score:.2f}" # Gradio interface interface = gr.Interface(fn=analyze_sentiment, inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), outputs="text", title="Sentiment Analyzer", description="Enter a sentence to analyze its sentiment.") # Launch the app (comment this out if you're uploading to Hugging Face) if __name__ == "__main__": interface.launch()