Spaces:
Runtime error
Runtime error
siddhantuniyal
commited on
Commit
·
ad7804d
1
Parent(s):
11b0fec
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
4 |
+
import nltk
|
5 |
+
nltk.download('vader_lexicon')
|
6 |
+
|
7 |
+
zero_shot_classifier = pipeline("zero-shot-classification" , model='roberta-large-mnli')
|
8 |
+
|
9 |
+
spam_detector = pipeline("text-classification", model="madhurjindal/autonlp-Gibberish-Detector-492513457")
|
10 |
+
|
11 |
+
issues = ["Misconduct" , "Negligence" , "Discrimination" , "Corruption" , "Violation of Rights" , "Inefficiency" ,
|
12 |
+
"Unprofessional Conduct", "Response Time" , "Use of Firearms" , "Property Damage"]
|
13 |
+
|
14 |
+
apprecn = ["Tech-Savvy Staff" , "Co-operative Staff" , "Well-Maintained Premises" , "Responsive Staff"]
|
15 |
+
|
16 |
+
def spam_detection(input_text):
|
17 |
+
|
18 |
+
return spam_detector(input_text)[0]['label'] == 'clean'
|
19 |
+
|
20 |
+
def sentiment_analysis(input_text):
|
21 |
+
|
22 |
+
score = SentimentIntensityAnalyzer().polarity_scores(input_text)
|
23 |
+
|
24 |
+
if score['neg']>score['pos']:
|
25 |
+
|
26 |
+
return "Negative Feedback"
|
27 |
+
|
28 |
+
elif score['neg']<score['pos']:
|
29 |
+
|
30 |
+
return "Positive Feedback"
|
31 |
+
|
32 |
+
else:
|
33 |
+
|
34 |
+
return "Neutral Feedback"
|
35 |
+
|
36 |
+
def positive_zero_shot(input_text):
|
37 |
+
|
38 |
+
return zero_shot_classifier(input_text , candidate_labels = apprecn , multi_label = False)['labels'][0]
|
39 |
+
|
40 |
+
|
41 |
+
def negative_zero_shot(input_text):
|
42 |
+
|
43 |
+
return zero_shot_classifier(input_text , candidate_labels = issues , multi_label = False)['labels'][0]
|
44 |
+
|
45 |
+
def pipeline(input_text):
|
46 |
+
|
47 |
+
if spam_detection(input_text):
|
48 |
+
|
49 |
+
if sentiment_analysis(input_text) == "Positive Feedback":
|
50 |
+
|
51 |
+
return "Positive Feedback" , positive_zero_shot(input_text)
|
52 |
+
|
53 |
+
elif sentiment_analysis(input_text) == "Negative Feedback":
|
54 |
+
|
55 |
+
return "Negative Feedback" , negative_zero_shot(input_text)
|
56 |
+
|
57 |
+
else:
|
58 |
+
|
59 |
+
return "Neutral Feedback" , ""
|
60 |
+
else:
|
61 |
+
return "Spam" , ""
|
62 |
+
|
63 |
+
iface = gr.Interface(fn = pipeline , inputs=['text'] , outputs=['text' , 'text'])
|
64 |
+
iface.launch(share=True)
|
65 |
+
|
66 |
+
|
67 |
+
|