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)