# SeqTypeAI — HuggingFace Spaces Deployment ## Repository layout ``` seqtypeai-spaces/ ├── app.py ← FastAPI backend (this session) ├── Dockerfile ├── requirements.txt ├── README.md ← HF Spaces metadata in front matter ├── static/ │ └── index.html ← Production frontend └── app/ ├── core/ │ └── feature_extractor.py ← copy from your local repo └── models/ ├── seqtype_classifier.joblib ├── label_encoder.joblib ├── feature_names.json ├── model_meta.json └── quality_norm.json ← optional ``` ## Steps ### 1. Copy your trained model artifacts After your HPC run completes: ```bash cp app/models/seqtype_classifier.joblib seqtypeai-spaces/app/models/ cp app/models/label_encoder.joblib seqtypeai-spaces/app/models/ cp app/models/feature_names.json seqtypeai-spaces/app/models/ cp app/models/model_meta.json seqtypeai-spaces/app/models/ cp app/core/feature_extractor.py seqtypeai-spaces/app/core/ ``` ### 2. Create a HuggingFace Space 1. Go to https://huggingface.co/new-space 2. Name: `seqtypeai` (or `cusanovich-lab/seqtypeai`) 3. SDK: **Docker** 4. Visibility: Public (for community) or Private (for lab use) 5. Click "Create Space" ### 3. Push the repository ```bash cd seqtypeai-spaces git init git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/seqtypeai git add . git commit -m "Initial SeqTypeAI deployment" git push origin main ``` HuggingFace will automatically build the Docker image and start the app. The URL will be: `https://YOUR_USERNAME-seqtypeai.hf.space` ### 4. Verify ```bash # Health check curl https://YOUR_USERNAME-seqtypeai.hf.space/health # Classify a FASTQ curl -X POST https://YOUR_USERNAME-seqtypeai.hf.space/classify \ -F "file=@sample.fastq.gz" | python -m json.tool ``` ## API reference ### POST /classify Upload a FASTQ file, receive ranked predictions. **Request:** `multipart/form-data` with `file` field **Response:** ```json { "filename": "sample.fastq.gz", "top_assay": "atac_seq", "top_label": "Bulk ATAC-seq", "confidence": 0.94, "predictions": [ {"assay": "atac_seq", "label": "Bulk ATAC-seq", "confidence": 0.94, "evidence": ""}, ... ], "features": { "rl_mean": 51.3, "gc_mean": 0.487, "tn5_start_approx": 0.534, ... }, "qc_checks": [ {"label": "Tn5 insertion bias", "status": "good", "value": 0.534, "desc": "..."}, ... ], "qc_overall": "good", "reasoning": "Top prediction is Bulk ATAC-seq (94% confidence). AT-rich read starts indicate Tn5 insertion bias.", "model_version": "1.0" } ``` ### GET /health Returns model load status, version, number of features and classes. ## Notes - The `/classify` endpoint uses your actual `HistGradientBoostingClassifier` model - If `feature_extractor.py` is present, the server uses it directly — identical features to training - If `feature_extractor.py` is missing, a lightweight fallback extractor runs (same features as the browser demo) - The chatbot in the production frontend calls the Anthropic API directly from the browser — no API key is stored server-side - HuggingFace free tier has a 16 GB RAM limit and 2 vCPU; the model loads in < 1 second and inference is fast (~50ms per file)