Spaces:
Running
Running
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) | |