Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +48 -0
- model.pkl +3 -0
- requirements.txt +3 -0
- vectorizer.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from string import punctuation
|
| 4 |
+
import nltk
|
| 5 |
+
from nltk.corpus import stopwords
|
| 6 |
+
from nltk.stem import WordNetLemmatizer
|
| 7 |
+
from nltk import word_tokenize
|
| 8 |
+
|
| 9 |
+
nltk.download('stopwords')
|
| 10 |
+
nltk.download('punkt')
|
| 11 |
+
nltk.download('wordnet')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
model = pickle.load(open('model.pkl', 'rb'))
|
| 15 |
+
vectorizer = pickle.load(open('vectorizer.pkl', 'rb'))
|
| 16 |
+
|
| 17 |
+
# Defining a function that will clean the text
|
| 18 |
+
def clean_text(text):
|
| 19 |
+
punc = list(punctuation)
|
| 20 |
+
stop = stopwords.words('english')
|
| 21 |
+
bad_tokens = punc + stop
|
| 22 |
+
tokens = word_tokenize(text)
|
| 23 |
+
lemma = WordNetLemmatizer()
|
| 24 |
+
word_tokens = [t for t in tokens if t.isalpha()]
|
| 25 |
+
clean_tokens = [lemma.lemmatize(t.lower()) for t in word_tokens if t not in bad_tokens]
|
| 26 |
+
return ' '.join(clean_tokens)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# defining the main function and creating the ui
|
| 30 |
+
def main():
|
| 31 |
+
st.set_page_config(page_title='Hate Speech Detector', page_icon='🤖')
|
| 32 |
+
st.header("Hate Speech Detection System")
|
| 33 |
+
text = st.text_area('Enter Text')
|
| 34 |
+
submit = st.button('Submit')
|
| 35 |
+
if submit:
|
| 36 |
+
itext = clean_text(text)
|
| 37 |
+
vectorized_text = vectorizer.transform([itext])
|
| 38 |
+
response = model.predict(vectorized_text)[0]
|
| 39 |
+
if response == 0:
|
| 40 |
+
st.write('Hate Speech')
|
| 41 |
+
if response == 1:
|
| 42 |
+
st.write('Offensive Language')
|
| 43 |
+
else:
|
| 44 |
+
st.write('No hate speech or offensive language detected')
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
main()
|
| 48 |
+
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4fa91712c6e78008a226376f3e1102d3ca526e26c16ee04c5ecf4fa939e57a78
|
| 3 |
+
size 332738
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
scikit-learn
|
| 3 |
+
nltk
|
vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:56ae5c2cc4e5b91b24b7d0af7408054f1c257ea11fc446d5a46e9bbbcef2f6e0
|
| 3 |
+
size 408930
|