import gradio as gr import requests from getStatus import run # Assuming this module contains the run function def getURL(URL): if URL.startswith("http://") or URL.startswith("https://"): websiteUrl = URL else: websiteUrl = "http://" + URL return websiteUrl def setHeaders(websiteUrl): try: URL = getURL(websiteUrl) web_response = requests.get(URL, timeout=5) user_agent = web_response.request.headers['User-Agent'] headers = {'User-Agent': user_agent} return headers except requests.RequestException as e: print(f"Error fetching headers: {e}") return None def websiteStatus(websiteUrl, user_agent_choice): try: URL = getURL(websiteUrl) if user_agent_choice == "Your Browser Headers": headers = setHeaders(websiteUrl) else: headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} web_response = requests.get(URL, headers=headers) web_status = str(web_response.status_code) code, webstatus, status, morestatus = run(web_status) print(f"Processed Output: {code}, {webstatus}, {status}, {morestatus}") # Debug print return code, webstatus, status, morestatus except requests.ConnectionError: error = f"Failed to connect to {websiteUrl}" return error, error, error, error except requests.Timeout: error = f"Request to {websiteUrl} timed out" return error, error, error, error except requests.RequestException as e: error = f"An error occurred: {e}" return error, error, error, error # Create a Gradio interface app = gr.Interface( fn=websiteStatus, inputs = [ gr.Textbox(label="Enter URL", placeholder="https://google.com", type="text"), gr.Radio(["Your Browser Headers", "Our Server Headers"], label="Select User Agent") ], outputs = [ gr.Textbox(label="Code", type="text"), gr.Textbox(label="Server/Website Status", type="text"), gr.Textbox(label="Code Status", type="text"), gr.Textbox(label="More Code Status Information", type="text") ], title="Website HTTP Status Checker
by Nayan Kasturi aka Raanna.
Checkout my Github for more projects and contact info.", description="This app scans the website for HTTP statuses.
Licenced under cc-by-nc-sa-4.0", api_name="get", concurrency_limit=10 ) if __name__ == "__main__": app.launch()