import gradio as gr from transformers import pipeline # Load pre-trained sentiment analysis model sentiment_model = pipeline("sentiment-analysis") # Function to process input sentences and return sentiment def get_sentiment(sentence): result = sentiment_model(sentence) sentiment_label = result[0]["label"] return sentiment_label # Create Gradio UI components input_text = gr.inputs.Textbox(lines=2, placeholder="Enter your sentence here...") output_text = gr.outputs.Textbox() # Create Gradio Interface iface = gr.Interface( fn=get_sentiment, inputs=input_text, outputs=output_text, title="Sentiment Analysis", description="Enter a sentence to analyze its sentiment (positive, negative, or neutral)." ) # Launch Gradio Interface if __name__ == "__main__": iface.launch()