Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,22 @@ def load_classifier(model_path: str):
|
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 11 |
return pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
st.title("URL Typosquatting Detection with URLGuardian")
|
| 14 |
st.markdown(
|
| 15 |
"This app uses the **URLGuardian** classifier developed by Anvilogic to detect potential suspicious URL. "
|
|
@@ -26,13 +42,14 @@ if st.button("Check Safety of the url"):
|
|
| 26 |
result = classifier(url)[0]
|
| 27 |
label = result["label"]
|
| 28 |
score = result["score"]
|
|
|
|
| 29 |
if label=='Safe':
|
| 30 |
st.success(
|
| 31 |
-
f"The URL '{
|
| 32 |
)
|
| 33 |
else:
|
| 34 |
st.error(
|
| 35 |
-
f"The URL '{
|
| 36 |
)
|
| 37 |
# Optionally, you can display the full result for debugging purposes:
|
| 38 |
st.write("Full classification output:", result)
|
|
|
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 11 |
return pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 12 |
|
| 13 |
+
def defang_url(url: str) -> str:
|
| 14 |
+
"""
|
| 15 |
+
Defangs the URL to prevent it from being clickable.
|
| 16 |
+
This function replaces the protocol and dots.
|
| 17 |
+
For example:
|
| 18 |
+
https://example.com --> hxxps://example[.]com
|
| 19 |
+
"""
|
| 20 |
+
# Replace the protocol
|
| 21 |
+
if url.startswith("https://"):
|
| 22 |
+
url = url.replace("https://", "hxxps://")
|
| 23 |
+
elif url.startswith("http://"):
|
| 24 |
+
url = url.replace("http://", "hxxp://")
|
| 25 |
+
|
| 26 |
+
# Replace periods in the rest of the URL
|
| 27 |
+
return url.replace(".", "[.]")
|
| 28 |
+
|
| 29 |
st.title("URL Typosquatting Detection with URLGuardian")
|
| 30 |
st.markdown(
|
| 31 |
"This app uses the **URLGuardian** classifier developed by Anvilogic to detect potential suspicious URL. "
|
|
|
|
| 42 |
result = classifier(url)[0]
|
| 43 |
label = result["label"]
|
| 44 |
score = result["score"]
|
| 45 |
+
defanged_url = defang_url(url)
|
| 46 |
if label=='Safe':
|
| 47 |
st.success(
|
| 48 |
+
f"The URL '{defanged_url}' is considered safe with a confidence of {score * 100:.2f}%."
|
| 49 |
)
|
| 50 |
else:
|
| 51 |
st.error(
|
| 52 |
+
f"The URL '{defanged_url}' is considered suspicious with a confidence of {score * 100:.2f}%."
|
| 53 |
)
|
| 54 |
# Optionally, you can display the full result for debugging purposes:
|
| 55 |
st.write("Full classification output:", result)
|