Spaces:
Sleeping
Sleeping
| 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( | |
| """ | |
| <h1 style='text-align: center;'>Sentiment Analysis App</h1> | |
| <p style='text-align: center;'>Analyze the sentiment of any review or short text. The model will classify it as <strong>Positive</strong> or <strong>Negative</strong>.</p> | |
| """, | |
| ) | |
| 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() |