Spaces:
Sleeping
Sleeping
Download app.py from PyarasaniSrinivas/CyberShield: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/PyarasaniSrinivas/CyberShield/resolve/main/app.py
- Command line
-
hf download hf://spaces/PyarasaniSrinivas/CyberShield/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PyarasaniSrinivas/CyberShield/resolve/main/app.py
1.65 kB
| import streamlit as st | |
| import joblib | |
| from textcleaning import clean_documents | |
| import pandas as pd | |
| model = joblib.load("model.pkl") | |
| st.set_page_config( | |
| page_title="Cyberbullying Detection", | |
| page_icon="🛡️", | |
| layout="centered" | |
| ) | |
| st.markdown( | |
| """ | |
| <h1 style='text-align:center;color:#4CAF50;'> | |
| 🛡️Cyberbullying Detection & Classification System | |
| </h1> | |
| <p style='text-align:center;font-size:18px;color:gray;'> | |
| Enter a social media message below to detect whether it contains cyberbullying. | |
| </p> | |
| <hr> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| user_text = st.text_area( | |
| "✍️ Enter Text", | |
| placeholder="Type or paste a message here...", | |
| height=180 | |
| ) | |
| col1, col2 = st.columns([1, 1]) | |
| with col1: | |
| predict = st.button("🔍 Predict", use_container_width=True) | |
| with col2: | |
| clear = st.button("🗑️ Clear Output", use_container_width=True) | |
| if clear: | |
| st.rerun() | |
| if predict: | |
| if user_text.strip(): | |
| user_series = pd.Series([user_text]) | |
| with st.spinner("Analyzing text..."): | |
| prediction = model.predict(user_series)[0] | |
| st.markdown("---") | |
| st.subheader("📊 Prediction Result") | |
| if prediction == "not_cyberbullying": | |
| st.success(f"✅ **Prediction:** {prediction}") | |
| else: | |
| st.error(f"🚨 **Prediction:** {prediction}") | |
| else: | |
| st.warning("⚠️ Please enter some text before clicking Predict.") | |
| st.markdown("---") | |
| st.caption("Developed using Streamlit | Scikit-learn | NLP | TF-IDF | Logistic Regression") |