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

root_path of launch does not work as expected #4352

Closed
1 task done
RussellLuo opened this issue May 28, 2023 · 5 comments
Closed
1 task done

root_path of launch does not work as expected #4352

RussellLuo opened this issue May 28, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@RussellLuo
Copy link
Contributor

Describe the bug

Per the docs of launch:

The root path (or "mount point") of the application, if it's not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application. For example, if the application is served at "https://example.com/myapp", the root_path should be set to "/myapp".

Related comments from a previous issue: #4291 (comment).

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

Given the following code:

import gradio as gr

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

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

if __name__ == "__main__":
    demo.launch(root_path="/myapp")

Run the demo:

python3 demo.py 
Running on local URL:  http://127.0.0.1:7861

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

Then access the demo from http://127.0.0.1:7861/myapp.

Screenshot

image

Logs

No extra logs.

System Info

Gradio 3.30.0
python 3.9.12
macOS

Severity

annoying

@RussellLuo RussellLuo added the bug Something isn't working label May 28, 2023
@abidlabs
Copy link
Member

Hi @RussellLuo there's some confusion here. The root_path parameter is set if your Gradio application is already running on https://example.com/myapp due to some reverse proxy (like nginx). Then, you set root_path to myapp so that everything works properly. We'll document this better when we write this Guide: #3260

It looks like what you want is to mount your Gradio application, within another FastAPI, see: https://gradio.app/sharing-your-app/#mounting-within-another-fastapi-app

@RussellLuo
Copy link
Contributor Author

RussellLuo commented May 30, 2023

@abidlabs Thanks for your reply!

I have managed to serve my Gradio application by using the strategy you mentioned above. However, it seemed that everything worked out well even if no root_path was specified. So I thought root_path was a thing equivalent to mounting Gradio application within another FastAPI.

Furthermore, launch has lots of parameters, is it possible to adjust the behavior of Gradio application like launch while mounting it within another FastAPI?

@ahmedelgammal
Copy link

ahmedelgammal commented Jul 12, 2023

I have the same error. I am trying to mount a gadio app as described, something like https://example.com/myapp using nginx reverse proxy. I get that error when I use root_path="/myapp" in the block.launch call. the response from the server is {"detail":"Not Found"}. I have no problem if I mount the app to the root. @abidlabs does root_path conflict with any other argument or requires other arguments to be set in a certain way ? Even running on the local server port does not work once I add root_path in the launch call.

@abidlabs
Copy link
Member

abidlabs commented Jul 12, 2023

Hi @ahmedelgammal I don't see enough details for us to be able to debug, but (a) are you using the latest version of gradio and (b) have you taken a look at this guide here: https://www.gradio.app/guides/running-gradio-on-your-web-server-with-nginx

@ahmedelgammal
Copy link

@abidlabs yes, I implemented that exactly, except that I am using blocks. This works as expected without the root_path. Once I add the root_path, the app doesn't work, even on the local server.

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