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
Comment on lines +30 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the shellcheck warning by adding quotes around the variable.

The static analysis tool flagged a potential issue with unquoted variable usage that could lead to word splitting.

Apply this diff to fix the shellcheck warning:

-          git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
+          git clone "https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git" space-backend
📝 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
run: |
rm -rf space-backend
git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
run: |
rm -rf space-backend
git clone "https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git" space-backend
🧰 Tools
🪛 actionlint (1.7.7)

30-30: shellcheck reported issue in this script: SC2086:info:2:31: Double quote to prevent globbing and word splitting

(shellcheck)

🤖 Prompt for AI Agents
In .github/workflows/deploy-backend-to-hf.yml around lines 30 to 32, the
HF_TOKEN variable is used without quotes in the git clone command, which can
cause word splitting issues. Fix this by adding double quotes around the
variable reference like "${HF_TOKEN}" to ensure it is treated as a single
argument and prevent shellcheck warnings.


- 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
````
Comment on lines +28 to +29
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct directory name in the quick-start step

The repo places this README under backend/, not new-backend/. The current command will fail.

-cd new-backend
+cd backend
📝 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
cd new-backend
````
cd backend
🤖 Prompt for AI Agents
In backend/README.md around lines 28 to 29, the quick-start step uses the
incorrect directory name 'new-backend'. Change the directory name in the command
from 'new-backend' to 'backend' to match the actual folder where the README and
backend code reside.


### 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