Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
@st.cache_resource
|
| 5 |
+
def load_classifier(model_path: str):
|
| 6 |
+
# Loads the URLGuardian classifier from the Hugging Face Hub.
|
| 7 |
+
return pipeline("text-classification", model=model_path)
|
| 8 |
+
|
| 9 |
+
# App Title and description
|
| 10 |
+
st.title("URL Typosquatting Detection with URLGuardian")
|
| 11 |
+
st.markdown(
|
| 12 |
+
"This app uses the **URLGuardian** classifier by Anvilogic from the Hugging Face Hub to detect potential typosquatting. "
|
| 13 |
+
"Enter a legitimate URL and a potentially typosquatted URL to see the classifier's prediction."
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# Load the classifier model from Hugging Face
|
| 17 |
+
model_path = "Anvilogic/URLGuardian" # Model repository on Hugging Face
|
| 18 |
+
classifier = load_classifier(model_path)
|
| 19 |
+
|
| 20 |
+
# URL inputs
|
| 21 |
+
url = st.text_input("Enter the URL:", value="https://example.com")
|
| 22 |
+
|
| 23 |
+
# Typosquatting detection on button click
|
| 24 |
+
if st.button("Check Typosquatting"):
|
| 25 |
+
if legit_url and suspect_url:
|
| 26 |
+
|
| 27 |
+
result = classifier(url)[0]
|
| 28 |
+
label = result['label']
|
| 29 |
+
score = result['score']
|
| 30 |
+
|
| 31 |
+
# Adjust the label names as per the model's documentation.
|
| 32 |
+
# This example assumes the label for a typosquatted URL might include "typo".
|
| 33 |
+
if "typo" in label.lower():
|
| 34 |
+
st.success(
|
| 35 |
+
f"The model predicts that '{suspect_url}' is likely a typosquatted version of '{legit_url}' "
|
| 36 |
+
f"with a confidence of {score * 100:.2f}%."
|
| 37 |
+
)
|
| 38 |
+
else:
|
| 39 |
+
st.warning(
|
| 40 |
+
f"The model predicts that '{suspect_url}' is NOT likely a typosquatted version of '{legit_url}' "
|
| 41 |
+
f"with a confidence of {score * 100:.2f}%."
|
| 42 |
+
)
|
| 43 |
+
else:
|
| 44 |
+
st.error("Please enter both a legitimate URL and a potentially typosquatted URL.")
|