--- 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 [try-app-here](https://deployment-for-simple-apps-d9dyk3fvonxzk2tgvvzems.streamlit.app/) This guide explains how to deploy your Streamlit app on [Streamlit Cloud](https://share.streamlit.io/) using your GitHub repository. Follow these detailed steps to get your app online and share it with the world. --- ### Table of Contents - [1. Deploying Your Streamlit App on Streamlit Cloud](#1-deploying-your-streamlit-app-on-streamlit-cloud) - [1.1 Prepare Your GitHub Repository](#11-prepare-your-github-repository) - [1.2 Set Up Your Streamlit Cloud Account](#12-set-up-your-streamlit-cloud-account) - [1.3 Deploy Your App on Streamlit Cloud](#13-deploy-your-app-on-streamlit-cloud) - [1.4 Verify and Share Your Deployed App](#14-verify-and-share-your-deployed-app) - [1.5 Additional Tips](#15-additional-tips) - [2. Deploying Your App on Hugging Face Spaces](#2-deploying-your-app-on-hugging-face-spaces) - [2.1 Create a Hugging Face Account](#21-create-a-hugging-face-account) - [2.2 Configure Your Space](#22-configure-your-space) - [2.3 Upload Your Files](#23-upload-your-files) - [2.4 Deploy Your App](#24-deploy-your-app) - [2.5 Sync Your GitHub Repository to Hugging Face Using GitHub Actions](#25-sync-your-github-repository-to-hugging-face-using-github-actions) - [2.6 Monitor and Update](#26-monitor-and-update) --- ### 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 named `app.py` or similar) in the repository’s root or in a designated folder. - **Include a `requirements.txt` File:** Add a `requirements.txt` file listing all the Python packages your app needs. For example: ```plaintext 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](https://share.streamlit.io/) 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` or `master`). - Enter the file path to your main Streamlit script (`app.py`). - Specify Python dependencies using `requirements.txt`. - **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](https://huggingface.co/spaces/Mohamedsheded33/search-engine-llm) ### 2.1 Create a Hugging Face Account - Go to [Hugging Face](https://huggingface.co/) 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** 1. In your GitHub repository, navigate to `.github/workflows/` (create the folders if they don’t exist). 2. Create a new file named `huggingface-sync.yml`. 3. Add the following content to the file: ```yaml 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:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME git push huggingface main --force ``` #### **Step 2: Set Up Hugging Face Secrets in GitHub** 1. Go to your GitHub repository’s **Settings** > **Secrets and variables** > **Actions**. 2. 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](https://huggingface.co/settings/tokens)). - `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.