Spaces:
Running
Running
Commit ·
5bfd99b
1
Parent(s): 33cb1da
docs: add HuggingFace deployment lessons to LEARNINGS.md
Browse filesCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- docs/LEARNINGS.md +28 -0
docs/LEARNINGS.md
CHANGED
|
@@ -178,6 +178,34 @@ pytest tests/ --cov=protein_conformal --cov-report=html # With coverage
|
|
| 178 |
|
| 179 |
---
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
## Session History
|
| 182 |
|
| 183 |
### 2026-02-05 (Gradio branch)
|
|
|
|
| 178 |
|
| 179 |
---
|
| 180 |
|
| 181 |
+
## HuggingFace Spaces Deployment
|
| 182 |
+
|
| 183 |
+
### Key Lesson: Optional Imports
|
| 184 |
+
When deploying to HuggingFace Spaces, **wrap optional module imports in try/except**. The Space only installs what's in `requirements.txt`, so unused modules with extra dependencies will crash the app on import.
|
| 185 |
+
|
| 186 |
+
```python
|
| 187 |
+
# Bad - crashes if py3Dmol not installed
|
| 188 |
+
from .visualization import create_structure_with_heatmap
|
| 189 |
+
|
| 190 |
+
# Good - gracefully handles missing deps
|
| 191 |
+
try:
|
| 192 |
+
from .visualization import create_structure_with_heatmap
|
| 193 |
+
except ImportError:
|
| 194 |
+
create_structure_with_heatmap = None
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
### Requirements.txt Best Practices
|
| 198 |
+
1. Include ALL imports used by the main app path
|
| 199 |
+
2. Comment out optional deps with clear notes
|
| 200 |
+
3. Test locally with a fresh venv before pushing
|
| 201 |
+
|
| 202 |
+
### Dataset Integration
|
| 203 |
+
- Set `HF_DATASET_ID` env variable in Space settings
|
| 204 |
+
- Dataset structure must match paths in `app.py` `ensure_assets()`
|
| 205 |
+
- Files downloaded on first run, then cached
|
| 206 |
+
|
| 207 |
+
---
|
| 208 |
+
|
| 209 |
## Session History
|
| 210 |
|
| 211 |
### 2026-02-05 (Gradio branch)
|