Deployment Guide - Two Options
You now have TWO deployment options for your model:
Option 1: Gradio Space (Current - Interactive UI)
URL: https://huggingface.co/spaces/chenhaoq87/MilkSpoilageClassifier-Demo
Features:
- β Interactive web interface
- β Visual inputs and outputs
- β No direct REST API for Custom GPT
Best for: Human users testing the model manually
Option 2: FastAPI Space (Recommended for Custom GPT)
Create a second Space with pure REST API:
Step 1: Create New Space
- Go to https://huggingface.co/new-space
- Name:
MilkSpoilageClassifier-API - SDK: Docker
- Click "Create Space"
Step 2: Upload Files
Upload these files to the new Space:
Files to upload:
apps/fastapi/app.pyβ upload asapp.pymodel/model.joblibβ upload asmodel.joblibapps/fastapi/Dockerfileβ upload asDockerfileapps/fastapi/requirements.txtβ upload asrequirements.txt
Dockerfile:
FROM python:3.10-slim
WORKDIR /app
# Copy files
COPY requirements.txt .
COPY app.py .
COPY model.joblib .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Expose port
EXPOSE 7860
# Run app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
requirements.txt:
fastapi>=0.100
uvicorn[standard]>=0.24
pydantic>=2.0
scikit-learn>=1.0
joblib>=1.0
numpy>=1.20
Step 3: Use with Custom GPT
Once the Space is running, your REST API will be at:
https://chenhaoq87-milkspoilageclassifier-api.hf.space/predict
OpenAPI Schema (see API_DOCUMENTATION.md)
Quick Command to Create FastAPI Space
Run this in PowerShell:
cd D:\HuggingFace\MilkSpoilageClassifier
# Upload to new Space
python -c "from huggingface_hub import HfApi, create_repo; api = HfApi(); create_repo('chenhaoq87/MilkSpoilageClassifier-API', repo_type='space', space_sdk='docker', exist_ok=True); api.upload_file('apps/fastapi/Dockerfile', 'Dockerfile', 'chenhaoq87/MilkSpoilageClassifier-API', repo_type='space'); api.upload_file('apps/fastapi/app.py', 'app.py', 'chenhaoq87/MilkSpoilageClassifier-API', repo_type='space'); api.upload_file('apps/fastapi/requirements.txt', 'requirements.txt', 'chenhaoq87/MilkSpoilageClassifier-API', repo_type='space'); api.upload_file('model/model.joblib', 'model.joblib', 'chenhaoq87/MilkSpoilageClassifier-API', repo_type='space'); print('FastAPI Space created!')"
Summary
| Feature | Gradio Space | FastAPI Space |
|---|---|---|
| Interactive UI | β | β |
| REST API | β | β |
| Custom GPT | β | β |
| Human Testing | β | β |
| API Docs | β | β (/docs) |
Recommendation: Keep both!
- Use Gradio Space for manual testing
- Use FastAPI Space for Custom GPT integration