Spaces:
Runtime error
Runtime error
Amulya M commited on
Commit ·
4d7f23f
1
Parent(s): be2e498
m1
Browse files- __pycache__/function.cpython-39.pyc +0 -0
- app.py +3 -3
- function.py +0 -41
- model.py +38 -0
__pycache__/function.cpython-39.pyc
DELETED
|
Binary file (1.46 kB)
|
|
|
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# from pydub import AudioSegment
|
| 2 |
-
import
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
|
|
@@ -18,7 +18,7 @@ if option == 'Text':
|
|
| 18 |
with col2:
|
| 19 |
b = st.button("Post", key='bb', help='Click to Post')
|
| 20 |
col3, col4 = st.columns(2)
|
| 21 |
-
de =
|
| 22 |
if a:
|
| 23 |
st.markdown(de[0])
|
| 24 |
if b:
|
|
@@ -37,7 +37,7 @@ if option == 'Sound File':
|
|
| 37 |
e = st.button("Detect")
|
| 38 |
with col7:
|
| 39 |
f = st.button("Post")
|
| 40 |
-
fg =
|
| 41 |
if d:
|
| 42 |
audio_file = open(fileObject.name, 'rb')
|
| 43 |
audio_bytes = audio_file.read()
|
|
|
|
| 1 |
# from pydub import AudioSegment
|
| 2 |
+
import model
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
|
|
|
|
| 18 |
with col2:
|
| 19 |
b = st.button("Post", key='bb', help='Click to Post')
|
| 20 |
col3, col4 = st.columns(2)
|
| 21 |
+
de = model.detect([pred])
|
| 22 |
if a:
|
| 23 |
st.markdown(de[0])
|
| 24 |
if b:
|
|
|
|
| 37 |
e = st.button("Detect")
|
| 38 |
with col7:
|
| 39 |
f = st.button("Post")
|
| 40 |
+
fg = model.detect([model.voice_file(fileObject.name)])
|
| 41 |
if d:
|
| 42 |
audio_file = open(fileObject.name, 'rb')
|
| 43 |
audio_bytes = audio_file.read()
|
function.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
import model
|
| 2 |
-
from sklearn.feature_extraction.text import CountVectorizer
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def detect_hate_speech(sample):
|
| 6 |
-
cv = CountVectorizer()
|
| 7 |
-
vect = cv.transform(sample).toarray()
|
| 8 |
-
pred_prob = np.max(model.predict_proba(vect))
|
| 9 |
-
pred = model.predict(vect)
|
| 10 |
-
return pred, pred_prob
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def detect(sample):
|
| 14 |
-
hatespeech = detect_hate_speech(sample)
|
| 15 |
-
mp = "Try again"
|
| 16 |
-
if hatespeech[0] == 0:
|
| 17 |
-
mp = "Hate Speech Detected"
|
| 18 |
-
elif hatespeech[0] == 1:
|
| 19 |
-
mp = "Offensive Language Detected"
|
| 20 |
-
elif hatespeech[0] == 2:
|
| 21 |
-
mp = "NO Hate Speech Detected"
|
| 22 |
-
return mp, hatespeech[1], hatespeech[0]
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def voice_file(file):
|
| 26 |
-
speech_config = speechsdk.SpeechConfig(subscription=api_key, endpoint=endpoint)
|
| 27 |
-
speech_config.speech_recognition_language = "en-US"
|
| 28 |
-
speech_config.set_profanity(speechsdk.ProfanityOption.Raw)
|
| 29 |
-
audio_config = speechsdk.audio.AudioConfig(filename=file)
|
| 30 |
-
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
|
| 31 |
-
speech_recognition_result = speech_recognizer.recognize_once_async().get()
|
| 32 |
-
if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
| 33 |
-
print(speech_recognition_result.text)
|
| 34 |
-
return speech_recognition_result.text
|
| 35 |
-
elif speech_recognition_result.text == "":
|
| 36 |
-
return "$empty$"
|
| 37 |
-
elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
|
| 38 |
-
return speech_recognition_result.no_match_details
|
| 39 |
-
elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
|
| 40 |
-
cancellation_details = speech_recognition_result.cancellation_details
|
| 41 |
-
return cancellation_details.reason
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.py
CHANGED
|
@@ -23,3 +23,41 @@ model = LogisticRegression(max_iter=1000)
|
|
| 23 |
model.fit(X_train,y_train)
|
| 24 |
y_pred = model.predict(X_test)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
model.fit(X_train,y_train)
|
| 24 |
y_pred = model.predict(X_test)
|
| 25 |
|
| 26 |
+
def detect_hate_speech(sample):
|
| 27 |
+
vect = cv.transform(sample).toarray()
|
| 28 |
+
pred_prob = np.max(model.predict_proba(vect))
|
| 29 |
+
pred = model.predict(vect)
|
| 30 |
+
return pred, pred_prob
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def detect(sample):
|
| 34 |
+
hatespeech = detect_hate_speech(sample)
|
| 35 |
+
mp = "Try again"
|
| 36 |
+
if hatespeech[0] == 0:
|
| 37 |
+
mp = "Hate Speech Detected"
|
| 38 |
+
elif hatespeech[0] == 1:
|
| 39 |
+
mp = "Offensive Language Detected"
|
| 40 |
+
elif hatespeech[0] == 2:
|
| 41 |
+
mp = "NO Hate Speech Detected"
|
| 42 |
+
return mp, hatespeech[1], hatespeech[0]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def voice_file(file):
|
| 46 |
+
speech_config = speechsdk.SpeechConfig(subscription=api_key, endpoint=endpoint)
|
| 47 |
+
speech_config.speech_recognition_language = "en-US"
|
| 48 |
+
speech_config.set_profanity(speechsdk.ProfanityOption.Raw)
|
| 49 |
+
audio_config = speechsdk.audio.AudioConfig(filename=file)
|
| 50 |
+
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
|
| 51 |
+
speech_recognition_result = speech_recognizer.recognize_once_async().get()
|
| 52 |
+
if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
| 53 |
+
print(speech_recognition_result.text)
|
| 54 |
+
return speech_recognition_result.text
|
| 55 |
+
elif speech_recognition_result.text == "":
|
| 56 |
+
return "$empty$"
|
| 57 |
+
elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
|
| 58 |
+
return speech_recognition_result.no_match_details
|
| 59 |
+
elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
|
| 60 |
+
cancellation_details = speech_recognition_result.cancellation_details
|
| 61 |
+
return cancellation_details.reason
|
| 62 |
+
|
| 63 |
+
|