import gradio as gr from transformers import pipeline # Initialize the Hugging Face sentiment-analysis pipeline sentiment_model = pipeline("sentiment-analysis") # Define the function that will use the model to predict sentiment def get_sentiment(text): results = sentiment_model(text) return results[0]["label"] # Create the Gradio interface interface = gr.Interface( fn=get_sentiment, inputs=gr.inputs.Textbox(placeholder="Type your text here..."), outputs="text", title="Sentiment Analysis", description="Input a piece of text and click the button to analyze sentiment.", theme="huggingface" # This applies Hugging Face theme to the interface ) # The interface can be launched directly in Python # interface.launch() # To deploy to Hugging Face Spaces, save the interface as an object called 'demo' demo = interface