Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +41 -0
streamlit_app.py
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load AI model
|
| 5 |
+
classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="mrm8488/bert-tiny-finetuned-sms-spam-detection"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# Page config
|
| 11 |
+
st.set_page_config(
|
| 12 |
+
page_title="AI Cyber Threat Detector",
|
| 13 |
+
page_icon="🛡️"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
st.title("🛡️ AI Cyber Threat Detector")
|
| 17 |
+
|
| 18 |
+
text = st.text_input(
|
| 19 |
+
"Enter URL or message"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if st.button("Analyze"):
|
| 23 |
+
|
| 24 |
+
if text.strip() == "":
|
| 25 |
+
st.warning("Please enter text")
|
| 26 |
+
|
| 27 |
+
else:
|
| 28 |
+
|
| 29 |
+
with st.spinner("Analyzing..."):
|
| 30 |
+
|
| 31 |
+
result = classifier(text)[0]
|
| 32 |
+
|
| 33 |
+
label = result["label"]
|
| 34 |
+
confidence = round(result["score"] * 100, 2)
|
| 35 |
+
|
| 36 |
+
if label.lower() == "spam":
|
| 37 |
+
st.error(f"⚠️ Threat Detected: {label}")
|
| 38 |
+
else:
|
| 39 |
+
st.success(f"✅ Safe: {label}")
|
| 40 |
+
|
| 41 |
+
st.write("Confidence:", confidence, "%")
|