CoolFace
Apppublic

GeoGhi/news-bias-classifier

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

News Bias Classification API

Minimal FastAPI inference service for a free-first Hugging Face Docker Space demo.

Why the model is not stored in the Space repo

Hugging Face Space repos can hit a 1 GB repository storage limit. This project's model.safetensors is about 1.74 GB, so the Space repo should contain only the API code.

Store the model in a separate Hugging Face model repo, then set the Space variable:

text
HF_MODEL_ID=your-username/news-bias-classifier-model

For a free demo, make the model repo public if possible. If the model repo is private, also add HF_TOKEN as a Space secret.

Endpoints

  • —GET /health
  • —POST /predict

Request:

json
{
  "text": "Full article text"
}

Response:

json
{
  "label": "left",
  "scores": {
    "left": 0.82,
    "center": 0.11,
    "right": 0.07
  }
}

Local development

From C:\Projects\NewsBiasClassification\backend:

powershell
python -m pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Locally, the backend uses the existing model at ../model/final unless HF_MODEL_ID is set.

Prepare the Space folder

From the repository root:

powershell
.\backend\scripts\prepare_hf_space.ps1

This creates:

text
backend/dist/hf-space/

with this shape:

text
.
|- app/
|- model/
|- requirements.txt
|- Dockerfile
|- .dockerignore
`- README.md

The default script output intentionally does not include model/final, so it stays under the Space repo storage limit.

Deploy to Hugging Face Spaces

  1. 1.Create a Hugging Face model repo, for example your-username/news-bias-classifier-model.
  2. 2.Upload the files from C:\Projects\NewsBiasClassification\model\final into that model repo.
  3. 3.Create a new Hugging Face Space.
  4. 4.Choose Docker as the Space SDK.
  5. 5.Choose CPU Basic hardware to keep the demo free.
  6. 6.Upload or push the contents of backend/dist/hf-space to the Space repo root.
  7. 7.In the Space settings, add HF_MODEL_ID=your-username/news-bias-classifier-model.
  8. 8.Wait for the Space to build.
  9. 9.Test https://your-space-name.hf.space/health.
  10. 10.Test POST https://your-space-name.hf.space/predict.

Optional Space variables:

text
HF_MODEL_ID=your-username/news-bias-classifier-model
HF_TOKEN=only-needed-for-private-model-repos
MAX_LENGTH=256
REQUEST_MAX_CHARS=20000
CORS_ORIGINS=https://your-frontend-domain.com

For local frontend testing against the deployed Space, set:

text
NEXT_PUBLIC_API_BASE_URL=https://your-space-name.hf.space