John6666 commited on
Commit
85cb4eb
·
verified ·
1 Parent(s): 6257ec6

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +13 -12
  2. app.py +37 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
- ---
2
- title: Test Internet 3
3
- emoji: 😻
4
- colorFrom: gray
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
+ ---
2
+ title: test internet ollama
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,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import requests
4
+
5
+ @spaces.GPU
6
+ def check_internet_gr(url: str, model: str, key: str):
7
+ try:
8
+ payload = {"model":model,"input":["test"]}
9
+ headers = {"Authorization": f"Bearer {key}"}
10
+ response = requests.post(url, json=payload, headers=headers, timeout=30, allow_redirects=False, verify=False)
11
+ if response.status_code == 200:
12
+ print(f"{url} is working. Status code:", response.status_code)
13
+ gr.Info(f"{url} is working. Status code: {response.status_code}")
14
+ else:
15
+ print(f"Connected to {url}, but the server returned an error. Status code:", response.status_code)
16
+ gr.Info(f"Connected to {url}, but the server returned an error. Status code: {response.status_code}")
17
+ except requests.ConnectionError as e:
18
+ print(f"No connection.", e)
19
+ gr.Info(f"No connection. {e}")
20
+ except requests.Timeout as e:
21
+ print(f"Request timed out.", e)
22
+ gr.Info(f"Request timed out. {e}")
23
+ except Exception as e:
24
+ print(f"An error occurred: {e}")
25
+ gr.Info(f"An error occurred: {e}")
26
+ return ""
27
+
28
+ with gr.Blocks() as demo:
29
+ url = gr.Textbox(label="URL", value="https://api.ollama.cloud/v1/embeddings")
30
+ model = gr.Textbox(label="Model", value="nomic-embed-text")
31
+ key = gr.Textbox(label="Key", value="put ollama key")
32
+ run_button = gr.Button("Submit", variant="primary")
33
+ info_md = gr.Markdown("<br><br><br>")
34
+
35
+ run_button.click(check_internet_gr, [url, model, key], [info_md])
36
+
37
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ huggingface_hub
2
+ pydantic==2.10.6