Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- README.md +13 -12
- app.py +36 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
-
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
1 |
+
---
|
2 |
+
title: test internet
|
3 |
+
emoji: π
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.34.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import gradio as gr
|
3 |
+
import requests
|
4 |
+
|
5 |
+
def check_internet_gr(url: str):
|
6 |
+
try:
|
7 |
+
response = requests.get(url, timeout=30, verify=False)
|
8 |
+
if response.status_code == 200:
|
9 |
+
print(f"{url} is working. Status code:", response.status_code)
|
10 |
+
gr.Info(f"{url} is working. Status code: {response.status_code}")
|
11 |
+
else:
|
12 |
+
print(f"Connected to {url}, but the server returned an error. Status code:", response.status_code)
|
13 |
+
gr.Info(f"Connected to {url}, but the server returned an error. Status code: {response.status_code}")
|
14 |
+
except requests.ConnectionError as e:
|
15 |
+
print(f"No connection.", e)
|
16 |
+
gr.Info(f"No connection. {e}")
|
17 |
+
except requests.Timeout as e:
|
18 |
+
print(f"Request timed out.", e)
|
19 |
+
gr.Info(f"Request timed out. {e}")
|
20 |
+
except Exception as e:
|
21 |
+
print(f"An error occurred: {e}")
|
22 |
+
gr.Info(f"An error occurred: {e}")
|
23 |
+
|
24 |
+
@spaces.GPU
|
25 |
+
def test(url: str):
|
26 |
+
check_internet_gr(url)
|
27 |
+
return ""
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
url = gr.Textbox(label="URL", value="https://api.openai.com")
|
31 |
+
run_button = gr.Button("Submit", variant="primary")
|
32 |
+
info_md = gr.Markdown("<br><br><br>")
|
33 |
+
|
34 |
+
run_button.click(test, [url], [info_md])
|
35 |
+
|
36 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
pydantic==2.10.6
|