File size: 1,261 Bytes
a77daa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

sentiment_examples = [
"""
I have been a customer for several years now. I have always received 
the best service, product, and customer service whenever I come here.
For all my service needs, this is the place I trust
""", """
I had a terrible experience here. Everyone was rude and unhelpful. I would not recommend this place to anyone.
""",]

sentiment = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

def get_sentiment(input):
    if not input:
        pass
    else:
        output = sentiment(input.lower())
        return output[0]['label']

interface_sentiment = gr.Interface(fn = get_sentiment,
                                    inputs=gr.Textbox(label="Text", lines=4),
                                    outputs=gr.Textbox(label="Sentiment"),
                                    title = 'Sentiment Analysis',
                                    examples=sentiment_examples,
                                    description="Get Sentiment (Positive / Negative) for a given text.",
                                    css="footer{display:none !important}",
                                    allow_flagging="never"
                                    )