Spaces:
Running
Running
Sachin commited on
Enhance retrain workflow with git history and conditions
Browse filesUpdated retrain workflow to include full git history and conditional model pushing.
.github/workflows/retrain.yml
CHANGED
|
@@ -15,8 +15,13 @@ jobs:
|
|
| 15 |
|
| 16 |
steps:
|
| 17 |
# 1. Get your code from GitHub
|
|
|
|
|
|
|
| 18 |
- name: Checkout repository
|
| 19 |
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# 2. Set up Python
|
| 22 |
- name: Set up Python
|
|
@@ -32,16 +37,25 @@ jobs:
|
|
| 32 |
pip install huggingface_hub
|
| 33 |
|
| 34 |
# 4. Run the training script
|
| 35 |
-
# This downloads data from your HF Dataset and trains a new model
|
| 36 |
- name: Run training script
|
|
|
|
| 37 |
env:
|
| 38 |
HF_WRITE_TOKEN: ${{ secrets.HF_WRITE_TOKEN }}
|
| 39 |
run: |
|
| 40 |
python train_intent_classifier.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
# 5. Push the NEW MODEL
|
| 43 |
-
# --- THIS IS THE CORRECTED STEP ---
|
| 44 |
- name: Push new model files to Hub
|
|
|
|
| 45 |
env:
|
| 46 |
HF_TOKEN: ${{ secrets.HF_WRITE_TOKEN }}
|
| 47 |
run: |
|
|
@@ -63,9 +77,9 @@ jobs:
|
|
| 63 |
print('Model upload complete.')
|
| 64 |
EOF
|
| 65 |
|
| 66 |
-
# 6. Push
|
| 67 |
-
# This automatically triggers a restart of your Space
|
| 68 |
- name: Push code to Space and trigger restart
|
|
|
|
| 69 |
env:
|
| 70 |
HF_TOKEN: ${{ secrets.HF_WRITE_TOKEN }}
|
| 71 |
run: |
|
|
@@ -73,13 +87,9 @@ jobs:
|
|
| 73 |
git config --global user.email "github-actions@github.com"
|
| 74 |
git config --global user.name "GitHub Actions"
|
| 75 |
|
| 76 |
-
# Add the Hugging Face Space as a new git "remote"
|
| 77 |
-
# This uses your secret token to authenticate
|
| 78 |
git remote add hf_space https://oauth:${HF_TOKEN}@huggingface.co/spaces/Sachin21112004/DreamFlow-AI
|
| 79 |
|
| 80 |
echo "Pushing code to Space..."
|
| 81 |
-
# Force-push the code from GitHub to the Space's 'main' branch
|
| 82 |
-
# This overwrites the code on the Space with your GitHub code
|
| 83 |
git push hf_space main --force
|
| 84 |
|
| 85 |
echo "Code push to Space complete. Space will restart automatically."
|
|
|
|
| 15 |
|
| 16 |
steps:
|
| 17 |
# 1. Get your code from GitHub
|
| 18 |
+
# --- THIS IS THE FIX ---
|
| 19 |
+
# We added "fetch-depth: 0" to download the full git history
|
| 20 |
- name: Checkout repository
|
| 21 |
uses: actions/checkout@v4
|
| 22 |
+
with:
|
| 23 |
+
fetch-depth: 0
|
| 24 |
+
# ------------------------
|
| 25 |
|
| 26 |
# 2. Set up Python
|
| 27 |
- name: Set up Python
|
|
|
|
| 37 |
pip install huggingface_hub
|
| 38 |
|
| 39 |
# 4. Run the training script
|
|
|
|
| 40 |
- name: Run training script
|
| 41 |
+
id: train_step
|
| 42 |
env:
|
| 43 |
HF_WRITE_TOKEN: ${{ secrets.HF_WRITE_TOKEN }}
|
| 44 |
run: |
|
| 45 |
python train_intent_classifier.py
|
| 46 |
+
|
| 47 |
+
# Check if the model directory was created by the script
|
| 48 |
+
if [ -d "./models/intent-classifier" ]; then
|
| 49 |
+
echo "Training successful. Model directory found."
|
| 50 |
+
echo "MODEL_TRAINED=true" >> $GITHUB_OUTPUT
|
| 51 |
+
else
|
| 52 |
+
echo "Training skipped (e.g., not enough data). Model directory not found."
|
| 53 |
+
echo "MODEL_TRAINED=false" >> $GITHUB_OUTPUT
|
| 54 |
+
fi
|
| 55 |
|
| 56 |
+
# 5. Push the NEW MODEL (Only if a model was trained)
|
|
|
|
| 57 |
- name: Push new model files to Hub
|
| 58 |
+
if: steps.train_step.outputs.MODEL_TRAINED == 'true'
|
| 59 |
env:
|
| 60 |
HF_TOKEN: ${{ secrets.HF_WRITE_TOKEN }}
|
| 61 |
run: |
|
|
|
|
| 77 |
print('Model upload complete.')
|
| 78 |
EOF
|
| 79 |
|
| 80 |
+
# 6. Push code to Space (Only if a model was trained)
|
|
|
|
| 81 |
- name: Push code to Space and trigger restart
|
| 82 |
+
if: steps.train_step.outputs.MODEL_TRAINED == 'true'
|
| 83 |
env:
|
| 84 |
HF_TOKEN: ${{ secrets.HF_WRITE_TOKEN }}
|
| 85 |
run: |
|
|
|
|
| 87 |
git config --global user.email "github-actions@github.com"
|
| 88 |
git config --global user.name "GitHub Actions"
|
| 89 |
|
|
|
|
|
|
|
| 90 |
git remote add hf_space https://oauth:${HF_TOKEN}@huggingface.co/spaces/Sachin21112004/DreamFlow-AI
|
| 91 |
|
| 92 |
echo "Pushing code to Space..."
|
|
|
|
|
|
|
| 93 |
git push hf_space main --force
|
| 94 |
|
| 95 |
echo "Code push to Space complete. Space will restart automatically."
|