titanabrian commited on
Commit
92885db
·
1 Parent(s): 53429e7

initial commit

Browse files
Files changed (5) hide show
  1. Dockerfile +16 -0
  2. app.py +36 -0
  3. poetry.lock +0 -0
  4. pyproject.toml +20 -0
  5. requirements.txt +49 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
+ import torch
5
+
6
+ app = FastAPI()
7
+
8
+ # Load tokenizer and model from Hugging Face Hub
9
+ import os
10
+ model_name = os.getenv("MODEL_NAME", "titanabrian/whatsapp-text-classifier-distilbert")
11
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
12
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
13
+ model.eval()
14
+
15
+ # Labels must match your model training
16
+ labels = ["confirmation", "question", "task", "transactional", "unclassified"]
17
+
18
+ class Message(BaseModel):
19
+ text: str
20
+
21
+ @app.get("/")
22
+ def root():
23
+ return {"message": "WhatsApp Intent Classifier is ready."}
24
+
25
+ @app.get("/model")
26
+ def get_model():
27
+ return {"model_name": model_name}
28
+
29
+
30
+ @app.post("/predict")
31
+ def predict(msg: Message):
32
+ inputs = tokenizer(msg.text, return_tensors="pt", truncation=True, padding=True)
33
+ with torch.no_grad():
34
+ outputs = model(**inputs)
35
+ pred_id = outputs.logits.argmax(dim=-1).item()
36
+ return {"label": labels[pred_id], "label_id": pred_id}
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "whatsapp-text-classification-api"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = [
6
+ {name = "titanabrian",email = "titanabrian.05@gmail.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.11"
10
+ dependencies = [
11
+ "fastapi (>=0.115.14,<0.116.0)",
12
+ "pydantic (>=2.11.7,<3.0.0)",
13
+ "transformers (>=4.53.1,<5.0.0)",
14
+ "torch (>=2.7.1,<3.0.0)"
15
+ ]
16
+
17
+
18
+ [build-system]
19
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
20
+ build-backend = "poetry.core.masonry.api"
requirements.txt ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.7.0 ; python_version >= "3.11"
2
+ anyio==4.9.0 ; python_version >= "3.11"
3
+ certifi==2025.6.15 ; python_version >= "3.11"
4
+ charset-normalizer==3.4.2 ; python_version >= "3.11"
5
+ colorama==0.4.6 ; python_version >= "3.11" and platform_system == "Windows"
6
+ fastapi==0.115.14 ; python_version >= "3.11"
7
+ filelock==3.18.0 ; python_version >= "3.11"
8
+ fsspec==2025.5.1 ; python_version >= "3.11"
9
+ hf-xet==1.1.5 ; python_version >= "3.11" and (platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "arm64" or platform_machine == "aarch64")
10
+ huggingface-hub==0.33.2 ; python_version >= "3.11"
11
+ idna==3.10 ; python_version >= "3.11"
12
+ jinja2==3.1.6 ; python_version >= "3.11"
13
+ markupsafe==3.0.2 ; python_version >= "3.11"
14
+ mpmath==1.3.0 ; python_version >= "3.11"
15
+ networkx==3.5 ; python_version >= "3.11"
16
+ numpy==2.3.1 ; python_version >= "3.11"
17
+ nvidia-cublas-cu12==12.6.4.1 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
18
+ nvidia-cuda-cupti-cu12==12.6.80 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
19
+ nvidia-cuda-nvrtc-cu12==12.6.77 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
20
+ nvidia-cuda-runtime-cu12==12.6.77 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
21
+ nvidia-cudnn-cu12==9.5.1.17 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
22
+ nvidia-cufft-cu12==11.3.0.4 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
23
+ nvidia-cufile-cu12==1.11.1.6 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
24
+ nvidia-curand-cu12==10.3.7.77 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
25
+ nvidia-cusolver-cu12==11.7.1.2 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
26
+ nvidia-cusparse-cu12==12.5.4.2 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
27
+ nvidia-cusparselt-cu12==0.6.3 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
28
+ nvidia-nccl-cu12==2.26.2 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
29
+ nvidia-nvjitlink-cu12==12.6.85 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
30
+ nvidia-nvtx-cu12==12.6.77 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
31
+ packaging==25.0 ; python_version >= "3.11"
32
+ pydantic-core==2.33.2 ; python_version >= "3.11"
33
+ pydantic==2.11.7 ; python_version >= "3.11"
34
+ pyyaml==6.0.2 ; python_version >= "3.11"
35
+ regex==2024.11.6 ; python_version >= "3.11"
36
+ requests==2.32.4 ; python_version >= "3.11"
37
+ safetensors==0.5.3 ; python_version >= "3.11"
38
+ setuptools==80.9.0 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" or python_version >= "3.12"
39
+ sniffio==1.3.1 ; python_version >= "3.11"
40
+ starlette==0.46.2 ; python_version >= "3.11"
41
+ sympy==1.14.0 ; python_version >= "3.11"
42
+ tokenizers==0.21.2 ; python_version >= "3.11"
43
+ torch==2.7.1 ; python_version >= "3.11"
44
+ tqdm==4.67.1 ; python_version >= "3.11"
45
+ transformers==4.53.1 ; python_version >= "3.11"
46
+ triton==3.3.1 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11"
47
+ typing-extensions==4.14.1 ; python_version >= "3.11"
48
+ typing-inspection==0.4.1 ; python_version >= "3.11"
49
+ urllib3==2.5.0 ; python_version >= "3.11"