Skip to content

Commit b02db47

Browse files
committed
Added GitHub Actions to deploy backend to Hugging Face Apce after each push to main branch
1 parent bff2d65 commit b02db47

5 files changed

Lines changed: 64 additions & 19 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: 🚀 Deploy Backend to HF Space
2+
3+
on:
4+
push:
5+
branches:
6+
- main # or your primary branch
7+
paths:
8+
- "backend/**" # only trigger when anything under backend/ changes
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: 👉 Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: 🔒 Install HF CLI
20+
run: pip install huggingface_hub
21+
22+
- name: 🔑 HF login
23+
env:
24+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
25+
run: huggingface-cli login --token "$HF_TOKEN"
26+
27+
- name: 📂 Prepare Space repo
28+
env:
29+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
30+
run: |
31+
rm -rf space-backend
32+
git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
33+
34+
- name: 📦 Install rsync
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y rsync
38+
39+
- name: 📤 Sync backend code
40+
env:
41+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
42+
run: |
43+
cd space-backend
44+
45+
# Only remove tracked files (preserve .git and config)
46+
git rm -r . || true
47+
cd ..
48+
49+
# Copy new backend files in
50+
cp -R backend/. space-backend/
51+
52+
# Push new code to HF Space
53+
cd space-backend
54+
git config user.name "github-actions[bot]"
55+
git config user.email "github-actions[bot]@users.noreply.github.com"
56+
git add --all
57+
git commit -m "Auto‑deploy backend: ${{ github.sha }}" || echo "No changes to commit"
58+
git push origin main
59+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ share/python-wheels/
2525
*.egg
2626
MANIFEST
2727

28+
.github/act-events/
29+
.secrets
30+
2831
# PyInstaller
2932
# Usually these files are written by a python script from a template
3033
# before PyInstaller builds the exe, so as to inject date/other infos into it.

backend/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ app_file: Dockerfile
99
pinned: false
1010
---
1111

12+
1213
# Perspective Backend
1314

15+
1416
Welcome to the **Perspective** backend! 🚀
1517

1618
This backend is built with FastAPI and managed using **uv**, a handy Python project tool that simplifies dependency management and running the app.

backend/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies = [
1919
"newspaper3k>=0.2.8",
2020
"nltk>=3.9.1",
2121
"pinecone>=7.3.0",
22-
"pinecone-client>=6.0.0",
2322
"rake-nltk>=1.0.6",
2423
"readability-lxml>=0.8.4.1",
2524
"requests>=2.32.3",

backend/uv.lock

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)