CoolFace
Apppublic

Damanger/ai-vs-human

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
1likes
App README

AI vs Human Text Detector — FastAPI + Docker (Hugging Face Space ready)

This repository exposes your uploaded Keras model (model.keras) as a simple HTTP API.

Endpoints

  • —GET /health — quick status probe
  • —POST /predict — body: {"text": "..."}
  • —POST /predict-batch — body: {"texts": ["...", "..."]}

Sample:

bash
curl -X POST http://localhost:7860/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "This is a sample essay."}'

Project layout

app.py
config.json
tokenizer.json
model.keras
requirements.txt
Dockerfile
.dockerignore

config.json provides max_length and the decision threshold. tokenizer.json rebuilds the original Keras tokenizer used during training.

Run locally

bash
pip install -r requirements.txt
python app.py   # or: uvicorn app:app --host 0.0.0.0 --port 7860

Docker (local)

bash
docker build -t ai-detector:cpu .
docker run -p 7860:7860 --rm ai-detector:cpu
# then: curl http://localhost:7860/health

Deploy to Hugging Face Spaces (Docker)

  1. 1.Create a new Space → Docker.
  2. 2.Upload the repo contents (including model.keras, tokenizer.json, config.json, Dockerfile, requirements.txt, app.py).
  3. 3.Push/Commit — the Space will build the container and run it.
  4. 4.The API will be reachable at https://<your-space>.hf.space (try /docs).

Notes:

  • —This build uses TensorFlow CPU 2.15 for compatibility with tokenizer_from_json and pad_sequences utilities.
  • —If your .keras file was saved with Keras 3 and the TF loader ever fails, switch to a Keras 3 loader inside app.py (see commented tips) and add keras==3.* to requirements.txt.

# Tips for switching to Keras 3 loader (only if needed)
# from keras.models import load_model as k_load_model
# _model = k_load_model(MODEL_PATH)