Accessing data in a private space from a public space

I have two spaces: a private space which contains image files and displays them in a gradio gallery, and a public space which loads this private space to run the app. The issue I am running into is that the images are loaded correctly while using the app in the private space, but the app in the public space fails to load them (the app continues running, just fails to load the data).

Does anyone know why a public space that loads a private space would not correctly load data? Is there some sort of permission that needs to be given to the public space to access this data? I’m at a loss and would greatly appreciate any and all help!

Hello @BBongiovanni,

Your second space being private the first one does not have access to it. A space does not have the permissions you have as a user.

To use your private space from the public one you’ll need to specify a token.

From your account generate a read access token then add a header to your requests of the form

Authorization: Bearer $HF_TOKEN

You can create a secret in your space settings to set this token to be used a runtime as an environment variable.

Thank you for your response! Below is the app.py file in the public space. I am not making a request, but rather loading a gradio Hugging Face repo. Is it possible to specify a Bearer token using this method? Or should I go about loading a private space in a different manner?

I really appreciate your help - I was close to giving up on this project entirely!

import os
import gradio as gr

read_key = os.environ.get('hf_space_api_key', None)

with gr.Blocks() as demo:
    gr.load("BBongiovanni/vexilink_private", api_key=read_key, hf_token=read_key, src="spaces")

demo.queue(concurrency_count=10, max_size=20)
demo.launch()

According to the Gradio documentation the parameter hf_token is available.

So creating a secret in your space’s settings HF_TOKEN=<access_token> you should be able to run:

import os
import gradio as gr

read_key = os.environ.get('HF_TOKEN', None)

with gr.Blocks() as demo:
    gr.load("BBongiovanni/vexilink_private", hf_token=read_key, src="spaces")

demo.queue(concurrency_count=10, max_size=20)
demo.launch()

@chris-rannou I created a new READ access token in my profile and added its contents as a secret in the public repo. Used the code you provided and still no luck.

The token is obviously being used correctly as we can run the app in the public space (https://huggingface.co/spaces/BBongiovanni/vexilink), but when the gradio gallery object is populated, none of the images show up… I’m stumped…

Do the images display correctly on the private space ?

@chris-rannou Yep, that’s correct. The app in the public space works as expected EXCEPT that the images that should be rendered in the gradio gallery are not. Their titles do, however. Here are two pictures of what the private and public space gives us.

Private space (works perfectly)

Public space (works perfectly EXCEPT the images do not appear)

Getting below error while loading a pvt space from public space.
/home/user/app/app.py:9: GradioUnusedKwargWarning: You have unused kwarg parameters in Chatbot, please remove them: {‘likeable’: False}
demo = gr.load(name=“spaces/amitagh/TestChatIntf”, hf_token = hf_key, api_key = hf_key)
Traceback (most recent call last):
File “/home/user/app/app.py”, line 9, in
demo = gr.load(name=“spaces/amitagh/TestChatIntf”, hf_token = hf_key, api_key = hf_key)
File “/home/user/.local/lib/python3.10/site-packages/gradio/external.py”, line 70, in load
return load_blocks_from_repo(
File “/home/user/.local/lib/python3.10/site-packages/gradio/external.py”, line 109, in load_blocks_from_repo
blocks: gradio.Blocks = factory_methods[src](name, hf_token, alias, **kwargs)
File “/home/user/.local/lib/python3.10/site-packages/gradio/external.py”, line 504, in from_spaces
return from_spaces_blocks(space=space_name, hf_token=hf_token)
File “/home/user/.local/lib/python3.10/site-packages/gradio/external.py”, line 510, in from_spaces_blocks
return gradio.Blocks.from_config(client.config, predict_fns, client.src)
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 801, in from_config
targets = [
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 803, in
original_mapping[
KeyError: None

more details here gr.load() failing with Error · Issue #5927 · gradio-app/gradio · GitHub.
Have you come across something similar.
Pvt space is working fine but public space has this error while loading.

Hi! Not sure if you’re still having this issue, but I came upon your post because I had a similar question. Here’s the solution! I loaded my private space using a token as an environmental variable as discussed earlier in this thread. Then I used my private space as a function and that worked perfectly! Here’s the Gradio documentation for how to use a block like a function: Using Blocks Like Functions

Either way, I hope this helps someone because it took me a while to figure out lol

Can you show me how you did so, because the functionality of my private repo is not working, the buttons for example