# Accessing data in a private space from a public space

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%3E%5C
**Category:** Spaces\
**Created:** [August 7, 2023, 1:58am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741 "2023-08-07T01:58:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BBongiovanni](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@BBongiovanni](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FBBongiovanni)%5C
**Post date:** [August 7, 2023, 1:58am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F1 "2023-08-07T01:58:19Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![chris-rannou](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@chris-rannou](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchris-rannou)%5C
**Post date:** [August 16, 2023, 10:08am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F2 "2023-08-16T10:08:21Z")

</div>

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](https://huggingface.co/docs/hub/security-tokens) then add a header to your requests of the form

```auto
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.

---

<div class="post-metadata">

**Author:** ![BBongiovanni](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@BBongiovanni](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FBBongiovanni)%5C
**Post date:** [August 16, 2023, 2:58pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F3 "2023-08-16T14:58:40Z")

</div>

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!

```auto
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()

```

---

<div class="post-metadata">

**Author:** ![chris-rannou](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@chris-rannou](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchris-rannou)%5C
**Post date:** [August 16, 2023, 3:47pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F4 "2023-08-16T15:47:58Z")

</div>

According to the [Gradio documentation](https://www.gradio.app/docs/load) 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:

```auto
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()
```

---

<div class="post-metadata">

**Author:** ![BBongiovanni](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@BBongiovanni](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FBBongiovanni)%5C
**Post date:** [August 16, 2023, 4:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F5 "2023-08-16T16:11:10Z")

</div>

@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](https://huggingface.co/spaces/BBongiovanni/vexilink)), but when the gradio gallery object is populated, none of the images show up… I’m stumped…

---

<div class="post-metadata">

**Author:** ![chris-rannou](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@chris-rannou](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchris-rannou)%5C
**Post date:** [August 17, 2023, 6:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F6 "2023-08-17T06:56:28Z")

</div>

Do the images display correctly on the private space ?

---

<div class="post-metadata">

**Author:** ![BBongiovanni](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@BBongiovanni](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FBBongiovanni)%5C
**Post date:** [August 17, 2023, 1:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F7 "2023-08-17T13:12:30Z")

</div>

@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)

 ![Screenshot 2023-08-17 at 9.08.23 AM](https://us1.discourse-cdn.com/hellohellohello/original/3X/4/9/49a5f94022773f66532761365e938d29d5648b36.png)

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

 ![Screenshot 2023-08-17 at 9.08.48 AM](https://us1.discourse-cdn.com/hellohellohello/original/3X/3/7/37ac3472433a9afbcc6eb743cdde78d77f4a3b38.png)

---

<div class="post-metadata">

**Author:** ![amitagh](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@amitagh](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Famitagh)%5C
**Post date:** [October 16, 2023, 1:34pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F8 "2023-10-16T13:34:14Z")

</div>

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](https://github.com/gradio-app/gradio/issues/5927).  
Have you come across something similar.  
Pvt space is working fine but public space has this error while loading.

---

<div class="post-metadata">

**Author:** ![Juggling](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Juggling](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJuggling)%5C
**Post date:** [January 24, 2024, 5:15pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F9 "2024-01-24T17:15:24Z")

</div>

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](https://www.gradio.app/guides/using-blocks-like-functions)

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

---

<div class="post-metadata">

**Author:** ![shimaahmedd](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@shimaahmedd](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fshimaahmedd)%5C
**Post date:** [March 27, 2024, 3:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F10 "2024-03-27T15:08:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kpranav22](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@kpranav22](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkpranav22)%5C
**Post date:** [February 25, 2025, 6:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccessing-data-in-a-private-space-from-a-public-space%2F49741%2F12 "2025-02-25T06:56:50Z")

</div>

Hi, @chris-rannou  
I had tried using approach, it is working but I am unable to get the output. The other private space is generating the output but it is not showing in the my public space.
