File size: 1,781 Bytes
823da93
 
2169a6e
 
 
823da93
 
 
2169a6e
 
823da93
 
 
 
 
 
 
 
2169a6e
823da93
 
 
 
2169a6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823da93
2169a6e
823da93
 
 
2169a6e
823da93
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
41
42
43
44
45
46
47
48
import google.generativeai as genai
import gradio as gr
from deep_translator import (GoogleTranslator)
from transformers import pipeline


api_key = "AIzaSyCmmus8HFPLXskU170_FR4j2CQeWZBKGMY"

spam_detector = pipeline("text-classification", model="madhurjindal/autonlp-Gibberish-Detector-492513457")

model = genai.GenerativeModel('gemini-pro')
genai.configure(api_key = api_key)

def get_response(feedback):
    
    try:
        #response = model.generate_content(f"State whether given response is positive, negative or neutral in one word: {feedback}")
        score = model.generate_content(f"Give me the polarity score between -1 to 1 for: {feedback}")
        issue = model.generate_content(f'Issues should be from ["Tech-Savvy Staff" , "Co-operative Staff" , "Well-Maintained Premises" , "Responsive Staff", "Misconduct" , "Negligence" , "Discrimination" , "Corruption" , "Violation of Rights" , "Inefficiency" , "Unprofessional Conduct", "Response Time" , "Use of Firearms" , "Property Damage"]. Give me the issue faced by the feedback giver in less than four words: {feedback}')
        return [score.text, issue.text]
    except Exception as e:
        return [-2, "Offensive"]

def translate(input_text):
    source_lang = detect(input_text)
    translated = GoogleTranslator(source=source_lang, target='en').translate(text=input_text)
    return translated
    
def spam_detection(input_text):
    return spam_detector(input_text)[0]['label'] == 'clean'

def pipeline(input_text):

    input_text = translate(input_text)
    
    if spam_detection(input_text):
        return get_response(input_text)
        
    else:
        return "Spam" , ""

iface = gr.Interface(
    fn = pipeline,
    inputs = ["text"],
    outputs = ["text", "text"]
)

iface.launch(share=True)