Keep hitting 500 Internal server error when trying to launch gradio app in Spaces

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?

Link to my space: Transcribe4myfriend - a Hugging Face Space by lucharo

2 Likes

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( 
...
1 Like

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…:sweat_smile:
This error has occurred twice, and the last time it was due to a faulty network cluster. This time, the cause is still unknown.

Hi HF-ers,

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?

No updates on this 500 issue?

Thanks!

1 Like

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.

#demo.launch(share=True, auth=("username", "password"))
demo.launch(share=True, auth=("username", "password"), ssr_mode=False)
2 Likes

Huge thanks for the workaround you shared! I was really struggling with this and tried so many ways to no avail. You saved me a ton more time.

Thanks again, you’re awesome!

1 Like