Spaces:
Runtime error
Runtime error
feat: change api response format
Browse files
app.py
CHANGED
@@ -66,7 +66,7 @@ def predict_hate_speech(audio_path):
|
|
66 |
api_name="/predict"
|
67 |
)
|
68 |
|
69 |
-
profanityFound =
|
70 |
threshold = 0.6
|
71 |
isHate = (engResult[0] != "NEITHER" and engResult[1] > threshold) or (
|
72 |
hingResult[0] != "NAG" and hingResult[1] > threshold) or (
|
@@ -77,19 +77,38 @@ def predict_hate_speech(audio_path):
|
|
77 |
audConf = audResult['Confidence'] if audResult['Classification'] == 'Hate Speech\n' else (1 - audResult['Confidence'])
|
78 |
|
79 |
confidence = (engConf + hingConf + audConf) / 3
|
80 |
-
# print(profanityFound, engResult, hingResult, audResult)
|
81 |
-
if profanityFound:
|
82 |
-
return ["hate", f"Result: Profanity Found", f"Text: {stt_text}"]
|
83 |
-
elif isHate:
|
84 |
-
return ["hate", f"Confidence: {confidence}", f"Text: {stt_text}"]
|
85 |
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
|
89 |
iface = gr.Interface(
|
90 |
fn=predict_hate_speech,
|
91 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
92 |
-
outputs=gr.
|
93 |
title="Hate Speech Audio Pipeline",
|
94 |
description="Upload an audio file to detect potential hate speech content.",
|
95 |
examples=[
|
|
|
66 |
api_name="/predict"
|
67 |
)
|
68 |
|
69 |
+
profanityFound = [word for word in stt_text.split() if word in profanity_hn]
|
70 |
threshold = 0.6
|
71 |
isHate = (engResult[0] != "NEITHER" and engResult[1] > threshold) or (
|
72 |
hingResult[0] != "NAG" and hingResult[1] > threshold) or (
|
|
|
77 |
audConf = audResult['Confidence'] if audResult['Classification'] == 'Hate Speech\n' else (1 - audResult['Confidence'])
|
78 |
|
79 |
confidence = (engConf + hingConf + audConf) / 3
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
if len(profanityFound) > 0:
|
82 |
+
return {
|
83 |
+
'prediciton' : 'hate',
|
84 |
+
'language' : 'Hindi',
|
85 |
+
'label' : 'Profanity found',
|
86 |
+
'confidence' : None,
|
87 |
+
'hate_text' : profanityFound
|
88 |
+
}
|
89 |
+
|
90 |
+
if isHate:
|
91 |
+
return {
|
92 |
+
'prediction' : 'hate',
|
93 |
+
'language' : 'English' if engConf > hingConf else 'Hinglish',
|
94 |
+
'label' : None,
|
95 |
+
'confidence' : confidence,
|
96 |
+
'hate_text' : stt_text
|
97 |
+
}
|
98 |
+
|
99 |
+
return {
|
100 |
+
'prediction' : 'not_hate',
|
101 |
+
'language' : None,
|
102 |
+
'label' : None,
|
103 |
+
'confidence' : None,
|
104 |
+
'hate_text' : None
|
105 |
+
}
|
106 |
|
107 |
|
108 |
iface = gr.Interface(
|
109 |
fn=predict_hate_speech,
|
110 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
111 |
+
outputs=gr.JSON(),
|
112 |
title="Hate Speech Audio Pipeline",
|
113 |
description="Upload an audio file to detect potential hate speech content.",
|
114 |
examples=[
|