Spaces:
Paused
Paused
| import spaces | |
| import gradio as gr | |
| import requests | |
| def check_internet_gr(url: str, model: str, key: str): | |
| try: | |
| payload = {"model":model,"input":["test"]} | |
| headers = {"Authorization": f"Bearer {key}"} | |
| response = requests.post(url, json=payload, headers=headers, timeout=30, allow_redirects=False, verify=False) | |
| if response.status_code == 200: | |
| print(f"{url} is working. Status code:", response.status_code) | |
| gr.Info(f"{url} is working. Status code: {response.status_code}") | |
| else: | |
| print(f"Connected to {url}, but the server returned an error. Status code:", response.status_code) | |
| gr.Info(f"Connected to {url}, but the server returned an error. Status code: {response.status_code}") | |
| except requests.ConnectionError as e: | |
| print(f"No connection.", e) | |
| gr.Info(f"No connection. {e}") | |
| except requests.Timeout as e: | |
| print(f"Request timed out.", e) | |
| gr.Info(f"Request timed out. {e}") | |
| except Exception as e: | |
| print(f"An error occurred: {e}") | |
| gr.Info(f"An error occurred: {e}") | |
| return "" | |
| with gr.Blocks() as demo: | |
| url = gr.Textbox(label="URL", value="https://api.ollama.cloud/v1/embeddings") | |
| model = gr.Textbox(label="Model", value="nomic-embed-text") | |
| key = gr.Textbox(label="Key", value="put ollama key") | |
| run_button = gr.Button("Submit", variant="primary") | |
| info_md = gr.Markdown("<br><br><br>") | |
| run_button.click(check_internet_gr, [url, model, key], [info_md]) | |
| demo.launch() | |