File size: 1,191 Bytes
253f433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1de506
 
 
 
 
 
2a6c323
253f433
 
 
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
# samples = [
#     "The service at the restaurant was really impressive",
#     "What is the status of my order number #1234?",
#     "I have a proposal for a new feature in your app",
#     "My package arrived late and the item was damaged",
#     "Your team is doing an excellent job",
#     "Could you help clarify the specifications of this product?",
#     "I'm extremely dissatisfied with the customer service",
#     "Have you thought about offering more plant-based options on your menu?",
#     "I really appreciate the speedy response from your customer service team",
#     "I enjoy using your application, great work"
# ]

from transformers import pipeline
import gradio as gr

classifier = pipeline(
    "zero-shot-classification",
    model="facebook/bart-large-mnli",
)

candidate_labels = ["opinion", "complaint", "query", "suggestion", "appreciation"]

def analyze_sentiment(text):
    # Classify the text
    label = classifier(text, candidate_labels)['labels'][0]
    
    # Print the text and its corresponding label
    print("Text: " + text + ", Label: " + label)
    return label

demo = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
demo.launch()