File size: 1,004 Bytes
c34bacc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
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()