Spaces:
Sleeping
Sleeping
File size: 1,109 Bytes
cb87793 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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() |