Download api_key.py from Mummar/lstm: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/Mummar/lstm/resolve/main/api_key.py
- Command line
-
hf download hf://spaces/Mummar/lstm/api_key.py
-
curl -L -o api_key.py https://huggingface.co/spaces/Mummar/lstm/resolve/main/api_key.py
1.01 kB
| from getpass import getpass | |
| import requests | |
| import os | |
| hard_reset = False ## <-- Set to True if you want to reset your NVIDIA_API_KEY | |
| while "nvapi-" not in os.environ.get("NVIDIA_API_KEY", "") or hard_reset: | |
| try: | |
| assert not hard_reset | |
| response = requests.get("http://docker_router:8070/get_key").json() | |
| assert response.get('nvapi_key') | |
| except: response = {'nvapi_key' : getpass("NVIDIA API Key: ")} | |
| os.environ["NVIDIA_API_KEY"] = response.get("nvapi_key") | |
| try: requests.post("http://docker_router:8070/set_key/", json={'nvapi_key' : os.environ["NVIDIA_API_KEY"]}).json() | |
| except: pass | |
| hard_reset = False | |
| if "nvapi-" not in os.environ.get("NVIDIA_API_KEY", ""): | |
| print("[!] API key assignment failed. Make sure it starts with `nvapi-` as generated from the model pages.") | |
| print(f"Retrieved NVIDIA_API_KEY beginning with \"{os.environ.get('NVIDIA_API_KEY')[:9]}...\"") | |
| from langchain_nvidia_ai_endpoints._common import NVEModel | |
| NVEModel().available_models |