Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hugging Face Hub themes require an internet connection to load, even if they're cached #3567

Closed
1 task done
space-nuko opened this issue Mar 22, 2023 · 3 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@space-nuko
Copy link
Contributor

Describe the bug

From what I understand the HF Hub downloader has a cache for if the spaces file is already downloaded. However Gradio seems to do some extra processing beforehand that requires the use of the HF API, so in practice those themes can only be used if there's an Internet connection

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

  1. Enable Internet
  2. Download/use a theme with Theme.from_hub(...)
  3. Disable Internet
  4. Re-run the program and try to use the same theme

Screenshot

No response

Logs

$ python
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import gradio as gr
>>> gr.themes.ThemeClass.from_hub('gradio/soft')
Downloading (…)_schema%400.0.1.json:   0%|                                                                                                                          | 0.00/12.9k [00:00<?, ?B/s] Downloading (…)_schema%400.0.1.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 12.9k/12.9k [00:00<00:00, 6.46MB/s]
<gradio.themes.base.ThemeClass object at 0x0000019DC7B97C40>

>>> gr.themes.ThemeClass.from_hub('gradio/soft')
<gradio.themes.base.ThemeClass object at 0x0000019DEF015540>

>>> # (disable internet...)

>>> gr.themes.ThemeClass.from_hub('gradio/soft')
Traceback (most recent call last):
  File "E:\sd\venv\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "E:\sd\venv\lib\site-packages\urllib3\util\connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\a\AppData\Local\Programs\Python\Python310\lib\socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "E:\sd\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "E:\sd\venv\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "E:\sd\venv\lib\site-packages\urllib3\connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
  File "E:\sd\venv\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000019DEF4B3940>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd\venv\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "E:\sd\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "E:\sd\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/spaces/gradio/soft (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000019DEF4B3940>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\sd\venv\lib\site-packages\gradio\themes\base.py", line 157, in from_hub
    space_info = api.space_info(name)
  File "E:\sd\venv\lib\site-packages\huggingface_hub\utils\_validators.py", line 120, in _inner_fn
    return fn(*args, **kwargs)
  File "E:\sd\venv\lib\site-packages\huggingface_hub\hf_api.py", line 1749, in space_info
    r = requests.get(path, headers=headers, timeout=timeout, params=params)
  File "E:\sd\venv\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "E:\sd\venv\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "E:\sd\venv\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "E:\sd\venv\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "E:\sd\venv\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/spaces/gradio/soft (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000019DEF4B3940>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

System Info

3.23.0, Windows, Chrome

Severity

annoying

@space-nuko space-nuko added the bug Something isn't working label Mar 22, 2023
@abidlabs
Copy link
Member

Gradio as a whole doesn't really work without internet connection (see #1450) so let's perhaps add this onto that issue?

@freddyaboulton
Copy link
Collaborator

Yea we check what the latest version is and if the theme repo still exists. In the meantime, you can .dump the theme to a json file and call .load on it from there if you have to run without internet!

@abidlabs
Copy link
Member

Will close as @freddyaboulton has suggested a workaround, and there is currently not a general expectation that Gradio should run fully without Internet (that will be handled in #1450)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants