killykilly commited on
Commit
59b19e3
·
verified ·
1 Parent(s): d22c18b

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +15 -0
  2. README.md +19 -3
  3. __pycache__/app.cpython-312.pyc +0 -0
  4. app.py +40 -0
  5. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt \
7
+ --extra-index-url https://download.pytorch.org/whl/cpu
8
+
9
+ COPY app.py .
10
+
11
+ # Writable cache for the model download (Spaces run as non-root uid 1000)
12
+ ENV HF_HOME=/tmp/hf
13
+
14
+ EXPOSE 7860
15
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,10 +1,26 @@
1
  ---
2
- title: Nigerian Transaction Classifier Api
3
- emoji: 📈
4
  colorFrom: green
5
  colorTo: gray
6
  sdk: docker
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Nigerian Transaction Classifier API
3
+ emoji: 🏦
4
  colorFrom: green
5
  colorTo: gray
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  ---
10
 
11
+ # Nigerian Transaction Classifier API
12
+
13
+ Serves `killykilly/nigerian-transaction-classifier` (DistilBERT) over a plain
14
+ HTTP API for the finance-analyzer backend, since the model is not available
15
+ through HF serverless Inference Providers.
16
+
17
+ The model is downloaded from the Hub at container startup, so pushing
18
+ retrained weights to the model repo and restarting this Space is all that is
19
+ needed to upgrade.
20
+
21
+ ## API
22
+
23
+ - `GET /health` → `{"status": "ok", "model": "..."}`
24
+ - `POST /classify` with `{"texts": ["debit | uber trip lagos", ...]}` →
25
+ `{"predictions": [{"label": "Transport", "score": 0.97}, ...]}`
26
+ (one prediction per input, same order)
__pycache__/app.cpython-312.pyc ADDED
Binary file (2.02 kB). View file
 
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from fastapi import FastAPI, HTTPException
4
+ from pydantic import BaseModel
5
+ from transformers import pipeline
6
+
7
+ MODEL_ID = os.getenv("MODEL_ID", "killykilly/nigerian-transaction-classifier")
8
+ MAX_BATCH = int(os.getenv("MAX_BATCH", "256"))
9
+
10
+ classifier = pipeline(
11
+ "text-classification",
12
+ model=MODEL_ID,
13
+ token=os.getenv("HF_TOKEN") or None,
14
+ truncation=True,
15
+ )
16
+
17
+ app = FastAPI(title="Nigerian Transaction Classifier API")
18
+
19
+
20
+ class ClassifyRequest(BaseModel):
21
+ texts: list[str]
22
+
23
+
24
+ @app.get("/health")
25
+ def health():
26
+ return {"status": "ok", "model": MODEL_ID}
27
+
28
+
29
+ @app.post("/classify")
30
+ def classify(request: ClassifyRequest):
31
+ if len(request.texts) > MAX_BATCH:
32
+ raise HTTPException(413, f"batch too large (max {MAX_BATCH})")
33
+ if not request.texts:
34
+ return {"predictions": []}
35
+ results = classifier(request.texts, batch_size=32)
36
+ return {
37
+ "predictions": [
38
+ {"label": r["label"], "score": float(r["score"])} for r in results
39
+ ]
40
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ transformers
4
+ torch