abersbail's picture
Add sentiment analyzer CPU Space
c34bacc verified
import gradio as gr
from sentiment_tool.service import SentimentService
service = SentimentService()
def analyze_sentiment(text):
return service.analyze(text)
with gr.Blocks(
title="Sentiment Analyzer CPU",
theme=gr.themes.Soft(primary_hue="yellow", secondary_hue="gray"),
) as demo:
gr.Markdown(
"""
# Sentiment Analyzer CPU
Paste text and get positive, neutral, and negative sentiment scores.
"""
)
text_input = gr.Textbox(label="Input Text", lines=8, placeholder="Write review, opinion, or message here")
run_button = gr.Button("Analyze", variant="primary")
label_output = gr.Textbox(label="Top Label", lines=1)
score_output = gr.Textbox(label="Score Breakdown", lines=4)
status_output = gr.Textbox(label="Status", lines=2)
run_button.click(
fn=analyze_sentiment,
inputs=[text_input],
outputs=[label_output, score_output, status_output],
)
if __name__ == "__main__":
demo.launch()