aws / studio-lab-examples

Example notebooks for working with SageMaker Studio Lab. Sign up for an account at the link below!
https://studiolab.sagemaker.aws
Apache License 2.0
637 stars 185 forks source link

Gradio Output #229

Closed rscherl closed 11 months ago

rscherl commented 1 year ago

I'm testing a simple Gradio example in a Sagemaker studio lab notebook. The Gradio documentation states that the output should appear within the notebook. It does not appear for me. [I tried it in a Google Colab notebook and it does appear.] I imagine there should be a simple setting to fix this, but I haven't been able to find it.

MicheleMonclova commented 1 year ago

https://github.com/gradio-app/gradio/issues/3038 check this solution ^^

icoxfog417 commented 1 year ago

Dear @rscherl

Could you please check the following example? https://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/gradio_example.ipynb

Currently, Studio Lab can not display Gradio in the notebook. Alternatively, you can open display it in another tab.

rscherl commented 1 year ago

Thanks. I tried the solution. But I get the error

TypeError Traceback (most recent call last) /tmp/ipykernel_88/1064744212.py in <cell line: 1>() ----> 1 demo.launch(server_port=8080,root_path=root_path, inline = False)

TypeError: launch() got an unexpected keyword argument 'root_path'

But I see root_path in the Gradio documentation as an input argument to launch. So, I'll try installing Gradio again.

rscherl commented 1 year ago

I reloaded grado and now the code runs without the error given above. [This time I used the Sagemaker distribution of Python and used %pip install python instead of !pip install python]. But I still can't see Gradio and get the message in the tab that We can't connct to the server at(xxxx.us-east-2.sagemaker.aws) So I'm still experimenting

rscherl commented 1 year ago

I got rid of the parens and added studio. So, now it connects to the server at xxxx.studio.us-east-2.sagemaker.aws. Still trying to get gradio to take input

rscherl commented 1 year ago

I get the tab, but the textboxes are not fully functional. This is what I see. image

icoxfog417 commented 1 year ago

Dear @rscherl Thank you for testing example. I think you have installed old version Gradio that does not support root_path (I have also faced your situation, style is not applied to Gradio application).

If you install Gradio by conda, please uninstall it and install latest version by pip. Because Gradio on conda-forge is old and does not support root_path.

rscherl commented 1 year ago

I did install using %pip install gradio. There is a typo in what I have above. But I will try it again and see if things improve.

rscherl commented 1 year ago

I mean uninstall first.

icoxfog417 commented 1 year ago

%pip install --upgrade gradio will work fine.

rscherl commented 1 year ago

Alas, not luck. The same output appeared. I tried using Chrome instead, but again the same result.

icoxfog417 commented 1 year ago

I confirmed gradio works well under the following setting in Chrome.

1. Install Gradio that supports root_path argument

Install gradio==3.40.1. You can use environment.yml in the examples.

2. Launch Gradio by setting server_port and root_path

Execute following codes from Jupyter Notebook (it is same as https://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/gradio_example.ipynb).

import gradio as gr

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

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
port = 8080
gr.close_all()
root_path = f"/studiolab/default/jupyter/proxy/{port}"
demo.launch(server_port=8080, root_path=root_path, inline=False)

3. Access gradio by the other tab in browser

Access to the gradio page.

https://(your_studio_lab_domain)/studiolab/default/jupyter/proxy/8080/

You can confirm (your_studio_lab_domain) in the Studio Lab URL.

image

Here is the actural screen shot (language setting is Japanese).

image

rscherl commented 1 year ago

Thanks again for all your effort. Mine still does not work. But I will get a clean copy of Sagemaker Studio Lab and try the example again

Maverick1983 commented 11 months ago

I use this example, but not working. When I will go to /proxy page I see this error on browser console

image

icoxfog417 commented 11 months ago

@Maverick1983 Could you please let us share your procedure? 404 not found will mean incorrect URL, you need 8080 after proxy.

https://(your_studio_lab_domain)/studiolab/default/jupyter/proxy/8080/
Maverick1983 commented 11 months ago

Of course I use the port, but I have 404 Not Found.

Update with other test: on my script missing _rootpath on launch Gradio. So now it's working!

rscherl commented 11 months ago

Thanks Luca and Takahiro. Now I got it to work. 😀 This is great. I did have to delete my Sagemaker Studio account and request a new one. They immediately gave it to me. I used the Sagemaker distribution of Python instead of the default. I used %pip install gradio==3.40.1 First I tried %conda, but it could not find gradio?

But then I followed your example and it worked. Finally. Of course I used Chrome. [It is still possible that there are some interactions between gradio and other packages that cause problems as I used a clean image.]

Rich From: Luca @.> Reply-To: aws/studio-lab-examples @.> Date: Friday, October 20, 2023 at 4:16 PM To: aws/studio-lab-examples @.> Cc: Richard Scherl @.>, Mention @.***> Subject: [External] Re: [aws/studio-lab-examples] Gradio Output (Issue #229)

I confirmed gradio works well under the following setting in Chrome.

  1. Install Gradio that supports root_path argument

Install gradio==3.40.1. You can use environment.yml in the examples.https://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/environment.yml

  1. Launch Gradio by setting server_port and root_path

Execute following codes from Jupyter Notebook (it is same as https://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/gradio_example.ipynbhttps://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/gradio_example.ipynb).

import gradio as gr

def greet(name):

return "Hello " + name + "!"

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

port = 8080

gr.close_all()

root_path = f"/studiolab/default/jupyter/proxy/{port}"

demo.launch(server_port=8080, root_path=root_path, inline=False)

  1. Access gradio by the other tab in browser

Access to the gradio page.

https://(your_studio_lab_domain)/studiolab/default/jupyter/proxy/8080/

You can confirm (your_studio_lab_domain) in the Studio Lab URL.

[image]https://user-images.githubusercontent.com/544269/261882894-cc407dfb-ea9b-40fb-ac48-9272331b0850.png

Here is the actural screen shot (language setting is Japanese).

[image]https://user-images.githubusercontent.com/544269/261883050-4fc69486-1d25-46dc-a5f4-b1fdc32b414c.png

I use this example, but not working. When I will go to /proxy page I see this error on browser console

[image]https://user-images.githubusercontent.com/20558694/277043303-1625b8f8-4f10-4161-959b-176515abf551.png

— Reply to this email directly, view it on GitHubhttps://github.com/aws/studio-lab-examples/issues/229#issuecomment-1773339535, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADFQCFFGB67TEGPFNG7DI23YALLTFAVCNFSM6AAAAAA3AH33EGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTGMZTSNJTGU. You are receiving this because you were mentioned.Message ID: @.***>

rscherl commented 11 months ago

I did get the following message at the end of the install of gradio. I hope this is a minor thing and will not lead to any problems when using tensorflow.

Rich

---- output ---

Building wheels for collected packages: ffmpy Building wheel for ffmpy (setup.py) ... done Created wheel for ffmpy: filename=ffmpy-0.3.1-py3-none-any.whl size=5579 sha256=51ce4f479fbeb4da4e46d96684c7287067fc83299b9447e28558171473c34da4 Stored in directory: /home/studio-lab-user/.cache/pip/wheels/75/a3/1a/2f3f90b9a4eb0408109ae1b5bae01efbdf8ab4ef98797433e4 Successfully built ffmpy Installing collected packages: pydub, ffmpy, websockets, uc-micro-py, typing-extensions, semantic-version, python-multipart, orjson, mdurl, h11, fsspec, uvicorn, starlette, pydantic-core, markdown-it-py, linkify-it-py, huggingface-hub, httpcore, annotated-types, pydantic, mdit-py-plugins, httpx, gradio-client, fastapi, altair, gradio Attempting uninstall: typing-extensions Found existing installation: typing_extensions 4.5.0 Uninstalling typing_extensions-4.5.0: Successfully uninstalled typing_extensions-4.5.0 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. tensorflow 2.12.1 requires typing-extensions<4.6.0,>=3.6.6, but you have typing-extensions 4.8.0 which is incompatible. Successfully installed altair-5.1.2 annotated-types-0.6.0 fastapi-0.104.0 ffmpy-0.3.1 fsspec-2023.9.2 gradio-3.40.1 gradio-client-0.6.1 h11-0.14.0 httpcore-0.18.0 httpx-0.25.0 huggingface-hub-0.18.0 linkify-it-py-2.0.2 markdown-it-py-2.2.0 mdit-py-plugins-0.3.3 mdurl-0.1.2 orjson-3.9.9 pydantic-2.4.2 pydantic-core-2.10.1 pydub-0.25.1 python-multipart-0.0.6 semantic-version-2.10.0 starlette-0.27.0 typing-extensions-4.8.0 uc-micro-py-1.0.2 uvicorn-0.23.2 websockets-11.0.3 Note: you may need to restart the kernel to use updated packages.

From: Luca @.> Reply-To: aws/studio-lab-examples @.> Date: Friday, October 20, 2023 at 4:16 PM To: aws/studio-lab-examples @.> Cc: Richard Scherl @.>, Mention @.***> Subject: [External] Re: [aws/studio-lab-examples] Gradio Output (Issue #229)

I confirmed gradio works well under the following setting in Chrome.

  1. Install Gradio that supports root_path argument

Install gradio==3.40.1. You can use environment.yml in the examples.https://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/environment.yml

  1. Launch Gradio by setting server_port and root_path

Execute following codes from Jupyter Notebook (it is same as https://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/gradio_example.ipynbhttps://github.com/aws/studio-lab-examples/blob/main/custom-environments/Gradio/gradio_example.ipynb).

import gradio as gr

def greet(name):

return "Hello " + name + "!"

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

port = 8080

gr.close_all()

root_path = f"/studiolab/default/jupyter/proxy/{port}"

demo.launch(server_port=8080, root_path=root_path, inline=False)

  1. Access gradio by the other tab in browser

Access to the gradio page.

https://(your_studio_lab_domain)/studiolab/default/jupyter/proxy/8080/

You can confirm (your_studio_lab_domain) in the Studio Lab URL.

[image]https://user-images.githubusercontent.com/544269/261882894-cc407dfb-ea9b-40fb-ac48-9272331b0850.png

Here is the actural screen shot (language setting is Japanese).

[image]https://user-images.githubusercontent.com/544269/261883050-4fc69486-1d25-46dc-a5f4-b1fdc32b414c.png

I use this example, but not working. When I will go to /proxy page I see this error on browser console

[image]https://user-images.githubusercontent.com/20558694/277043303-1625b8f8-4f10-4161-959b-176515abf551.png

— Reply to this email directly, view it on GitHubhttps://github.com/aws/studio-lab-examples/issues/229#issuecomment-1773339535, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADFQCFFGB67TEGPFNG7DI23YALLTFAVCNFSM6AAAAAA3AH33EGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTGMZTSNJTGU. You are receiving this because you were mentioned.Message ID: @.***>

icoxfog417 commented 11 months ago

Dear @Maverick1983 I am glad to hear you can run the Gradio. And @rscherl , thank you for sharing your succeeded procedure. The Gradio 3.40.1 is not listed at conda however over 3.24.1 versions are listed recently. So conda install gradio will work now.

Anyway, we are happy to hear solving the issues.