Damanger/ai-vs-human
1
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 probePOST /predict— body:{"text": "..."}POST /predict-batch— body:{"texts": ["...", "..."]}
Sample:
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
.dockerignoreconfig.json provides max_length and the decision threshold. tokenizer.json rebuilds the original Keras tokenizer used during training.
Run locally
pip install -r requirements.txt
python app.py # or: uvicorn app:app --host 0.0.0.0 --port 7860Docker (local)
docker build -t ai-detector:cpu .
docker run -p 7860:7860 --rm ai-detector:cpu
# then: curl http://localhost:7860/healthDeploy to Hugging Face Spaces (Docker)
- Create a new Space → Docker.
- Upload the repo contents (including
model.keras,tokenizer.json,config.json,Dockerfile,requirements.txt,app.py). - Push/Commit — the Space will build the container and run it.
- 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_jsonandpad_sequencesutilities. - If your
.kerasfile was saved with Keras 3 and the TF loader ever fails, switch to a Keras 3 loader insideapp.py(see commented tips) and addkeras==3.*torequirements.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)