import gradio as gr from transformers import pipeline # Load a pre-trained sentiment analysis model model = pipeline("sentiment-analysis") # Define a function for sentiment analysis def analyze_sentiment(text): return model(text)[0] # Get the first result (sentiment and score) # Create a Gradio interface for user input and output iface = gr.Interface( fn=analyze_sentiment, inputs="text", outputs="json", title="Sentiment Analysis Demo", description="This app analyzes the sentiment of your text input using a pre-trained model." ) # Launch the interface if __name__ == "__main__": iface.launch()