Share app url without sharing the files and version

Hi Community!

I just want to share the URL of my application without sharing the Files and versions on Huggingface spaces. Is there any way to achieve this?

6 Likes

Hi @Kunal7 !

Is this for gradio or streamlit? To be clear, you’d like to share your space without people being able to read it’s source code?

I’ve a streamlit app that I’d like to host on huggingface spaces without people being able to read the source code. Is it possible to do so?

Hi @freddyaboulton!

Thanks for the response. I am trying to deploy my app on streamlit.

To be clear, you’d like to share your space without people being able to read its source code?

Yes, exactly. This is what I intend to do

Thanks for the clarification @Kunal7 and @anon15932797 ! There isn’t a built in solution for this at the moment. Will bring this up with the team!

@Kunal7 and @anon15932797 one thing you could do is clone a private repo from your app.py file and import your demo from there. I’ve seen that with gradio demos it might work with streamlit!

Can you please explain your use case a bit more? How come you’d like to keep the code private?

1 Like

That is actually a great idea, one can use that with fine-granular personal access token(PAT).

Create a PAT from GitHub with Content read access and use it as a password.

Basically, the link will become
https://YOUR_USERNAME:YOUR_PAT_TOKEN@github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git

It is not possible to use ssh (port 22) because only ports 80 and 443 are allowed.

Then, by using the gitpython library, the repository can be downloaded from the inside of the python script

Another way would be using SSH over HTTPS, I tried and learned a lot about underlying containers, I would be happy if anyone would like to try that. :slight_smile:

1 Like

I’ve created a PAT from Github with content read access and followed the other instructions. However I couldn’t figure out how to use gitpython, could you elaborate on this? I’ve tried git.Repo.clone_from() function and also tried using pygit2 package.

After installing gitpython, you can import it:

from git import Repo

And using clone_from()

Repo.clone_from("https://YOUR_USERNAME:YOUR_PAT_TOKEN@github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git", 
    "/repo_directory")

I assume you know putting your PAT Token to secrets and calling it from environment variables. Otherwise someone can read your private repository. The following document structure is expected:

your_huggingface_repo/
  app.py
  README.py
  repo_directory/
    inside_code.py

After downloading the repo:

import repo_directory.inside_code as inside_code

should be the last step.

1 Like

I’ve followed these steps and it works with default values, but whenever I make a different selection from drop-down it’s throwing an error

GitCommandError: Cmd('git') failed due to: exit code(128) cmdline: git clone -v https://*****:*****@github.com/TracingInsights/Charts.git repo_directory stderr: 'fatal: destination path 'repo_directory' already exists and is not an empty directory. '

My huggingface space is at: F1 Analysis - a Hugging Face Space by tracinginsights
My streamlit app is at: https://tracinginsights.streamlit.app/

Hi there, currently I’m in a position where I need to hide my code but I do wan’t to share the streamlit app. Did you manage to get it working, and if yes, how did you solve this last drop-down error?

hi @BobvanVeen , I’ve recently responded to same same question here, please let me know if that helps you, otherwise I’m happy to help

2 Likes

Hi everyone! I’ve got a gradio app hosted on HuggingFace Spaces that I’m using to collect data from different users on HuggingFace Datasets. However, I don’t want to expose the code to the users. How can I achieve that?

2 Likes

Hi @radames I’ve tried using gr.load() to load my sreamlit app from a private space but I get ValueError: Could not load the Space. Is there a workaround for streamlit apps?

Hi @aannor, unfortunately, all these tricks only work for Gradio apps as gr.load() is an exclusive design considering Spaces infra. I’m not familiar with any tricks to overcome this with Streamlit. Perhaps @whitphx knows of a trick?

Unfortunately I don’t have any idea on it… ALAIK gr.load() only works with Gradio Spaces (and Model repos).

Just don’t recreate the directory if it already exists

if os.path.exists('./repo'):
    pass
else:
    Repo.clone_from(st.secrets['GIT_URL'],'./repo')