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
30.73k stars 2.29k forks source link

"UserWarning: LoginButton created outside of a Blocks context." is always shown #8349

Open hysts opened 1 month ago

hysts commented 1 month ago

Describe the bug

The following warning is always shown when usinggr.LoginButton.

UserWarning: LoginButton created outside of a Blocks context. May not work unless you call its `activate()` method manually.

(internal slack)

Have you searched existing issues? 🔎

Reproduction

You can see this warning even in the log of this sample Space under the gradio org on HF Hub.

import gradio as gr 

with gr.Blocks() as demo:
    gr.LoginButton()

demo.launch()

(The sample Space above is using gradio==4.31.2, but the warning appears when using gradio==4.31.5 too.)

Screenshot

Logs

No response

System Info

gradio==4.31.5

Severity

I can work around it

abidlabs commented 1 month ago

cc @Wauplin do you have a chance to look at this?

Wauplin commented 1 month ago

Weird... I'll have a look at it yes 👍

Wauplin commented 1 month ago

@abidlabs I investigated this issue and don't have a clue what's going on here. I duplicated the logincomponent Space (see here) which recreates the warning described in this issue but otherwise I've not been able to reproduce it locally, which makes it really hard to debug.

The warning itself is triggered in LoginButton.__init__(...) because for some reason, the blocks context is not detected. This check has been first updated in this PR and more recently in this one. I tried several versions, including the most recent one, and the blocks context is never detected. From what I understand from your message here, it is important that we do not activate the button if we're not in a blocks context.

Any idea to move forward?

abidlabs commented 1 month ago

Really appreciate @Wauplin for looking into this! I'll dive into this when I get some time to see what's going on. This issue itself doesn't seem like a blocker but there may be something deeper going on