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

Simple Gradio sample crashes after loading #5459

Closed
testlabauto opened this issue Nov 22, 2024 · 6 comments
Closed

Simple Gradio sample crashes after loading #5459

testlabauto opened this issue Nov 22, 2024 · 6 comments
Assignees
Labels

Comments

@testlabauto
Copy link
Contributor

System details:

Positron and OS details:

Positron Version: 2024.12.0 (Universal) build 41
OSX

Interpreter details:

Python 3.10.12

Describe the issue:

This simple Gradio sample no longer stays running:

import gradio as gr

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

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

It dies with:

~/.pyenv/versions/3.10.12/bin/python /Users/christophermead/posit/qa-example-content/workspaces/python_apps/gradio_example/gradio_example.py
(base) ➜  qa-example-content ~/.pyenv/versions/3.10.12/bin/python /Users/christophermead/posit/qa-example-content/workspaces/python_apps/gradio_example/gradio_exam
ple.py
* Running on local URL:  http://127.0.0.1:7860
Traceback (most recent call last):
  File "/Users/christophermead/posit/qa-example-content/workspaces/python_apps/gradio_example/gradio_example.py", line 5, in <module>
    demo.launch()
  File "/Users/christophermead/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/blocks.py", line 2582, in launch
    raise ValueError(
ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

Steps to reproduce the issue:

  1. Run simple Gradio sample above
  2. Note that it will run but will quickly die

Expected or desired behavior:

Gradio continues to run.

Were there any error messages in the UI, Output panel, or Developer Tools console?

Did not see any

@juliasilge juliasilge added the bug Something isn't working label Nov 25, 2024
@juliasilge juliasilge added this to the 2025.01.0 Pre-Release milestone Nov 25, 2024
@sharon-wang sharon-wang self-assigned this Nov 25, 2024
@sharon-wang
Copy link
Member

sharon-wang commented Dec 3, 2024

I opened an issue gradio-app/gradio#10093 and a PR gradio-app/gradio#10094 in Gradio to allow 307 HTTP codes which should resolve the error. The change was accepted 🎉 and it's currently targeted for gradio@5.8.0 (see gradio-app/gradio#10082).

Copying over the issue description here for reference:

Gradio Issue 10093

Describe the bug

HTTP Code 302 is listed in the acceptable HTTP codes for url_ok; however, alternative temporary redirect codes 303 and 307 are not included in the list.

https://github.com/gradio-app/gradio/blob/01b919f04b69732fd8adb52f6d156e5683589221/gradio/networking.py#L51-L62

MDN Docs for the mentioned HTTP codes:

Although 302 is commonly used, 303 and 307 may be used to be more specific about how the temporary redirect should be handled.

Currently, url_ok() does not consider response codes 303 and 307 to be OK. Could they be added to the permitted response codes?

Reproduction

Example App for Repro

This app should be run in Positron with the Run App feature, which creates a proxy for the app and displays the proxied url in the viewer.

import gradio as gr
def image_classifier(inp):
    return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
demo.launch()

The app runs successfully, but crashes immediately after starting up with:

Traceback (most recent call last):
  File "/Users/sashimi/Documents/projects/my-python-project_gradio/gradio_example.py", line 5, in <module>
    demo.launch()
  File "/Users/sashimi/Documents/projects/my-python-project_gradio/.venv/lib/python3.12/site-packages/gradio/blocks.py", line 2590, in launch
    raise ValueError(
ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

Adding 307 to the list of acceptable status codes allows the app to run successfully, without the following error occurring:

Traceback (most recent call last):
  File "/Users/sashimi/Documents/projects/my-python-project_gradio/gradio_example.py", line 5, in <module>
    demo.launch()
  File "/Users/sashimi/Documents/projects/my-python-project_gradio/.venv/lib/python3.12/site-packages/gradio/blocks.py", line 2590, in launch
    raise ValueError(
ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

Logs

Modified networking.py in my .venv to see the response code -- 307

def url_ok(url: str) -> bool:
    try:
        for _ in range(5):
            with warnings.catch_warnings():
                warnings.filterwarnings("ignore")
                r = httpx.head(url, timeout=3, verify=False)
            if r.status_code in (200, 401, 302):  # 401 or 302 if auth is set
                return True
            # --- start sharon debug ---
            print(r)
            # --- end sharon debug ---
            time.sleep(0.500)
    except (ConnectionError, httpx.ConnectError, httpx.TimeoutException):
        return False
    return False

Output

~/Documents/projects/my-python-project_gra
dio/.venv/bin/python /Users/sashimi/Documents/projects/my-python-project_gradio/gradio_example.py
* Running on local URL:  http://127.0.0.1:7860
<Response [307 Temporary Redirect]>
<Response [307 Temporary Redirect]>
<Response [307 Temporary Redirect]>
<Response [307 Temporary Redirect]>
<Response [307 Temporary Redirect]>
Traceback (most recent call last):
  File "/Users/sashimi/Documents/projects/my-python-project_gradio/gradio_example.py", line 5, in <module>
    demo.launch()
  File "/Users/sashimi/Documents/projects/my-python-project_gradio/.venv/lib/python3.12/site-packages/gradio/blocks.py", line 2590, in launch
    raise ValueError(
ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 5.7.1
gradio_client version: 1.5.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.6.2.post1
audioop-lts is not installed.
fastapi: 0.115.5
ffmpy: 0.4.0
gradio-client==1.5.0 is not installed.
httpx: 0.28.0
huggingface-hub: 0.26.3
jinja2: 3.1.4
markupsafe: 2.1.5
numpy: 2.1.3
orjson: 3.10.12
packaging: 24.2
pandas: 2.2.3
pillow: 11.0.0
pydantic: 2.10.2
pydub: 0.25.1
python-multipart==0.0.12 is not installed.
pyyaml: 6.0.2
ruff: 0.8.1
safehttpx: 0.1.1
semantic-version: 2.10.0
starlette: 0.41.3
tomlkit==0.12.0 is not installed.
typer: 0.14.0
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.32.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.10.0
httpx: 0.28.0
huggingface-hub: 0.26.3
packaging: 24.2
typing-extensions: 4.12.2
websockets: 12.0

After making the fix locally, I'm seeing a separate issue in Positron Web where some .css files are not being loaded from the right path:

Image

css.ts:29 Unable to preload CSS for http://localhost:8080/assets/index-Bmd1Nf3q.css
(anonymous) @ css.ts:29
error
(anonymous) @ css.ts:28
Wt @ css.ts:26
connectedCallback @ main.ts:95
await in connectedCallback
ju @ main.ts:207
(anonymous) @ main.ts:210Understand this errorAI
css.ts:29 Unable to preload CSS for http://127.0.0.1:7860/proxy/53806/theme.css?v=76ee63afdb6c2791ddf9b92428cb796885031b4a4f1259df434def0a7c3f9d63

I feel like this might be related to gradio-app/gradio#9101 / gradio-app/gradio#9822.

@sharon-wang
Copy link
Member

Yeah, looks like gradio-app/gradio#9822 is causing the relative CSS paths to be used instead of an absolute path, which we rely on. I reverted the change in gradio-app/gradio#9822 by modifying the minified JS in the gradio libary in my venv and the CSS loads from the correct absolute path.

@sharon-wang
Copy link
Member

Opened PR: #5590, but keeping it as a draft, as we'll need to wait on the release of gradio@5.8.0.

@juliasilge
Copy link
Contributor

Just so I am clear, does this mean that Positron will work with newer versions of gradio but will not work with older versions of gradio?

@sharon-wang
Copy link
Member

Yes sort of -- previously it was somewhat undefined which versions of Gradio would work with Run App.

We were experiencing a version of gradio-app/gradio#9529, so I tested Run App with this combination of versions gradio==3.3.1 fastapi==0.85.2 httpx==0.24.1 as noted in the issue. In conjunction with the root_path workaround, Gradio apps with these dependency versions were working, and it seemed that the QA automation tests with the latest versions of Gradio at the time of running may have also been working (? @testlabauto to confirm, although we also are unsure if the test was previously working).

Now, we've seen other versions of Gradio failing, e.g. Chris saw the failure in the issue description with Gradio 5.6.0 recently, so it's not clear which versions of Gradio were working.

sharon-wang added a commit that referenced this issue Dec 9, 2024
### Summary

- Addresses #5459
- Companion Gradio Issue
gradio-app/gradio#10093
- Companion Gradio PR gradio-app/gradio#10094
- Re-enables `Python - Verify Basic Gradio App [C903307]`

#### localhost ValueError
gradio-app/gradio#10094 addresses the following
error described in #5459

```
Traceback (most recent call last):
  File "/Users/christophermead/posit/qa-example-content/workspaces/python_apps/gradio_example/gradio_example.py", line 5, in <module>
    demo.launch()
  File "/Users/christophermead/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/blocks.py", line 2582, in launch
    raise ValueError(
ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.
```

We'll need to wait for [Gradio
5.8.0](gradio-app/gradio#10082) before we can
confirm that this error is fixed -- **edit: 5.8.0 has been released**!
This error occurs before the [CSS styling
issue](#5459 (comment))
can be seen. A manual patch to gradio is currently needed in order to
reach this second issue.

#### Failure to load styles
Our use of `GRADIO_ROOT_PATH` is no longer needed and also no longer
works since the underlying issue was resolved in [Gradio
5.7.0](gradio-app/gradio#9970), via
gradio-app/gradio#9822. The related code is
being removed in this PR.

### QA Notes

The [gradio example
app](https://github.com/posit-dev/qa-example-content/tree/main/workspaces/python_apps/gradio_example)
should now work in Web and Desktop.
@testlabauto
Copy link
Contributor Author

Verified Fixed

Positron Version(s) : 2025.01.0-50
OS Version          : OSX

Test scenario(s)

Gradio app no longer crashing locally or in CI. Tested with newest and second newest gradio versions as of today.

Link(s) to TestRail test cases run or created:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants