Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import gradio as gr | |
from nltk.sentiment.vader import SentimentIntensityAnalyzer | |
import nltk | |
nltk.download('vader_lexicon') | |
zero_shot_classifier = pipeline("zero-shot-classification" , model='roberta-large-mnli') | |
spam_detector = pipeline("text-classification", model="madhurjindal/autonlp-Gibberish-Detector-492513457") | |
issues = ["Misconduct" , "Negligence" , "Discrimination" , "Corruption" , "Violation of Rights" , "Inefficiency" , | |
"Unprofessional Conduct", "Response Time" , "Use of Firearms" , "Property Damage"] | |
apprecn = ["Tech-Savvy Staff" , "Co-operative Staff" , "Well-Maintained Premises" , "Responsive Staff"] | |
def spam_detection(input_text): | |
return spam_detector(input_text)[0]['label'] == 'clean' | |
def sentiment_analysis(input_text): | |
score = SentimentIntensityAnalyzer().polarity_scores(input_text) | |
if score['neg']>score['pos']: | |
return "Negative Feedback" | |
elif score['neg']<score['pos']: | |
return "Positive Feedback" | |
else: | |
return "Neutral Feedback" | |
def positive_zero_shot(input_text): | |
return zero_shot_classifier(input_text , candidate_labels = apprecn , multi_label = False)['labels'][0] | |
def negative_zero_shot(input_text): | |
return zero_shot_classifier(input_text , candidate_labels = issues , multi_label = False)['labels'][0] | |
def pipeline(input_text): | |
if spam_detection(input_text): | |
if sentiment_analysis(input_text) == "Positive Feedback": | |
return "Positive Feedback" , positive_zero_shot(input_text) | |
elif sentiment_analysis(input_text) == "Negative Feedback": | |
return "Negative Feedback" , negative_zero_shot(input_text) | |
else: | |
return "Neutral Feedback" , "" | |
else: | |
return "Spam" , "" | |
iface = gr.Interface(fn = pipeline , inputs=['text'] , outputs=['text' , 'text']) | |
iface.launch(share=True) | |