Spaces:
Running
Running
File size: 2,139 Bytes
504b188 bfaa32a 669c50e ea0cebb 799e478 bfaa32a 504b188 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# app.py
import streamlit as st
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import SVC
import joblib
# Load the SVM model and TF-IDF vectorizer
svm_model = joblib.load('svm_model.pkl')
tfidf_vectorizer = joblib.load('tfidf_vectorizer.pkl')
def preprocess_input(text):
# Preprocess the input text (e.g., convert to lowercase, remove special characters, etc.)
# Implement your specific preprocessing steps based on the training data
processed_text = text.lower()
# Add more preprocessing steps as needed
return processed_text
def predict_bullying(text):
# Preprocess input text
processed_text = preprocess_input(text)
# Convert text to numerical representation using TF-IDF
text_tfidf = tfidf_vectorizer.transform([processed_text])
# Make prediction using the SVM model
prediction = svm_model.predict(text_tfidf)[0]
return prediction
# Streamlit UI
def main():
st.title("Cyberbullying Detection App (Arabic)")
user_input = st.text_area("Enter a text for cyberbullying detection:")
if st.button("Predict"):
if user_input:
prediction = predict_bullying(user_input)
if prediction == "Bullying":
st.write(f"<span style='color:red; font-weight:bold'>{prediction}</span>", unsafe_allow_html=True)
else:
st.write(f"<span style='color:cyan; font-weight:bold'>{prediction}</span>", unsafe_allow_html=True)
else:
st.warning("Please enter text for prediction.")
st.header("Sample Texts")
st.write("<span style='color:red; font-weight:bold'>ุนููุงู ุฎุฑุง ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐๐๐๐๐</span>", unsafe_allow_html=True)
st.write("<span style='color:red; font-weight:bold'>ุฃูุช ููุจ</span>", unsafe_allow_html=True)
st.write("ูุงู
ุจุงุฑุญ ุงุดุชุฑูุช ุจููุงุชู . ุดุบูู ุฌู
ูู ูุญูู . ูุงูุซุฑ ุดู ุจุนุฌุจูู ุจ ููุฏูููุงุชู ุงูู ุจุชุญุณุณูู ุงูู ู
ุนู .")
st.write("ุงููุฏ ุจูุดุฌุนู โคโค")
if __name__ == "__main__":
main()
|