Spaces:
Sleeping
Sleeping
Kasilanka Bhoopesh Siva Srikar
commited on
Commit
·
bae6e88
1
Parent(s):
08123aa
Update Dockerfile for Hugging Face Spaces deployment
Browse files- Use PORT environment variable (Hugging Face standard)
- Default to port 7860 (Hugging Face default)
- Include content directory for data file
- Add deployment documentation for Docker SDK
- DEPLOYMENT_STEPS.md +59 -0
- Dockerfile +9 -1
- HUGGINGFACE_DEPLOY_DOCKER.md +135 -0
- README_HUGGINGFACE.md +62 -0
DEPLOYMENT_STEPS.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚀 Hugging Face Spaces Deployment - Quick Steps
|
| 2 |
+
|
| 3 |
+
## ✅ Select Docker SDK
|
| 4 |
+
|
| 5 |
+
When creating your Hugging Face Space:
|
| 6 |
+
1. **SDK Options**: You'll see 3 options
|
| 7 |
+
- **Gradio** ❌ (for Gradio apps)
|
| 8 |
+
- **Docker** ✅ **SELECT THIS ONE!** (for Streamlit)
|
| 9 |
+
- **Static** ❌ (for static HTML)
|
| 10 |
+
|
| 11 |
+
2. **Select "Docker"** - This will use your Dockerfile automatically
|
| 12 |
+
|
| 13 |
+
## 📋 Deployment Steps
|
| 14 |
+
|
| 15 |
+
### Step 1: Create Space
|
| 16 |
+
1. Go to: https://huggingface.co/spaces
|
| 17 |
+
2. Click **"Create new Space"**
|
| 18 |
+
3. Fill in:
|
| 19 |
+
- **Space name**: `heart-attack-risk-predictor`
|
| 20 |
+
- **SDK**: **Docker** ✅
|
| 21 |
+
- **Visibility**: **Public**
|
| 22 |
+
- **Hardware**: **CPU basic** (free)
|
| 23 |
+
4. Click **"Create Space"**
|
| 24 |
+
|
| 25 |
+
### Step 2: Connect GitHub
|
| 26 |
+
1. Go to **"Settings"** tab in your space
|
| 27 |
+
2. Scroll to **"Repository"** section
|
| 28 |
+
3. Select **"GitHub"**
|
| 29 |
+
4. Repository: `KBSSRIKARVIT/heart-attack-risk-ensemble`
|
| 30 |
+
5. Branch: `main`
|
| 31 |
+
6. Click **"Save"**
|
| 32 |
+
|
| 33 |
+
### Step 3: Wait for Build
|
| 34 |
+
- Hugging Face will build your Docker image
|
| 35 |
+
- Takes 5-10 minutes (first time)
|
| 36 |
+
- Watch progress in **"Logs"** tab
|
| 37 |
+
|
| 38 |
+
### Step 4: Access Your App
|
| 39 |
+
Once built, your app is live at:
|
| 40 |
+
```
|
| 41 |
+
https://huggingface.co/spaces/KBSSRIKARVIT/heart-attack-risk-predictor
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
## ✅ What's Configured
|
| 45 |
+
|
| 46 |
+
- ✅ Dockerfile updated for Hugging Face (uses PORT env var)
|
| 47 |
+
- ✅ Port 7860 (Hugging Face standard)
|
| 48 |
+
- ✅ All model files included
|
| 49 |
+
- ✅ Content directory included
|
| 50 |
+
- ✅ All dependencies in requirements.txt
|
| 51 |
+
|
| 52 |
+
## 🎯 That's It!
|
| 53 |
+
|
| 54 |
+
Select **Docker SDK** and deploy! Your Streamlit app will run in the Docker container.
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
**Need help?** Check `HUGGINGFACE_DEPLOY_DOCKER.md` for detailed instructions.
|
| 59 |
+
|
Dockerfile
CHANGED
|
@@ -27,11 +27,19 @@ COPY .streamlit /app/.streamlit
|
|
| 27 |
RUN mkdir -p /app/model_assets
|
| 28 |
COPY model_assets/ /app/model_assets/
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Optional: copy test script for quick in-container verification
|
| 31 |
COPY test_predict.py /app/test_predict.py
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
EXPOSE 8051
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
|
|
|
|
| 27 |
RUN mkdir -p /app/model_assets
|
| 28 |
COPY model_assets/ /app/model_assets/
|
| 29 |
|
| 30 |
+
# Copy content directory (for data file used in feature encoding)
|
| 31 |
+
RUN mkdir -p /app/content
|
| 32 |
+
COPY content/ /app/content/
|
| 33 |
+
|
| 34 |
# Optional: copy test script for quick in-container verification
|
| 35 |
COPY test_predict.py /app/test_predict.py
|
| 36 |
|
| 37 |
+
# Hugging Face Spaces uses PORT environment variable or defaults to 7860
|
| 38 |
+
# Expose both ports for compatibility
|
| 39 |
+
EXPOSE 7860
|
| 40 |
EXPOSE 8051
|
| 41 |
|
| 42 |
+
# Use PORT environment variable if set, otherwise default to 7860 (Hugging Face standard)
|
| 43 |
+
CMD ["sh", "-c", "streamlit run streamlit_app.py --server.headless=true --server.address=0.0.0.0 --server.port=${PORT:-7860}"]
|
| 44 |
|
| 45 |
|
HUGGINGFACE_DEPLOY_DOCKER.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🐳 Deploy to Hugging Face Spaces Using Docker SDK
|
| 2 |
+
|
| 3 |
+
## ✅ Select Docker SDK
|
| 4 |
+
|
| 5 |
+
When creating your Hugging Face Space, select **"Docker"** as the SDK.
|
| 6 |
+
|
| 7 |
+
Hugging Face will automatically detect and use your `Dockerfile`.
|
| 8 |
+
|
| 9 |
+
## 🚀 Deployment Steps
|
| 10 |
+
|
| 11 |
+
### Step 1: Create New Space
|
| 12 |
+
|
| 13 |
+
1. Go to: https://huggingface.co/spaces
|
| 14 |
+
2. Click **"Create new Space"**
|
| 15 |
+
3. Fill in:
|
| 16 |
+
- **Space name**: `heart-attack-risk-predictor` (or your choice)
|
| 17 |
+
- **SDK**: Select **"Docker"** ✅
|
| 18 |
+
- **Visibility**: **Public** (required for free tier)
|
| 19 |
+
- **Hardware**: **CPU basic** (free tier)
|
| 20 |
+
- Click **"Create Space"**
|
| 21 |
+
|
| 22 |
+
### Step 2: Connect GitHub Repository
|
| 23 |
+
|
| 24 |
+
1. After creating the space, go to **"Settings"** tab
|
| 25 |
+
2. Scroll to **"Repository"** section
|
| 26 |
+
3. Select **"GitHub"** as source
|
| 27 |
+
4. **Repository**: `KBSSRIKARVIT/heart-attack-risk-ensemble`
|
| 28 |
+
5. **Branch**: `main`
|
| 29 |
+
6. Click **"Save"**
|
| 30 |
+
|
| 31 |
+
### Step 3: Verify Dockerfile
|
| 32 |
+
|
| 33 |
+
Hugging Face will automatically use your `Dockerfile`. Verify it's correct:
|
| 34 |
+
|
| 35 |
+
- ✅ Base image: `python:3.11-slim`
|
| 36 |
+
- ✅ Port: `8051` (Hugging Face will map this automatically)
|
| 37 |
+
- ✅ Streamlit command configured
|
| 38 |
+
- ✅ All dependencies in `requirements.txt`
|
| 39 |
+
|
| 40 |
+
### Step 4: Update Dockerfile for Hugging Face (if needed)
|
| 41 |
+
|
| 42 |
+
Hugging Face Spaces automatically:
|
| 43 |
+
- Maps port 8051 to the web interface
|
| 44 |
+
- Sets environment variables
|
| 45 |
+
- Handles HTTPS
|
| 46 |
+
|
| 47 |
+
Your current Dockerfile should work, but we may need a small adjustment for Hugging Face's port expectations.
|
| 48 |
+
|
| 49 |
+
### Step 5: Wait for Build
|
| 50 |
+
|
| 51 |
+
1. Hugging Face will:
|
| 52 |
+
- Pull your code from GitHub
|
| 53 |
+
- Build the Docker image
|
| 54 |
+
- Deploy the container
|
| 55 |
+
2. **Build time**: 5-10 minutes (first time)
|
| 56 |
+
3. Watch progress in **"Logs"** tab
|
| 57 |
+
|
| 58 |
+
### Step 6: Access Your App
|
| 59 |
+
|
| 60 |
+
Once built, your app will be live at:
|
| 61 |
+
```
|
| 62 |
+
https://huggingface.co/spaces/KBSSRIKARVIT/heart-attack-risk-predictor
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## 🔧 Dockerfile Configuration for Hugging Face
|
| 66 |
+
|
| 67 |
+
Hugging Face Spaces expects the app to:
|
| 68 |
+
- Listen on the port specified in `PORT` environment variable
|
| 69 |
+
- Or use port 7860 (default)
|
| 70 |
+
|
| 71 |
+
Let's check if we need to update the Dockerfile:
|
| 72 |
+
|
| 73 |
+
```dockerfile
|
| 74 |
+
# Current Dockerfile uses port 8051
|
| 75 |
+
# Hugging Face can map this, but let's make it flexible
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## 📝 Optional: Update Dockerfile for Hugging Face
|
| 79 |
+
|
| 80 |
+
If the app doesn't start, we may need to update the Dockerfile to use Hugging Face's expected port:
|
| 81 |
+
|
| 82 |
+
```dockerfile
|
| 83 |
+
# Use PORT environment variable or default to 7860
|
| 84 |
+
CMD ["sh", "-c", "streamlit run streamlit_app.py --server.headless=true --server.address=0.0.0.0 --server.port=${PORT:-7860}"]
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
But first, let's try with the current Dockerfile - Hugging Face should handle the port mapping.
|
| 88 |
+
|
| 89 |
+
## ✅ Verification Checklist
|
| 90 |
+
|
| 91 |
+
After deployment:
|
| 92 |
+
|
| 93 |
+
- [ ] Build completes without errors
|
| 94 |
+
- [ ] App loads at the Hugging Face URL
|
| 95 |
+
- [ ] Streamlit interface displays correctly
|
| 96 |
+
- [ ] Models load successfully
|
| 97 |
+
- [ ] Predictions work
|
| 98 |
+
|
| 99 |
+
## 🐛 Troubleshooting
|
| 100 |
+
|
| 101 |
+
### Build Fails
|
| 102 |
+
|
| 103 |
+
**Check logs** for specific errors:
|
| 104 |
+
- Dependency installation issues
|
| 105 |
+
- Dockerfile syntax errors
|
| 106 |
+
- Port configuration issues
|
| 107 |
+
|
| 108 |
+
### App Doesn't Start
|
| 109 |
+
|
| 110 |
+
**Possible issues**:
|
| 111 |
+
- Port mismatch (Hugging Face expects 7860 or PORT env var)
|
| 112 |
+
- Missing model files
|
| 113 |
+
- Path issues
|
| 114 |
+
|
| 115 |
+
**Solution**: Update Dockerfile to use `PORT` environment variable.
|
| 116 |
+
|
| 117 |
+
### Models Not Loading
|
| 118 |
+
|
| 119 |
+
**Verify**:
|
| 120 |
+
- Model files are in the repository
|
| 121 |
+
- Paths in `streamlit_app.py` are correct
|
| 122 |
+
- Files are copied in Dockerfile
|
| 123 |
+
|
| 124 |
+
## 🎯 Summary
|
| 125 |
+
|
| 126 |
+
1. **Select "Docker" SDK** when creating the space
|
| 127 |
+
2. **Connect GitHub repository**
|
| 128 |
+
3. **Hugging Face uses your Dockerfile automatically**
|
| 129 |
+
4. **Wait for build** (5-10 minutes)
|
| 130 |
+
5. **Access your app** at the Hugging Face URL
|
| 131 |
+
|
| 132 |
+
---
|
| 133 |
+
|
| 134 |
+
**Ready to deploy?** Follow these steps and your Streamlit app will be live on Hugging Face Spaces! 🚀
|
| 135 |
+
|
README_HUGGINGFACE.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚀 Hugging Face Spaces Deployment
|
| 2 |
+
|
| 3 |
+
## Quick Start
|
| 4 |
+
|
| 5 |
+
1. **Go to**: https://huggingface.co/spaces
|
| 6 |
+
2. **Click**: "Create new Space"
|
| 7 |
+
3. **Select**: **Docker** SDK ✅
|
| 8 |
+
4. **Connect**: Your GitHub repository `KBSSRIKARVIT/heart-attack-risk-ensemble`
|
| 9 |
+
5. **Wait**: 5-10 minutes for build
|
| 10 |
+
6. **Done**: Your app is live!
|
| 11 |
+
|
| 12 |
+
## SDK Selection
|
| 13 |
+
|
| 14 |
+
When creating the space, you'll see three options:
|
| 15 |
+
|
| 16 |
+
1. **Gradio** - For Gradio apps (not this one)
|
| 17 |
+
2. **Docker** - ✅ **Select this one!** (for Streamlit)
|
| 18 |
+
3. **Static** - For static HTML sites (not this one)
|
| 19 |
+
|
| 20 |
+
## Why Docker?
|
| 21 |
+
|
| 22 |
+
- ✅ Your app is a Streamlit app
|
| 23 |
+
- ✅ You have a `Dockerfile` ready
|
| 24 |
+
- ✅ Docker SDK supports Streamlit
|
| 25 |
+
- ✅ More control over the environment
|
| 26 |
+
|
| 27 |
+
## What Happens
|
| 28 |
+
|
| 29 |
+
1. Hugging Face pulls your code from GitHub
|
| 30 |
+
2. Builds Docker image using your `Dockerfile`
|
| 31 |
+
3. Runs the container with Streamlit
|
| 32 |
+
4. Maps port 7860 to web interface
|
| 33 |
+
5. Your app is accessible worldwide!
|
| 34 |
+
|
| 35 |
+
## Files Needed
|
| 36 |
+
|
| 37 |
+
- ✅ `Dockerfile` - Container configuration
|
| 38 |
+
- ✅ `streamlit_app.py` - Main app
|
| 39 |
+
- ✅ `requirements.txt` - Dependencies
|
| 40 |
+
- ✅ `model_assets/` - Model files
|
| 41 |
+
- ✅ All other app files
|
| 42 |
+
|
| 43 |
+
## Port Configuration
|
| 44 |
+
|
| 45 |
+
The Dockerfile is configured to:
|
| 46 |
+
- Use `PORT` environment variable (set by Hugging Face)
|
| 47 |
+
- Default to port 7860 (Hugging Face standard)
|
| 48 |
+
- Also expose port 8051 for compatibility
|
| 49 |
+
|
| 50 |
+
## After Deployment
|
| 51 |
+
|
| 52 |
+
Your app will be available at:
|
| 53 |
+
```
|
| 54 |
+
https://huggingface.co/spaces/KBSSRIKARVIT/heart-attack-risk-predictor
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Replace `KBSSRIKARVIT` with your Hugging Face username and `heart-attack-risk-predictor` with your space name.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
**That's it!** Select Docker SDK and deploy! 🎉
|
| 62 |
+
|