-
-
Notifications
You must be signed in to change notification settings - Fork 76
Rendering data on /results page. #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
533b118
added Dockerfile for backend-deployment on Hugging Face Spaces
ParagGhatage 56804b6
removed old backend
ParagGhatage 7d5eaf0
renamed new-backend to backend
ParagGhatage bff2d65
added renamed backend folder to the git
ParagGhatage b02db47
Added GitHub Actions to deploy backend to Hugging Face Apce after eac…
ParagGhatage 0712a25
change in backend url in /analyze/loading page
ParagGhatage 982e9b8
rendered data returned from backend on the frontend /redults page
ParagGhatage 3291e26
Merge branch 'main' into rendering-data
ParagGhatage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| - 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /.venv | ||
| */.env |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Empty file.
Empty file.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Add
HF_USERNAMEto your repository secrets or use a repository variable.📝 Committable suggestion
🤖 Prompt for AI Agents