Spaces:
Running
Running
File size: 1,143 Bytes
dd7fe10 c5d7fd8 dd7fe10 c5d7fd8 dd7fe10 c5d7fd8 e26a87b c5d7fd8 dd7fe10 c5d7fd8 dd7fe10 c5d7fd8 dd7fe10 c5d7fd8 |
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 |
import gradio as gr
import requests
# Define a function to check the connection to an external URL
def check_connection(url):
try:
# Send a GET request to the URL
response = requests.get(url)
# Return the HTTP status code and connection status
status = f"Status Code: {response.status_code}, Connection Status: {'Connection successful' if response.status_code == 200 else 'Connection failed'}"
return status
except Exception as e:
# In case the request fails
return f"Connection failed: {str(e)}"
# Define Gradio interface elements
url_input = gr.inputs.Text(label="URL", placeholder="Enter the URL to check")
output_text = gr.outputs.Textbox(label="Connection Status")
# Define Gradio app configuration
title = "URL Connection Checker"
description = "Enter a URL and check its HTTP status code and connection status."
examples = [["https://www.example.com"]]
# Create and launch the Gradio app
gr.Interface(
fn=check_connection,
inputs=url_input,
outputs=output_text,
title=title,
description=description,
examples=examples
).launch(share=True)
|