seawolf2357 commited on
Commit
c5d7fd8
ยท
verified ยท
1 Parent(s): 82b5fd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -1,28 +1,33 @@
1
  import gradio as gr
2
  import requests
3
 
4
- # ์™ธ๋ถ€ URL์— ์ ‘์†ํ•˜๋Š” ํ•จ์ˆ˜ ์ •์˜
5
  def check_connection(url):
6
  try:
7
- # URL์— GET ์š”์ฒญ์„ ๋ณด๋ƒ…๋‹ˆ๋‹ค.
8
  response = requests.get(url)
9
- # HTTP ์ƒํƒœ ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ์ ‘์† ์ƒํƒœ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
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
- print("Connection failed")
17
- return "Connection failed"
18
 
19
- # ๊ทธ๋ผ๋””์˜ค UI ์ •์˜
20
- url_input = gr.Interface.TextInput(label="URL", placeholder="Enter the URL to check")
21
- output_text = gr.Interface.Textbox(label="Connection Status")
22
 
23
- # ๊ทธ๋ผ๋””์˜ค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
24
  title = "URL Connection Checker"
25
- description = "Enter a URL and click 'Check Connection' to see the HTTP status code and connection status."
26
- examples = [["https://seawolf2357-fastgpt.hf.space/"]]
27
- timer_input = gr.Interface.Slider(minimum=1, maximum=60, default=5, label="Check Interval (minutes)")
28
- gr.Interface(fn=check_connection, inputs=url_input, outputs=output_text, title=title, description=description, examples=examples).launch(inline=False, inbrowser=True, share=True)
 
 
 
 
 
 
 
 
 
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)