gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.96k stars 2.58k forks source link

Gradio Interface does not run locally without internet connection #1450

Open liuyixi520 opened 2 years ago

liuyixi520 commented 2 years ago

Describe the bug

I am in a offline environment, that can not connect the internet. I see nothing in my browser when following 'Quick Start' section of the readme.

  1. use conda Create environment with python 3.7: conda create -n gradio3 python=3.7
  2. install gradio: pip install gradio Run the example script In the browser (Chrome and Edge tested) I see nothing. There errors in the console logs that say: https://fonts.googleapis.com/css?family=Source Sans Pro net::ERR_NAME_NOT_RESOLVED

can anyone give me a hlep to slove this problem, thanks very much. I am in a hurry

Is there an existing issue for this?

Reproduction

import gradio as gr

def greet(name): return "Hello " + name + "!!"

gr.Interface(fn=greet, inputs="text", outputs="text").launch(debug=True)

Screenshot

2125392789

Logs

Running on local URL:  http://127.0.0.1:7860/

To create a public link, set `share=True` in `launch()`.

System Info

Gradio: 3.0.10
Python: 3.7.0
OS: Windows 7
Browsers: Chrome 70.0.3538.110

Severity

blocking all usage of gradio

abidlabs commented 2 years ago

Hmmm it looks like we are loading certain assets from the web for Gradio 3.0. We should fix that @aliabid94

In the meantime, perhaps you can try using an older version of gradio (say gradio==2.9.4 -- I don't think they require being online)

liuyixi520 commented 2 years ago

Hmmm it looks like we are loading certain assets from the web for Gradio 3.0. We should fix that @aliabid94

In the meantime, perhaps you can try using an older version of gradio (say gradio==2.9.4 -- I don't think they require being online)

thank you very much, my problem has been solved by your advice. and when you fix this bug in your new version, can you give me a message, so i can use gradio3 in my work

aliabid94 commented 2 years ago

That's strange. Will take a look.

abidlabs commented 2 years ago

Related to fonts: #1224

pngwn commented 2 years ago

We currently load fonts from the google fonts CDN, the iframe resizer from CDNJS and bokeh from the Bokeh CDN. All of these things will break when offline. We need to copy the source and self host, preferably along with other static assets on the CDN rather than on the server in order to fix these issues (we should be self hosting fonts for performance reasons but font are slightly more complex as the google CDN is quite clever, we need to ensure we only load the smallest subset we can get away with).

tpanza commented 2 years ago

What help is needed with this?

Besides fonts, there are several places in the code where contact via https is attempted to gradio.app.

$ grep -RnF 'gradio.app'
documentation.py:18:    documentation at www.gradio.app/docs.
networking.py:29:GRADIO_API_SERVER = "https://api.gradio.app/v1/tunnel-request"
strings.py:5:MESSAGING_API_ENDPOINT = "https://api.gradio.app/gradio-messaging/en"
utils.py:46:analytics_url = "https://api.gradio.app/"
utils.py:47:PKG_VERSION_URL = "https://api.gradio.app/pkg-version"
templates/cdn/index.html:11:            <meta property="og:url" content="https://gradio.app/" />
templates/cdn/assets/index.8da6a09f.js:6197:                    attr(a, "href", "https://gradio.app");
templates/frontend/index.html:11:               <meta property="og:url" content="https://gradio.app/" />
templates/frontend/share.html:11:               <meta property="og:url" content="https://gradio.app/" />
templates/frontend/assets/index.4ddf74a5.js:6197:                       attr(a, "href", "https://gradio.app");

This also breaks when offline, with the exception of MESSAGING_API_ENDPOINT, which has a fallback provision to use hardcoded defaults.

bolshoytoster commented 1 year ago

Another thing to note, analytics are on by default, which don't work with no network.

If anyone else is having issues with this, you can add analytics_enabled=False when initialising your gr.Interface/gr.TabbedInterface.

ThatCoffeeGuy commented 1 year ago

Another thing to note, analytics are on by default, which don't work with no network.

If anyone else is having issues with this, you can add analytics_enabled=False when initialising your gr.Interface/gr.TabbedInterface.

Do we know what sort of data is being mined by analytics?

abidlabs commented 1 year ago

See here:

https://github.com/gradio-app/gradio/blob/7c1db51d95293e7a9b645dbbdcaf603d989cb89a/gradio/blocks.py#L594

and here:

https://github.com/gradio-app/gradio/blob/7c1db51d95293e7a9b645dbbdcaf603d989cb89a/gradio/blocks.py#L1686

Juenjie commented 1 year ago

@abidlabs I want to deploy a chatbot on my local machine without internet connection for many users. However, when I use gradio==2.9.4, it does not contain the class gr.chatbot. When I use 3.24.1, it requires internet connection. Do you have any suggestion on this? I am not familiar with UI.

abidlabs commented 1 year ago

Hi @Juenjie unfortunately I do not think it is possible to use gr.Chatbot right now without Internet connection. The gr.Chatbot component was introduced in 3.x and, as you mentioned, 3.x currently does require Internet connection, mostly to fetch frontend assets.

Slins-23 commented 1 year ago

@abidlabs For version 3.24.1, which is the one used for https://github.com/oobabooga/text-generation-webui/, the reasons are as mentioned: the frontend resources. I came up with a quick hack which makes it work offline, so I don't know the ramifications of the changes, as my goal was to almost blindly remove remote references. I don't know whether this has been fixed in newer versions, or if it will be useful or not, but I attached the files with the changes made, it might be helpful to pinpoint the exact lines of code that should be reworked. Related issue: https://github.com/oobabooga/text-generation-webui/issues/867

gradio.zip

OgalFinklestein commented 1 year ago

Happy Bugiversary. Are the plans to resolve this year-old issue?

aliabid94 commented 1 year ago

https://github.com/gradio-app/gradio/pull/4398 should fix offline for most use cases

pourmand1376 commented 1 year ago

My Gradio app want to load some javascript file from Amazon which it fails on my server (my server and my client don't have access to the internet). What should I do?

Url of the file: https://gradio.s3-us-west-2.amazonaws.com/3.39.0/assets/index-fda37c89.js.

Is there any way to make this file available offline?

pourmand1376 commented 1 year ago

Update: I've found mutliple places where amazonaws is used (+).

https://github.com/gradio-app/gradio/blob/ff6f5250a7c5cf2a2fe5c9585689dcd70c5c18ad/js/_website/src/routes/%2Blayout.svelte#L49-L53

markdjwilliams commented 1 year ago

I'm encountering this exact issue in gradio 3.44.4

Is there an earlier 3.x version which supports offline usage?

pngwn commented 1 year ago

Do you have an example app showing this behaviour? The CDN should only be used when embedding gradio apps, for local apps it should be pulling the files from your local file system.

pngwn commented 1 year ago

Update: I've found mutliple places where amazonaws is used

This is just the Gradio website and doesn't affect the Gradio library.

xinqingguo commented 8 months ago

analytics_enabled=False

This works! My Gradio version is 4.19.2

djaym7 commented 7 months ago

@xinqingguo did you set the env variable os.environ["GRADIO_ANALYTICS_ENABLED"] = "False" or some parameter ?

justinzyw commented 5 months ago

We currently load fonts from the google fonts CDN, the iframe resizer from CDNJS and bokeh from the Bokeh CDN. All of these things will break when offline. We need to copy the source and self host, preferably along with other static assets on the CDN rather than on the server in order to fix these issues (we should be self hosting fonts for performance reasons but font are slightly more complex as the google CDN is quite clever, we need to ensure we only load the smallest subset we can get away with).

Same here. the fonts loading from the google fonts and the iframe resizer loading from cloudflare are the blockers.

abidlabs commented 4 months ago

This could be good for 5.0 @aliabid94