Spaces:
Running
Running
Commit
•
4000d7b
1
Parent(s):
b6d3a33
Update app.py
Browse files
app.py
CHANGED
@@ -30,15 +30,22 @@ def spam_detection(input_text):
|
|
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 "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
def pipeline(input_text):
|
43 |
|
44 |
input_text = translate(input_text)
|
@@ -46,25 +53,26 @@ def pipeline(input_text):
|
|
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,
|
66 |
inputs = ["text"],
|
67 |
-
outputs = ["text", "text"]
|
68 |
)
|
69 |
|
70 |
-
iface.launch(
|
|
|
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. If no specific category is detected, take "Offensive" as default. Feedback: {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. If no specific category is detected, take "Appreciation" as default. Feedback: {input_text}').text
|
40 |
except Exception as e:
|
41 |
+
return "Appreciation"
|
42 |
+
|
43 |
+
def which_department(input_text):
|
44 |
+
try:
|
45 |
+
return model.generate_content(f'Departments should be from ["Crime branch", "Rajasthan Armed Constabulary (RAC)", "State Special Branch", "Anti Terrorist Squad (ATS)", "Planning and Welfare", "Training", "Forensic Science laboratory", "Telecommunications", "Cybersecurity", "Traffic Police"] only. Give me the department about which the user is giving feedback. If no specific department is mentioned, take "Crime Branch" as default. Feedback: {input_text}').text
|
46 |
+
except Exception as e:
|
47 |
+
return "Crime branch"
|
48 |
+
|
49 |
def pipeline(input_text):
|
50 |
|
51 |
input_text = translate(input_text)
|
|
|
53 |
if spam_detection(input_text):
|
54 |
|
55 |
sent = float(sentiment(input_text))
|
56 |
+
dept = which_department(input_text)
|
57 |
|
58 |
if sent > 0:
|
59 |
|
60 |
+
return str(sent), positive_zero_shot(input_text), dept
|
61 |
|
62 |
elif sent < 0:
|
63 |
|
64 |
+
return str(sent), negative_zero_shot(input_text), dept
|
65 |
|
66 |
else:
|
67 |
|
68 |
+
return "0", "No issue", dept
|
69 |
else:
|
70 |
+
return "42", "Spam", "No department"
|
71 |
|
72 |
iface = gr.Interface(
|
73 |
fn = pipeline,
|
74 |
inputs = ["text"],
|
75 |
+
outputs = ["text", "text", "text"]
|
76 |
)
|
77 |
|
78 |
+
iface.launch()
|