Spaces:
Sleeping
Sleeping
Tirath5504
commited on
Commit
•
d8a7f48
1
Parent(s):
0ff50a3
Update app.py
Browse files
app.py
CHANGED
@@ -24,8 +24,8 @@ def predict(image):
|
|
24 |
|
25 |
label , confidence = imgResult[0]['label'] , float(imgResult[1]['label'])
|
26 |
|
27 |
-
if confidence > 0.
|
28 |
-
return ["hate" , label]
|
29 |
else:
|
30 |
|
31 |
ocr_text = extract_text(image).lower()
|
@@ -41,15 +41,24 @@ def predict(image):
|
|
41 |
)
|
42 |
|
43 |
profanityFound = any(word in ocr_text.split() for word in profanity_hn)
|
44 |
-
|
45 |
-
if
|
46 |
-
return ["
|
|
|
|
|
|
|
|
|
47 |
else:
|
48 |
-
return ["
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
iface = gr.Interface(fn=predict,
|
51 |
inputs = gr.Image(type='filepath'),
|
52 |
-
outputs=[gr.Label(label = "Class") , gr.Label(label = "Hate Symbol(if any)")],
|
53 |
title = "Hate Speech Detection in Image",
|
54 |
description = "Detect hateful symbols or text in Image"
|
55 |
)
|
|
|
24 |
|
25 |
label , confidence = imgResult[0]['label'] , float(imgResult[1]['label'])
|
26 |
|
27 |
+
if confidence > 0.95:
|
28 |
+
return ["hate" , f"label: {label}, confidence: {confidence}"]
|
29 |
else:
|
30 |
|
31 |
ocr_text = extract_text(image).lower()
|
|
|
41 |
)
|
42 |
|
43 |
profanityFound = any(word in ocr_text.split() for word in profanity_hn)
|
44 |
+
|
45 |
+
if profanityFound:
|
46 |
+
return ["hate", "Profanity Found"]
|
47 |
+
elif engResult[0] != "NEITHER":
|
48 |
+
return ["hate", engResult[0]]
|
49 |
+
elif hingResult[0] != "NAG":
|
50 |
+
return ["hate", hingResult[0]]
|
51 |
else:
|
52 |
+
return ["not_hate", "No hate found, yay!"]
|
53 |
+
|
54 |
+
# if not profanityFound and engResult[0] == "NEITHER" and hingResult[0] == "NAG":
|
55 |
+
# return ["not_hate" , "No Hate Symbols Detected"]
|
56 |
+
# else:
|
57 |
+
# return ["hate" , "No Hate Symbols Detected"]
|
58 |
|
59 |
iface = gr.Interface(fn=predict,
|
60 |
inputs = gr.Image(type='filepath'),
|
61 |
+
outputs=[gr.Label(label = "Class (Hate or Not Hate)") , gr.Label(label = "Hate Symbol (if any)")],
|
62 |
title = "Hate Speech Detection in Image",
|
63 |
description = "Detect hateful symbols or text in Image"
|
64 |
)
|