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