Spaces:
Sleeping
Sleeping
| # This workflow trains a model AND deploys the full Gradio app with that model. | |
| name: Train and Deploy Gradio App to Spaces | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| train-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checks out your GitHub repository code | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| # Fetch all history for all branches and tags | |
| fetch-depth: 0 | |
| # Step 2: Set up the Python environment | |
| - name: Set up Python 3.9 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.9' | |
| # Step 3: Install all dependencies from your requirements.txt file | |
| - name: Install Dependencies | |
| run: pip install -r requirements.txt | |
| # Step 4: Prepare the data for training | |
| - name: Prepare Data | |
| run: python prepare_data.py | |
| # Step 5: Train the model to create the model.joblib file | |
| - name: Train Baseline Linear Model | |
| run: python train.py | |
| # Step 6: Push the entire project to your Hugging Face Space | |
| - name: Push to HF Space | |
| env: | |
| # Your HF token, stored as a GitHub secret | |
| HF_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }} | |
| run: | | |
| # Clones your Hugging Face Space repository into a new folder named 'space' | |
| git clone https://ashandilgith:$HF_TOKEN@huggingface.co/spaces/ashandilgith/predictive_maintenance space | |
| # Use rsync to copy all files from the current directory to the 'space' directory, | |
| # excluding the 'space' directory itself to prevent the error. | |
| rsync -av --delete --exclude='/space' --exclude='.git' ./ ./space/ | |
| # Go into the 'space' folder to perform git operations | |
| cd ./space | |
| # Configure git user for the commit | |
| git config --global user.email "actions@github.com" | |
| git config --global user.name "GitHub Actions Bot" | |
| # Add all the new and updated files to be committed | |
| git add . | |
| # Commit the changes with a descriptive message | |
| # The '--allow-empty' flag prevents errors if there are no changes to commit. | |
| git commit -m "feat: Deploy latest version of Gradio app" --allow-empty | |
| # Push the changes to the Hugging Face Space repository | |
| git push |