import gradio as gr from transformers import pipeline sentiment_pipeline = pipeline("sentiment-analysis") def predict_sentiment(text): result = sentiment_pipeline(text)[0] return f"{result['label']}" with gr.Blocks(theme=gr.themes.Soft()) as interface: gr.Markdown( """
Analyze the sentiment of any review or short text. The model will classify it as Positive or Negative.
""", ) with gr.Row(): with gr.Column(): input_text = gr.Textbox( label="Enter your text", placeholder="Type your review here...", lines=4 ) submit_btn = gr.Button("Analyze") with gr.Column(): output_label = gr.Textbox( label="Prediction", interactive=False ) submit_btn.click(predict_sentiment, inputs=input_text, outputs=output_label) interface.launch()