vladmandic / automatic

SD.Next: Advanced Implementation of Stable Diffusion and other Diffusion-based generative image models
https://github.com/vladmandic/automatic
GNU Affero General Public License v3.0
5.61k stars 413 forks source link

[Issue]: Recent gradio update won't run offline? #685

Closed scottmudge closed 1 year ago

scottmudge commented 1 year ago

Edit: ignore, found a work around.

vladmandic commented 1 year ago

console progress bar is printed by sampler, nothing to do with gradio. and works for me. which sampler are you using? does it work with default unipc?

and also no issues with even when network is offline - i just unplugged my pc and tried (you can clearly see network check that checks version fails and thats it, everything else works):

19:42:20-787298 INFO     Python 3.10.6 on Linux
19:42:20-807490 INFO     Version: d22103e9 Mon May 1 19:12:10 2023 -0400
19:42:30-845076 ERROR    Failed to check version: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /repos/vladmandic/automatic/branches/master (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f97d9141a20>: Failed to establish a new connection: [Errno -3] Temporary failure
                         in name resolution')) None
...
19:42:31-702859 INFO     Server arguments: []
Running on local URL:  https://127.0.0.1:7860
...
Model loaded in 1.8s (load=0.3s create=0.2s apply=0.5s vae=0.2s move=0.5s)
Startup time: 19.1s (torch=1.8s gradio=0.8s libraries=0.2s models=2.2s codeformer=0.1s scripts=1.7s vae=0.1s ui=8.4s start=2.1s checkpoint=1.8s)
Progress 2.54it/s ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00 0:00:03
scottmudge commented 1 year ago

Yeah it was unipc that wasn't outputting anything. But samples were still being generated, so not sure what's going on.

And it starts up fine without a network connection, but when I tried to open the gradio ui in a browser on the offline machine, it wouldn't load. It would just have the loading spinner going indefinitely, and the chrome developer console had scripts complaining about being offline.

vladmandic commented 1 year ago

yup, reproduced. i didn't see it before since if you had page open before, closing and restart browser still works since browser will return cached results.

don't see anything obvious since only js script that requires network connection was added to gradio repo 2 years ago, not recent. would need to dive deep, but at the end, still wouldn't be able to fix it as it would require code change in gradio itself. and other two failed requests are just fonts loaded from css, so that cannot be it.

can you report there? https://github.com/gradio-app/gradio

scottmudge commented 1 year ago

Will do. The console output issue was due to a duplicate instance of the console being open, I forgot the close the other one, which was correctly showing the progress bar. So the main issue is just with Gradio.

Thanks for reproducing the issue.

scottmudge commented 1 year ago

@vladmandic

Apparently it's been a bug on Gradio for a long time. As you note, the issue is loading fonts from Google.

However, there is a fix you can implement (I tested it). In modules/shared.py, you can enforce using standard system fonts by changing, for example (assuming the active theme is gradio/default):


def reload_gradio_theme(theme_name=None):
    global gradio_theme # pylint: disable=global-statement
    if not theme_name:
        theme_name = opts.gradio_theme
    if theme_name == "black-orange":
        gradio_theme = gr.themes.Default()
    elif theme_name.startswith("gradio/"):
        if theme_name == "gradio/default":
            gradio_theme = gr.themes.Default()
        if theme_name == "gradio/base":
            gradio_theme = gr.themes.Base()
        if theme_name == "gradio/glass":
            gradio_theme = gr.themes.Glass()
        if theme_name == "gradio/monochrome":
            gradio_theme = gr.themes.Monochrome()
        if theme_name == "gradio/soft":
            gradio_theme = gr.themes.Soft()
...

to

def reload_gradio_theme(theme_name=None):
    global gradio_theme # pylint: disable=global-statement
    if not theme_name:
        theme_name = opts.gradio_theme
    if theme_name == "black-orange":
        gradio_theme = gr.themes.Default()
    elif theme_name.startswith("gradio/"):
        if theme_name == "gradio/default":
            gradio_theme = gr.themes.Default(
            font=['Helvetica', 'ui-sans-serif', 'system-ui', 'sans-serif'],
            font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],)
        if theme_name == "gradio/base":
            gradio_theme = gr.themes.Base()
        if theme_name == "gradio/glass":
            gradio_theme = gr.themes.Glass()
        if theme_name == "gradio/monochrome":
            gradio_theme = gr.themes.Monochrome(
...

This is what some people have appeared to do. Perhaps add some logic to detect if google's font API address is reachable, and if not, enforce these standard fonts.

I might be able to add a PR for this, but it seems like a simple change.

vladmandic commented 1 year ago

loading fonts should not hang ui like that - if they are, its really bad design from gradio. did you confirm this?

scottmudge commented 1 year ago

Yep:

https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/10003

https://github.com/gradio-app/gradio/issues/1450

It is indeed a terrible design, and they've known about it since last year. I guess they never got around to fixing it.

I've implemented a simple fix which checks if the google fonts API URL is reachable, will create a PR. Enforcing the default fonts allows the UI to load without external internet access.

scottmudge commented 1 year ago

Alright, created a PR for the fix: #712

Not sure if it's the best implementation, but it works for me. Maybe you have a better idea about going about it.