Spaces:
Sleeping
Sleeping
File size: 3,427 Bytes
7edc0cc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | # 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)
|