Amiruzzaman commited on
Commit
504b188
1 Parent(s): 1de6f64

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +48 -0
  2. requirements.txt +4 -0
  3. svm_model.pkl +3 -0
  4. tfidf_vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ import pandas as pd
4
+ from sklearn.feature_extraction.text import TfidfVectorizer
5
+ from sklearn.svm import SVC
6
+ import joblib
7
+
8
+ # Load the SVM model and TF-IDF vectorizer
9
+ svm_model = joblib.load('svm_model.pkl')
10
+ tfidf_vectorizer = joblib.load('tfidf_vectorizer.pkl')
11
+
12
+ def preprocess_input(text):
13
+ # Preprocess the input text (e.g., convert to lowercase, remove special characters, etc.)
14
+ # Implement your specific preprocessing steps based on the training data
15
+ processed_text = text.lower()
16
+ # Add more preprocessing steps as needed
17
+
18
+ return processed_text
19
+
20
+ def predict_bullying(text):
21
+ # Preprocess input text
22
+ processed_text = preprocess_input(text)
23
+
24
+ # Convert text to numerical representation using TF-IDF
25
+ text_tfidf = tfidf_vectorizer.transform([processed_text])
26
+
27
+ # Make prediction using the SVM model
28
+ prediction = svm_model.predict(text_tfidf)[0]
29
+
30
+ return prediction
31
+
32
+ # Streamlit UI
33
+ def main():
34
+ st.title("Cyberbullying Detection App (Arabic)")
35
+ user_input = st.text_area("Enter a text for cyberbullying detection:")
36
+
37
+ if st.button("Predict"):
38
+ if user_input:
39
+ prediction = predict_bullying(user_input)
40
+ if prediction == "Bullying":
41
+ st.write(f"<span style='color:red; font-weight:bold'>{prediction}</span>", unsafe_allow_html=True)
42
+ else:
43
+ st.write(f"<span style='color:cyan; font-weight:bold'>{prediction}</span>", unsafe_allow_html=True)
44
+ else:
45
+ st.warning("Please enter text for prediction.")
46
+
47
+ if __name__ == "__main__":
48
+ main()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ scikit-learn
4
+ joblib
svm_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86cc2e53d9ed03b786c0b0d08162e63cd2a0eddf30c9ef3548837178f326a034
3
+ size 384771
tfidf_vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86a2ed13d6b9ccca4d42dd85f37ef23980bfb8f6c5090bd471f7d653bf2203df
3
+ size 493534