Spaces:
Running
Running
File size: 1,332 Bytes
dd7fe10 e26a87b dd7fe10 e26a87b dd7fe10 82b5fd4 dd7fe10 b281c94 f49559c |
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 |
import gradio as gr
import requests
# μΈλΆ URLμ μ μνλ ν¨μ μ μ
def check_connection(url):
try:
# URLμ GET μμ²μ 보λ
λλ€.
response = requests.get(url)
# HTTP μν μ½λμ ν¨κ» μ μ μνλ₯Ό λ°νν©λλ€.
status = f"Status Code: {response.status_code}, Connection Status: {'Connection successful' if response.status_code == 200 else 'Connection failed'}"
# μ°κ²° μνλ₯Ό μΆλ ₯ν©λλ€.
print(status)
return status
except:
# μμ²μ΄ μ€ν¨νμ κ²½μ°
print("Connection failed")
return "Connection failed"
# κ·ΈλΌλμ€ UI μ μ
url_input = gr.Interface.TextInput(label="URL", placeholder="Enter the URL to check")
output_text = gr.Interface.Textbox(label="Connection Status")
# κ·ΈλΌλμ€ μ ν리μΌμ΄μ
μ€ν
title = "URL Connection Checker"
description = "Enter a URL and click 'Check Connection' to see the HTTP status code and connection status."
examples = [["https://seawolf2357-fastgpt.hf.space/"]]
timer_input = gr.Interface.Slider(minimum=1, maximum=60, default=5, label="Check Interval (minutes)")
gr.Interface(fn=check_connection, inputs=url_input, outputs=output_text, title=title, description=description, examples=examples).launch(inline=False, inbrowser=True, share=True)
|