# Embedding Spaces with auth for public models counter-intuitive?

**URL:** <https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868>\
**Category:** Spaces\
**Created:** [March 2, 2023, 8:39am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868 "2023-03-02T08:39:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![EtheE](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@EtheE](https://discuss.huggingface.co/u/EtheE)\
**Post date:** [March 2, 2023, 8:39am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/1 "2023-03-02T08:39:52Z")

</div>

I think I must be missing something. Can someone tell me what?

1. Embedding spaces is a great option - but only available for public spaces
2. The gradio instructions even show how to add authentication - awesome!
3. But as your space is now public (because 1), you have to remember to add your auth credentials in a secret, otherwise anyone can just see it in your code
4. Also, you have to make your space public to use the Embed option, while you may not have been ready to do so

My take: One of the clear use cases to use “Embed your space” is to share the app without sharing the code (e.g. prototype for something that is in stealth), but by only allowing the option for public spaces, that use case won’t fly.

Am I missing something? Is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![EtheE](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@EtheE](https://discuss.huggingface.co/u/EtheE)\
**Post date:** [March 7, 2023, 5:46am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/2 "2023-03-07T05:46:23Z")

</div>

For anyone else reading this: I couldn’t find a good solution this for my situation, so I ended up running my Gradio application on one of the well known PaaS providers. Works quite well with github integration, just had to set a few environment settings.

I do want to stress that I’m still a huge fan of Huggingface, and it may not make sense for the platform to support the “stealth” scenario I describe above.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [March 9, 2023, 8:24am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/3 "2023-03-09T08:24:24Z")

</div>

Hello @EtheE, thank you for your feedback. We have received similar requests in the past, we might implement a solution it in the future. However, we have previously suggested different workarounds depending on the specific use case:

- To hide sensitive source code on Space, you can create a private Space and a second public Space which only loads the private Space using the ‘gr.Interface.load()’ method. This method can load a Space even if it is private. Check more her [Gradio Docs](https://gradio.app/docs/#interface-load).

- To hide specific files only, you can create a private dataset/model and use the ‘huggingface\_hub’ client to load your dataset/model using the hub token via Space settings.

- You can also use our Inference Endpoints PaaS service which is fully integrated with HF tools and our hub. This service provides a way to deploy a Space as a REST API. You can learn more about it here [Inference Endpoints - Hugging Face](https://huggingface.co/inference-endpoints)

---

<div class="post-metadata">

**Author:** ![EtheE](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@EtheE](https://discuss.huggingface.co/u/EtheE)\
**Post date:** [March 12, 2023, 5:57am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/4 "2023-03-12T05:57:54Z")

</div>

Thanks @radames! Even though I searched, I hadn’t come across that first answer! While it introduces a bit of overhead, it’s definitely a good option and something I’ll give another try in the near future.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [March 12, 2023, 6:17am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/5 "2023-03-12T06:17:48Z")

</div>

Thanks for the feedback, I’ll update our Space docs

---

<div class="post-metadata">

**Author:** ![germanp](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@germanp](https://discuss.huggingface.co/u/germanp)\
**Post date:** [April 19, 2023, 3:21pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/6 "2023-04-19T15:21:47Z")

</div>

Hello @radames, thank you for the suggestions. I just tried the first option (load Space from a private Space), but the app throws this error if the source code Space is private:

```auto
File "/home/user/.local/lib/python3.8/site-packages/websockets/legacy/client.py", line 329, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

```

Maybe something change lately within Spaces?

I´m using Gradio Blocks instead of directly use gr.load(), according to their documentation. Would this cause the problem?

---

<div class="post-metadata">

**Author:** ![o0o0o00o0](https://avatars.discourse-cdn.com/v4/letter/o/c2a13f/32.png) [@o0o0o00o0](https://discuss.huggingface.co/u/o0o0o00o0)\
**Post date:** [April 25, 2023, 2:25pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/7 "2023-04-25T14:25:18Z")

</div>

However, using ‘gr.load()’ method need user\_token, which will be public in the second space.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [April 25, 2023, 5:49pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/8 "2023-04-25T17:49:55Z")

</div>

hi @germanp, can you please make sure you’re on the latest Gradio version?, checking on the metadata on README.md

```auto
sdk: gradio
sdk_version: 3.27.0

```

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [April 25, 2023, 5:54pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/9 "2023-04-25T17:54:25Z")

</div>

you can use the Spaces secrets to share your user\_token, that will be on the server side on your Gradio app, [Spaces Overview](https://huggingface.co/docs/hub/spaces-overview#managing-secrets)

---

<div class="post-metadata">

**Author:** ![o0o0o00o0](https://avatars.discourse-cdn.com/v4/letter/o/c2a13f/32.png) [@o0o0o00o0](https://discuss.huggingface.co/u/o0o0o00o0)\
**Post date:** [April 26, 2023, 3:24am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/10 "2023-04-26T03:24:03Z")

</div>

Thank you for your response! I just tried it and it worked, but the output is empty while the referenced space works well. It takes the same amount of time as the referenced space, so I think it should have actually run, but there was no expected output.  
My take: I use ‘gr.load().launch()’, my space’s input is a image and output is a video.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [April 26, 2023, 4:43am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/11 "2023-04-26T04:43:07Z")

</div>

another alternative is to try our new gradio client library, it also supports loading from a private Space

> **[Getting Started With The Python Client](https://gradio.app/getting-started-with-the-python-client/)**
>
> A Step-by-Step Gradio Tutorial

---

<div class="post-metadata">

**Author:** ![o0o0o00o0](https://avatars.discourse-cdn.com/v4/letter/o/c2a13f/32.png) [@o0o0o00o0](https://discuss.huggingface.co/u/o0o0o00o0)\
**Post date:** [April 26, 2023, 8:10am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/13 "2023-04-26T08:10:55Z")

</div>

I guess that the video is stored in the referenced space, the output component use the path of the video, when it comes to the second space, it can’t find the video path in his own space, so the output is empty.

---

<div class="post-metadata">

**Author:** ![o0o0o00o0](https://avatars.discourse-cdn.com/v4/letter/o/c2a13f/32.png) [@o0o0o00o0](https://discuss.huggingface.co/u/o0o0o00o0)\
**Post date:** [April 26, 2023, 11:17am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/14 "2023-04-26T11:17:45Z")

</div>

I solved my problem perfectly with this solution. Thank you very much

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [April 26, 2023, 4:59pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/15 "2023-04-26T16:59:09Z")

</div>

very cool @o0o0o00o0 , cc @freddyaboulton since Gradio client solved the issue 🙌

---

<div class="post-metadata">

**Author:** ![khw](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@khw](https://discuss.huggingface.co/u/khw)\
**Post date:** [May 11, 2023, 6:39am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/16 "2023-05-11T06:39:08Z")

</div>

@o0o0o00o0 @radames I tried this the gradio\_client solution to call a private HF space of mine, but the API link I got (in the format of xxx-yyy.hf.space) is not sharable and can only be used by me. Is there a way make it sharable to others?  
Using the gr.load() method I got into the same issue as @o0o0o00o0, where the output images are empty.

---

<div class="post-metadata">

**Author:** ![o0o0o00o0](https://avatars.discourse-cdn.com/v4/letter/o/c2a13f/32.png) [@o0o0o00o0](https://discuss.huggingface.co/u/o0o0o00o0)\
**Post date:** [May 11, 2023, 6:59am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/17 "2023-05-11T06:59:28Z")

</div>

Have you make the space which uses the gradio\_client solution public?

---

<div class="post-metadata">

**Author:** ![sageco214](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@sageco214](https://discuss.huggingface.co/u/sageco214)\
**Post date:** [May 11, 2023, 2:33pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/18 "2023-05-11T14:33:32Z")

</div>

Hi there, I get the following error when I try launching a public space.

```
for fn_index, dependency in enumerate(self.config["dependencies"])

```

KeyError: ‘dependencies’

Would you know why this is happening?

---

<div class="post-metadata">

**Author:** ![khw](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@khw](https://discuss.huggingface.co/u/khw)\
**Post date:** [May 11, 2023, 5:10pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/19 "2023-05-11T17:10:58Z")

</div>

Thanks for responding @o0o0o00o0 . I have made it public.  
Just in case I misunderstood the instruction, here’s my code for the new HF space, which should take image inputs from users and output images:

```auto
import os
from gradio_client import Client
HF_token = os.environ.get('HF_token')
client = Client('xxx/yyy', hf_token=HF_token ) 

```

The new space actually resulted in a runtime error:

```auto
Loaded as API: https://xxx-yyy.hf.space

```

and this API above is what I was referring to as not sharable.

---

<div class="post-metadata">

**Author:** ![jobyzhu](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jobyzhu](https://discuss.huggingface.co/u/jobyzhu)\
**Post date:** [June 2, 2023, 3:42am UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/20 "2023-06-02T03:42:26Z")

</div>

Hi there, did you solve this?  
I also got this error but don’t know what happened.

---

<div class="post-metadata">

**Author:** ![santhakumar](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@santhakumar](https://discuss.huggingface.co/u/santhakumar)\
**Post date:** [June 23, 2023, 6:29pm UTC](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868/21 "2023-06-23T18:29:21Z")

</div>

I am also getting the same error. Not able to load private space from public space with HF token

[Next page](https://discuss.huggingface.co/t/embedding-spaces-with-auth-for-public-models-counter-intuitive/32868.md?page=2)
