I’m trying to implement basic username/password authentication in a Gradio app. It works locally but fails in HF Space.
# Basic auth configuration
app.launch(
auth=(username, password), # username/password from env vars
show_api=False
)
Environment variables are properly set in Space as secrets (APP_USER, APP_PSWD).
This is the error I am getting:
Error: Login credentials are required to access this space.
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.
What’s the correct way to implement basic auth in a Gradio app on HF Spaces?
From the error message, it seems that it should work just by passing share=True in .launch(), but in the first place, a normal Space works with share=False or the default without any options.
I don’t know why it needs to be set…
Mmmm, thank you for the response, I changed it to share = True and I get this:
/usr/local/lib/python3.10/site-packages/gradio/blocks.py:2596: UserWarning: Setting share=True is not supported on Hugging Face Spaces
warnings.warn(
...
I think it’s safe to ignore that warning. It doesn’t interfere with the operation. In fact, it seems to be in a running state.
The problem is the 500 error that is currently occurring, but this is a little unusual. There is a possibility that it is similar to the Tonic issue below. I hope it’s a problem that can be dealt with by the author’s side alone…
This error has occurred twice, and the last time it was due to a faulty network cluster. This time, the cause is still unknown.
I also encountered a 500 Internal server error code when I passed:
demo.queue().launch(auth = custom_auth, share = True)
See:
I’m trying to build the web app with simple auth using Gradio 5.8.0 which works well locally or on Colab.
Is this the same issue that you guys discussed above?
I think your problem is called the Tonic’s 500 error. By the way, there’s nothing wrong with Tonic. In short, it’s a bug caused by the Server Side Rendering (SSR) used in Gradio 5. In many cases, you can get around it by setting ssr_mode=False. Alternatively, you can revert to Gradio 4.44.1 or earlier.