Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/deploy-backend-to-hf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 🚀 Deploy Backend to HF Space

on:
push:
branches:
- main # or your primary branch
paths:
- "backend/**" # only trigger when anything under backend/ changes

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 👉 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 🔒 Install HF CLI
run: pip install huggingface_hub

- name: 🔑 HF login
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: huggingface-cli login --token "$HF_TOKEN"

- name: 📂 Prepare Space repo
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
rm -rf space-backend
git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make the Hugging Face username configurable.

The hardcoded username "Thunder1245" reduces workflow reusability. Consider using a GitHub secret or repository variable.

-          git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
+          git clone https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/perspective-backend.git space-backend

Add HF_USERNAME to your repository secrets or use a repository variable.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
git clone https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/perspective-backend.git space-backend
🤖 Prompt for AI Agents
In .github/workflows/deploy-backend-to-hf.yml at line 32, the Hugging Face
username is hardcoded as "Thunder1245" in the git clone URL, which limits
reusability. Replace the hardcoded username with a reference to a GitHub secret
or repository variable named HF_USERNAME, so the username can be configured
externally. Ensure you add HF_USERNAME to your repository secrets or variables
accordingly.


- name: 📦 Install rsync
run: |
sudo apt-get update
sudo apt-get install -y rsync

- name: 📤 Sync backend code
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
cd space-backend

# Only remove tracked files (preserve .git and config)
git rm -r . || true
cd ..

# Copy new backend files in
cp -R backend/. space-backend/

# Push new code to HF Space
cd space-backend
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add --all
git commit -m "Auto‑deploy backend: ${{ github.sha }}" || echo "No changes to commit"
git push origin main

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ share/python-wheels/
*.egg
MANIFEST

.github/act-events/
.secrets

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.venv
*/.env
File renamed without changes.
30 changes: 30 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.13-slim-bookworm

COPY --from=ghcr.io/astral-sh/uv:0.7.12 /uv /bin/uv

# Install OS dependencies
RUN apt-get update && apt-get install -y curl build-essential

# Create app dir and set it as working directory
WORKDIR /app

# Create a writable cache dir & change ownership to a non-root user
ENV UV_CACHE_DIR=/app/.uv-cache
RUN mkdir -p /app/.uv-cache && \
adduser --disabled-password --gecos "" appuser && \
chown -R appuser:appuser /app

# Copy project code
COPY . /app

# Switch to non-root user
USER appuser

# Install dependencies
RUN uv sync --locked --no-cache

# Expose the port Hugging Face looks for
EXPOSE 7860

# Start the app
CMD ["uv", "run", "main.py"]
91 changes: 91 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: Perspective API 🧠
emoji: 🧠
colorFrom: green
colorTo: blue
sdk: docker
sdk_version: "0.100.0"
app_file: Dockerfile
pinned: false
---


# Perspective Backend


Welcome to the **Perspective** backend! 🚀

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

---

## Getting Started

### 1. Clone the repo & jump into backend folder

```bash
git clone https://github.com/AOSSIE-Org/Perspective.git
cd new-backend
````

### 2. Add new modules easily

To add any new Python package/module, just run:

```bash
uv add <module_name>
```

Example:

```bash
uv add fastapi requests
```

This will automatically update your `pyproject.toml` and install the package for you.

*No need to manually create or activate virtual environments — uv handles it for you!*

### 3. Run the server

Start the backend server with:

```bash
uv run main.py
```

The server will be available at:

```
http://localhost:8000/api/
```

---

## Important Notes

* All dependencies are tracked in `pyproject.toml`.
* No manual setup of venv or conda environments is required.
* For full documentation on **uv**, visit:
[https://docs.astral.sh/uv/](https://docs.astral.sh/uv/)

---

## Project Structure (brief)

```
new-backend/
├── main.py # App entry point
├── pyproject.toml # Dependency & project config
├── uv.lock # .loc file like package-lock.json
├── .python-version # Python version used by the backend
└── app/
├── routes/ # API route handlers
├── components/ # Business logic components
├── db/ # Database related code
└── utils/ # Utility functions
```

---

If you hit any issues or want to contribute, feel free to open an issue or PR.
File renamed without changes.
Empty file removed backend/app/core/config.py
Empty file.
Empty file removed backend/app/db/database.py
Empty file.
Empty file removed backend/app/db/models.py
Empty file.
File renamed without changes.
23 changes: 0 additions & 23 deletions backend/app/main.py

This file was deleted.

Empty file removed backend/app/models/schemas.py
Empty file.
File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions backend/app/prompts/opposite_perspective.py

This file was deleted.

26 changes: 0 additions & 26 deletions backend/app/prompts/related_topics.py

This file was deleted.

69 changes: 0 additions & 69 deletions backend/app/routes.py

This file was deleted.

File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions backend/app/scrapers/article_scraper.py

This file was deleted.

16 changes: 0 additions & 16 deletions backend/app/scrapers/clean_data.py

This file was deleted.

Loading