--- title: Chainlit Docker emoji: 📉 colorFrom: yellow colorTo: red sdk: docker pinned: false --- to run locally: chainlit run app.py -w --- This application is used to deploy a Chainlit application on HuggingFace space. The code is on the Github repository and it is linked throgh Github actions to HuggingFace so that for each push on Github there's an associated push to HuggingFace: Docker is used in order to perform the deploy. The readme file has to contain as first rows what's present above in order to deploy it correctly. Chainlit authentication is used. --- Check out the configuration reference at https://huggingface.co./docs/hub/spaces-config-reference Create a Dockerfile as follows: FROM python:3.9 WORKDIR /code COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt COPY . . CMD ["chainlit", "run", "app.py", "--port", "7860"] Then commit and push: git add . git commit -m "first commit" git push **\*\*** ATTENTION **\*\*** The PUSH as it is will FAILS: since October 2023 it is not possible to push using simply username and password: we need to generate a token at HuggingFace and perform the push accordingly: https://huggingface.co./blog/password-git-deprecation If you don’t have any SSH keys on your machine, you can use ssh-keygen to generate a new SSH key pair (public + private keys): ssh-keygen -t ed25519 -C "your.email@example.co" Be sure that the OpenSSH service is STARTED This generates the couple of keys in the current folder; better to move them into the standard ssh folder (in windows usually c:\users\MYUSERNAME\.ssh; in such scenario we will have something like c:\users\MYUSERNAME\.ssh\ed25519 and inside the pub and private key with the name chosen) Once your new key is generated, add it to your SSH agent with ssh-add; let's assume we have a key with name id_ed25519 in the folder C:\users\paisl\.ssh\id_ed25519: ssh-add "C:\users\paisl\.ssh\id_ed25519\id_ed25519" To add a SSH key to your account, click on the “Add SSH key” button. Then, enter a name for this key (for example, “Personal computer”), and copy and paste the content of your public SSH key in the area below. The public key is located in the ~/.ssh/id_XXXX.pub file you found or generated in the previous steps. Click on “Add key”, and voilà! You have added a SSH key to your huggingface.co account. > ssh -T git@hf.co > The authenticity of host 'hf.co (...)' can't be established. > ED25519 key fingerprint is ... > This key is not known by any other names > Are you sure you want to continue connecting (yes/no/[fingerprint])? yes > Warning: Permanently added 'hf.co' (ED25519) to the list of known hosts. > Hi MY_NAME, welcome to Hugging Face. > ssh -T git@hf.co > Hi ..., welcome to Hugging Face. git remote set-url origin https://MY_GITHUB_NAME:MY_TOKEN@huggingface.co/spaces/MY_HUGGING_FACE_NAME/Chainlit-docker git pull origin Once pulled, the target: https://huggingface.co./spaces/MY_HUGGINGFACE_NAME/Chainlit-docker?logs=container will starting loading the application (we will see the logs) and in the end we will see it running at: https://huggingface.co./spaces/MY_HUGGINGFACE_NAME/Chainlit-docker Let's now push the code into the Github repo: let's create the Github repo and let's ADD this new repo to the config: git remote add github_repo https://github.com/MY_GITHUB_NAME/Chainlit-docker.git in order to push on this we need to specify the github repo, so performing: git push github_repo You can keep your app in sync with your GitHub repository with Github Actions First, you should set up your GitHub repository and Spaces app together. Add your Spaces app as an additional remote to your existing Git repository. git remote add space https://huggingface.co./spaces/MY_HUGGINGFACE_NAME/Chainlit-docker Then force push to sync everything for the first time: git push --force space main Create a Github secret with your HF_TOKEN. Github secret tutorial: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-encrypted-secrets-for-an-environment repository -> settings -> secrets and variables -> actions -> new repo secret create the HF_TOKEN with the value of the token configured in HuggingFace In your repository, create the .github/workflows/ directory to store your workflow files: - actions_onpull.yaml - actions_onpush.yaml in order to push on Github repo we need to type: git push github_repo It is possible to act as follows: - cloning the repo to a new folder - performing all operations and everything will be alligned to hugging face; such as: -- git add . -- git commit -m "do something" -- git push Please note that the last opearation is no more git push github_repo but just git push, because github is the main reference now -- in order to handle authentication it is necessary to generate a key: chainlit create-secret then the key generated must be included in the .env file CHAINLIT_AUTH_SECRET=YOUR_KEY_HERE