Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,68 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
from getStatus import run # Assuming this module contains the run function
|
| 4 |
-
|
| 5 |
-
def getURL(URL):
|
| 6 |
-
if URL.startswith("http://") or URL.startswith("https://"):
|
| 7 |
-
websiteUrl = URL
|
| 8 |
-
else:
|
| 9 |
-
websiteUrl = "http://" + URL
|
| 10 |
-
return websiteUrl
|
| 11 |
-
|
| 12 |
-
def setHeaders(websiteUrl):
|
| 13 |
-
try:
|
| 14 |
-
URL = getURL(websiteUrl)
|
| 15 |
-
web_response = requests.get(URL, timeout=5)
|
| 16 |
-
user_agent = web_response.request.headers['User-Agent']
|
| 17 |
-
headers = {'User-Agent': user_agent}
|
| 18 |
-
return headers
|
| 19 |
-
except requests.RequestException as e:
|
| 20 |
-
print(f"Error fetching headers: {e}")
|
| 21 |
-
return None
|
| 22 |
-
|
| 23 |
-
def websiteStatus(websiteUrl, user_agent_choice):
|
| 24 |
-
try:
|
| 25 |
-
URL = getURL(websiteUrl)
|
| 26 |
-
|
| 27 |
-
if user_agent_choice == "Your Browser Headers":
|
| 28 |
-
headers = setHeaders(websiteUrl)
|
| 29 |
-
else:
|
| 30 |
-
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'}
|
| 31 |
-
|
| 32 |
-
web_response = requests.get(URL, headers=headers)
|
| 33 |
-
web_status = str(web_response.status_code)
|
| 34 |
-
code, webstatus, status, morestatus = run(web_status)
|
| 35 |
-
print(f"Processed Output: {code}, {webstatus}, {status}, {morestatus}") # Debug print
|
| 36 |
-
return code, webstatus, status, morestatus
|
| 37 |
-
|
| 38 |
-
except requests.ConnectionError:
|
| 39 |
-
error = f"Failed to connect to {websiteUrl}"
|
| 40 |
-
return error, error, error, error
|
| 41 |
-
except requests.Timeout:
|
| 42 |
-
error = f"Request to {websiteUrl} timed out"
|
| 43 |
-
return error, error, error, error
|
| 44 |
-
except requests.RequestException as e:
|
| 45 |
-
error = f"An error occurred: {e}"
|
| 46 |
-
return error, error, error, error
|
| 47 |
-
|
| 48 |
-
# Create a Gradio interface
|
| 49 |
-
app = gr.Interface(
|
| 50 |
-
fn=websiteStatus,
|
| 51 |
-
inputs=[
|
| 52 |
-
gr.Textbox(label="Enter URL", placeholder="https://google.com", type="text"),
|
| 53 |
-
gr.Radio(["Your Browser Headers", "Our Server Headers"], label="Select User Agent")
|
| 54 |
-
],
|
| 55 |
-
outputs=[
|
| 56 |
-
gr.Textbox(label="Code", type="text"),
|
| 57 |
-
gr.Textbox(label="Server/Website Status", type="text"),
|
| 58 |
-
gr.Textbox(label="Code Status", type="text"),
|
| 59 |
-
gr.Textbox(label="More Code Status Information", type="text")
|
| 60 |
-
]
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from getStatus import run # Assuming this module contains the run function
|
| 4 |
+
|
| 5 |
+
def getURL(URL):
|
| 6 |
+
if URL.startswith("http://") or URL.startswith("https://"):
|
| 7 |
+
websiteUrl = URL
|
| 8 |
+
else:
|
| 9 |
+
websiteUrl = "http://" + URL
|
| 10 |
+
return websiteUrl
|
| 11 |
+
|
| 12 |
+
def setHeaders(websiteUrl):
|
| 13 |
+
try:
|
| 14 |
+
URL = getURL(websiteUrl)
|
| 15 |
+
web_response = requests.get(URL, timeout=5)
|
| 16 |
+
user_agent = web_response.request.headers['User-Agent']
|
| 17 |
+
headers = {'User-Agent': user_agent}
|
| 18 |
+
return headers
|
| 19 |
+
except requests.RequestException as e:
|
| 20 |
+
print(f"Error fetching headers: {e}")
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
def websiteStatus(websiteUrl, user_agent_choice):
|
| 24 |
+
try:
|
| 25 |
+
URL = getURL(websiteUrl)
|
| 26 |
+
|
| 27 |
+
if user_agent_choice == "Your Browser Headers":
|
| 28 |
+
headers = setHeaders(websiteUrl)
|
| 29 |
+
else:
|
| 30 |
+
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'}
|
| 31 |
+
|
| 32 |
+
web_response = requests.get(URL, headers=headers)
|
| 33 |
+
web_status = str(web_response.status_code)
|
| 34 |
+
code, webstatus, status, morestatus = run(web_status)
|
| 35 |
+
print(f"Processed Output: {code}, {webstatus}, {status}, {morestatus}") # Debug print
|
| 36 |
+
return code, webstatus, status, morestatus
|
| 37 |
+
|
| 38 |
+
except requests.ConnectionError:
|
| 39 |
+
error = f"Failed to connect to {websiteUrl}"
|
| 40 |
+
return error, error, error, error
|
| 41 |
+
except requests.Timeout:
|
| 42 |
+
error = f"Request to {websiteUrl} timed out"
|
| 43 |
+
return error, error, error, error
|
| 44 |
+
except requests.RequestException as e:
|
| 45 |
+
error = f"An error occurred: {e}"
|
| 46 |
+
return error, error, error, error
|
| 47 |
+
|
| 48 |
+
# Create a Gradio interface
|
| 49 |
+
app = gr.Interface(
|
| 50 |
+
fn=websiteStatus,
|
| 51 |
+
inputs=[
|
| 52 |
+
gr.Textbox(label="Enter URL", placeholder="https://google.com", type="text"),
|
| 53 |
+
gr.Radio(["Your Browser Headers", "Our Server Headers"], label="Select User Agent")
|
| 54 |
+
],
|
| 55 |
+
outputs=[
|
| 56 |
+
gr.Textbox(label="Code", type="text"),
|
| 57 |
+
gr.Textbox(label="Server/Website Status", type="text"),
|
| 58 |
+
gr.Textbox(label="Code Status", type="text"),
|
| 59 |
+
gr.Textbox(label="More Code Status Information", type="text")
|
| 60 |
+
]
|
| 61 |
+
title="Website HTTP Status Checker<br> by <a href='https://nayankasturi.eu.org'>Nayan Kasturi</a> aka Raanna.<br> Checkout my <a href='https://github.com/raannakasturi'>Github</a> for more projects and contact info.",
|
| 62 |
+
description="This app scans the website for HTTP statuses.<br> Licenced under <a href='https://creativecommons.org/licenses/by-nc-sa/4.0/'>cc-by-nc-sa-4.0</a>",
|
| 63 |
+
api_name="get",
|
| 64 |
+
concurrency_limit=10
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
app.launch()
|