Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import google.generativeai as genai
|
|
| 2 |
import gradio as gr
|
| 3 |
from deep_translator import (GoogleTranslator)
|
| 4 |
from transformers import pipeline
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
api_key = "AIzaSyCmmus8HFPLXskU170_FR4j2CQeWZBKGMY"
|
|
@@ -11,15 +12,13 @@ spam_detector = pipeline("text-classification", model="madhurjindal/autonlp-Gibb
|
|
| 11 |
model = genai.GenerativeModel('gemini-pro')
|
| 12 |
genai.configure(api_key = api_key)
|
| 13 |
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
try:
|
| 17 |
#response = model.generate_content(f"State whether given response is positive, negative or neutral in one word: {feedback}")
|
| 18 |
score = model.generate_content(f"Give me the polarity score between -1 to 1 for: {feedback}")
|
| 19 |
-
|
| 20 |
-
return [score.text, issue.text]
|
| 21 |
except Exception as e:
|
| 22 |
-
return
|
| 23 |
|
| 24 |
def translate(input_text):
|
| 25 |
source_lang = detect(input_text)
|
|
@@ -29,15 +28,38 @@ def translate(input_text):
|
|
| 29 |
def spam_detection(input_text):
|
| 30 |
return spam_detector(input_text)[0]['label'] == 'clean'
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def pipeline(input_text):
|
| 33 |
|
| 34 |
input_text = translate(input_text)
|
| 35 |
|
| 36 |
if spam_detection(input_text):
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
-
return "
|
| 41 |
|
| 42 |
iface = gr.Interface(
|
| 43 |
fn = pipeline,
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from deep_translator import (GoogleTranslator)
|
| 4 |
from transformers import pipeline
|
| 5 |
+
from langdetect import detect
|
| 6 |
|
| 7 |
|
| 8 |
api_key = "AIzaSyCmmus8HFPLXskU170_FR4j2CQeWZBKGMY"
|
|
|
|
| 12 |
model = genai.GenerativeModel('gemini-pro')
|
| 13 |
genai.configure(api_key = api_key)
|
| 14 |
|
| 15 |
+
def sentiment(feedback):
|
|
|
|
| 16 |
try:
|
| 17 |
#response = model.generate_content(f"State whether given response is positive, negative or neutral in one word: {feedback}")
|
| 18 |
score = model.generate_content(f"Give me the polarity score between -1 to 1 for: {feedback}")
|
| 19 |
+
return score.text
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
+
return "-1"
|
| 22 |
|
| 23 |
def translate(input_text):
|
| 24 |
source_lang = detect(input_text)
|
|
|
|
| 28 |
def spam_detection(input_text):
|
| 29 |
return spam_detector(input_text)[0]['label'] == 'clean'
|
| 30 |
|
| 31 |
+
def negative_zero_shot(input_text):
|
| 32 |
+
try:
|
| 33 |
+
return model.generate_content(f'Issues should be from ["Misconduct" , "Negligence" , "Discrimination" , "Corruption" , "Violation of Rights" , "Inefficiency" , "Unprofessional Conduct", "Response Time" , "Use of Firearms" , "Property Damage"] only. Give me the issue faced by the feedback giver in less than four words: {input_text}').text
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return "Offensive"
|
| 36 |
+
|
| 37 |
+
def positive_zero_shot(input_text):
|
| 38 |
+
try:
|
| 39 |
+
return model.generate_content(f'Issues should be from ["Miscellaneous", "Tech-Savvy Staff" , "Co-operative Staff" , "Well-Maintained Premises" , "Responsive Staff"] only. Give me the issue faced by the feedback giver in less than four words: {input_text}').text
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return "Offensive"
|
| 42 |
def pipeline(input_text):
|
| 43 |
|
| 44 |
input_text = translate(input_text)
|
| 45 |
|
| 46 |
if spam_detection(input_text):
|
| 47 |
+
|
| 48 |
+
sent = float(sentiment(input_text))
|
| 49 |
+
|
| 50 |
+
if sent > 0:
|
| 51 |
+
|
| 52 |
+
return str(sent), positive_zero_shot(input_text)
|
| 53 |
+
|
| 54 |
+
elif sent < 0:
|
| 55 |
+
|
| 56 |
+
return str(sent), negative_zero_shot(input_text)
|
| 57 |
|
| 58 |
+
else:
|
| 59 |
+
|
| 60 |
+
return "0", "No issue"
|
| 61 |
else:
|
| 62 |
+
return "42", "Spam"
|
| 63 |
|
| 64 |
iface = gr.Interface(
|
| 65 |
fn = pipeline,
|