Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
def check_connection(url):
|
| 6 |
try:
|
| 7 |
-
#
|
| 8 |
response = requests.get(url)
|
| 9 |
-
#
|
| 10 |
status = f"Status Code: {response.status_code}, Connection Status: {'Connection successful' if response.status_code == 200 else 'Connection failed'}"
|
| 11 |
-
# ์ฐ๊ฒฐ ์ํ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
|
| 12 |
-
print(status)
|
| 13 |
return status
|
| 14 |
-
except:
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
return "Connection failed"
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
url_input = gr.
|
| 21 |
-
output_text = gr.
|
| 22 |
|
| 23 |
-
#
|
| 24 |
title = "URL Connection Checker"
|
| 25 |
-
description = "Enter a URL and
|
| 26 |
-
examples = [["https://
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# Define a function to check the connection to an external URL
|
| 5 |
def check_connection(url):
|
| 6 |
try:
|
| 7 |
+
# Send a GET request to the URL
|
| 8 |
response = requests.get(url)
|
| 9 |
+
# Return the HTTP status code and connection status
|
| 10 |
status = f"Status Code: {response.status_code}, Connection Status: {'Connection successful' if response.status_code == 200 else 'Connection failed'}"
|
|
|
|
|
|
|
| 11 |
return status
|
| 12 |
+
except Exception as e:
|
| 13 |
+
# In case the request fails
|
| 14 |
+
return f"Connection failed: {str(e)}"
|
|
|
|
| 15 |
|
| 16 |
+
# Define Gradio interface elements
|
| 17 |
+
url_input = gr.inputs.Text(label="URL", placeholder="Enter the URL to check")
|
| 18 |
+
output_text = gr.outputs.Textbox(label="Connection Status")
|
| 19 |
|
| 20 |
+
# Define Gradio app configuration
|
| 21 |
title = "URL Connection Checker"
|
| 22 |
+
description = "Enter a URL and check its HTTP status code and connection status."
|
| 23 |
+
examples = [["https://www.example.com"]]
|
| 24 |
+
|
| 25 |
+
# Create and launch the Gradio app
|
| 26 |
+
gr.Interface(
|
| 27 |
+
fn=check_connection,
|
| 28 |
+
inputs=url_input,
|
| 29 |
+
outputs=output_text,
|
| 30 |
+
title=title,
|
| 31 |
+
description=description,
|
| 32 |
+
examples=examples
|
| 33 |
+
).launch(share=True)
|