Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# PhishTank configuration
|
| 5 |
+
PHISHTANK_USER_AGENT = "phishtank/PHISH"
|
| 6 |
+
|
| 7 |
+
def check_url_phishtank(url):
|
| 8 |
+
endpoint = "https://checkurl.phishtank.com/checkurl/"
|
| 9 |
+
payload = {"url": url, "format": "json"}
|
| 10 |
+
headers = {"User-Agent": PHISHTANK_USER_AGENT}
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
response = requests.post(endpoint, data=payload, headers=headers, timeout=5)
|
| 14 |
+
response.raise_for_status()
|
| 15 |
+
data = response.json()
|
| 16 |
+
|
| 17 |
+
if data.get('results', {}).get('in_database', False) and data.get('results', {}).get('verified', False):
|
| 18 |
+
return "Phishing"
|
| 19 |
+
return "Legitimate"
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return "Legitimate"
|
| 22 |
+
|
| 23 |
+
def predict_url(url):
|
| 24 |
+
try:
|
| 25 |
+
if not url.startswith(("http://", "https://")):
|
| 26 |
+
url = "https://" + url
|
| 27 |
+
|
| 28 |
+
# Check PhishTank
|
| 29 |
+
pt_result = check_url_phishtank(url)
|
| 30 |
+
return pt_result
|
| 31 |
+
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"Error in URL prediction: {e}")
|
| 34 |
+
return "Legitimate"
|
| 35 |
+
|
| 36 |
+
# Gradio Interface
|
| 37 |
+
interface = gr.Interface(
|
| 38 |
+
fn=predict_url,
|
| 39 |
+
inputs=gr.Textbox(label="Enter URL", placeholder="https://example.com"),
|
| 40 |
+
outputs=gr.Textbox(label="Result"),
|
| 41 |
+
title="Phishing URL Detector (PhishTank Only)",
|
| 42 |
+
description="Check if a URL is in the PhishTank database",
|
| 43 |
+
examples=[
|
| 44 |
+
["https://www.apple.com"],
|
| 45 |
+
["https://login-facebook-secure.xyz/login.php"],
|
| 46 |
+
["https://bit.ly/suspicious-download"]
|
| 47 |
+
]
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|