Spaces:
Sleeping
A newer version of the Streamlit SDK is available:
1.43.1
title: Search Engine Llm
emoji: 🏢
colorFrom: purple
colorTo: gray
sdk: streamlit
sdk_version: 1.42.2
app_file: app.py
pinned: false
license: apache-2.0
short_description: a sample llm app for deploying on HF spaces
Deployment-for-simple-apps
deployment of LLM apps in various spaces (Streamlit, Hugging Face Spaces)
1. Deploying Your Streamlit App on Streamlit Cloud
This guide explains how to deploy your Streamlit app on Streamlit Cloud using your GitHub repository. Follow these detailed steps to get your app online and share it with the world.
Table of Contents
1.1 Prepare Your GitHub Repository
Create a Repository:
Create a new GitHub repository where you will store your Streamlit app code.Add Your Streamlit App:
Place your main Streamlit script (commonly namedapp.py
or similar) in the repository’s root or in a designated folder.Include a
requirements.txt
File:
Add arequirements.txt
file listing all the Python packages your app needs. For example:streamlit numpy pandas
Commit and Push:
Ensure all files are committed and pushed to GitHub.
1.2 Set Up Your Streamlit Cloud Account
Sign Up/Login:
Go to Streamlit Cloud and sign up or log in using your GitHub account.Connect GitHub:
Authorize Streamlit Cloud to access your GitHub repositories.
1.3 Deploy Your App on Streamlit Cloud
Create a New App Deployment:
Click the 'New App' button on Streamlit Cloud and select your GitHub repository.Configure Deployment Settings:
- Select the branch (e.g.,
main
ormaster
). - Enter the file path to your main Streamlit script (
app.py
). - Specify Python dependencies using
requirements.txt
.
- Select the branch (e.g.,
Deploy:
Click the 'Deploy' button. Streamlit Cloud will automatically set up the environment and run your app.
1.4 Verify and Share Your Deployed App
Check for Errors:
Monitor the deployment logs to identify any issues.Get Your App Link:
Once deployed, Streamlit Cloud provides a public URL for your app.Share Your App:
Share the generated URL with others to access your app.
1.5 Additional Tips
Use a
secrets.toml
File for Credentials:
Store API keys and sensitive data securely using the Streamlit Cloud secrets management feature.Monitor App Usage:
Check Streamlit Cloud’s analytics to monitor user interactions.
2. Deploying Your App on Hugging Face Spaces
Hugging Face Spaces provides an easy way to deploy machine learning models and apps using frameworks like Streamlit, Gradio, and FastAPI. Follow these steps to deploy your app on Hugging Face Spaces. app-here
2.1 Create a Hugging Face Account
- Go to Hugging Face and sign up or log in.
- Navigate to 'Spaces' and click 'Create a new Space'.
2.2 Configure Your Space
- Select a Framework: Choose 'Streamlit' as the framework if you are deploying a Streamlit app.
- Set Visibility: Choose whether your Space is public or private.
- Connect to GitHub (Optional): You can link your Space to a GitHub repository.
2.3 Upload Your Files
- Add your
app.py
file (or the main script for your app). - Include a
requirements.txt
file listing all required dependencies. - Commit and push the files to your Hugging Face Space.
2.4 Deploy Your App
- Once the files are uploaded, Hugging Face will automatically build and deploy your app.
- You will receive a public URL where users can access your app.
2.5 Sync Your GitHub Repository to Hugging Face Using GitHub Actions
To keep your Hugging Face Space updated with changes from your GitHub repository, you can set up a GitHub Action workflow.
Step 1: Create a GitHub Action Workflow
- In your GitHub repository, navigate to
.github/workflows/
(create the folders if they don’t exist). - Create a new file named
huggingface-sync.yml
. - Add the following content to the file:
name: Sync to Hugging Face Spaces
on:
push:
branches:
- main # Adjust this if your branch is different
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Push to Hugging Face Space
env:
HF_USERNAME: ${{ secrets.HF_USERNAME }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
SPACE_NAME: your-space-name
run: |
git remote add huggingface https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME
git push huggingface main --force
Step 2: Set Up Hugging Face Secrets in GitHub
- Go to your GitHub repository’s Settings > Secrets and variables > Actions.
- Click New repository secret and add the following:
HF_USERNAME
: Your Hugging Face username.HF_TOKEN
: Your Hugging Face API token (get it from Hugging Face settings).SPACE_NAME
: The name of your Hugging Face Space.
Step 3: Push Changes to Trigger the Action
Whenever you push a new commit to your repository, this workflow will automatically update your Hugging Face Space.
By following these steps, you ensure that your Hugging Face Space always stays in sync with your GitHub repository without manual updates.
2.6 Monitor and Update
- Check logs for errors and debugging.
- Update your files and commit changes to reflect updates in your Space.