Spaces:
Sleeping
Sleeping
Commit ·
5961cf0
1
Parent(s): adcc112
Add Dockerfile and deployment guide for Hugging Face Spaces
Browse files- Dockerfile +37 -0
- deployment_guide.md +41 -0
- src/main.py +8 -1
Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.10 slim as base for a smaller image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
ENV PORT=7860
|
| 8 |
+
|
| 9 |
+
# Set working directory
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
# Install system dependencies for OpenCV, MediaPipe, and C++ compilation
|
| 13 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 14 |
+
build-essential \
|
| 15 |
+
cmake \
|
| 16 |
+
libgl1-mesa-glx \
|
| 17 |
+
libglib2.0-0 \
|
| 18 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 19 |
+
|
| 20 |
+
# Copy requirements first for better caching
|
| 21 |
+
COPY requirements.txt .
|
| 22 |
+
|
| 23 |
+
# Install Python dependencies
|
| 24 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
+
|
| 26 |
+
# Copy the rest of the application
|
| 27 |
+
COPY . .
|
| 28 |
+
|
| 29 |
+
# Compile the C++ engagement module
|
| 30 |
+
RUN python setup.py build_ext --inplace
|
| 31 |
+
|
| 32 |
+
# Expose the port used by Hugging Face Spaces
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# Run the application with uvicorn
|
| 36 |
+
# We use 0.0.0.0 to allow external access and 7860 as the port
|
| 37 |
+
CMD ["python", "src/main.py"]
|
deployment_guide.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploying to Hugging Face Spaces (Option A)
|
| 2 |
+
|
| 3 |
+
Hugging Face Spaces is the best free option for FocusFlow because it supports Docker, allowing us to compile the C++ module in the cloud.
|
| 4 |
+
|
| 5 |
+
## Step 1: Create the Space
|
| 6 |
+
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces).
|
| 7 |
+
2. Click **"Create new Space"**.
|
| 8 |
+
3. Name your space (e.g., `FocusFlow`).
|
| 9 |
+
4. Select **Docker** as the SDK.
|
| 10 |
+
5. Choose **"Blank"** template.
|
| 11 |
+
6. Set visibility to **Public** or **Private**.
|
| 12 |
+
7. Click **Create Space**.
|
| 13 |
+
|
| 14 |
+
## Step 2: Push your code
|
| 15 |
+
Since your code is already on GitHub, you can either:
|
| 16 |
+
|
| 17 |
+
### Method A: Connect GitHub (Easiest)
|
| 18 |
+
1. On your new Space page, go to **Settings**.
|
| 19 |
+
2. Find the **"Connected GitHub Repository"** section.
|
| 20 |
+
3. Link your `kush-rc/FocusFlow` repository.
|
| 21 |
+
4. Hugging Face will automatically build and deploy whenever you push to GitHub.
|
| 22 |
+
|
| 23 |
+
### Method B: Manually Push via Git
|
| 24 |
+
1. Get the Git URL of your Space (ends in `.git`).
|
| 25 |
+
2. Add it as a new remote:
|
| 26 |
+
```bash
|
| 27 |
+
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/FocusFlow
|
| 28 |
+
```
|
| 29 |
+
3. Push to Hugging Face:
|
| 30 |
+
```bash
|
| 31 |
+
git push -f hf main
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Step 3: Monitoring the Build
|
| 35 |
+
- Once pushed, go to the **"Logs"** tab in your Space.
|
| 36 |
+
- You will see the Docker image building and the C++ module compiling.
|
| 37 |
+
- Once finished, the Status will change to **"Running"**.
|
| 38 |
+
|
| 39 |
+
## Important Notes
|
| 40 |
+
- **Port**: Hugging Face requires the app to listen on port `7860`. The `Dockerfile` and `main.py` are already configured for this.
|
| 41 |
+
- **Webcam**: Ensure your site is accessed via `https` (Hugging Face provides this automatically) so the browser allows camera access.
|
src/main.py
CHANGED
|
@@ -363,5 +363,12 @@ async def websocket_stream(websocket: WebSocket):
|
|
| 363 |
db.end_session(session_id)
|
| 364 |
|
| 365 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
# Disable reload because writing to the database triggers a server restart loop
|
| 367 |
-
uvicorn.run("src.main:app", host=
|
|
|
|
| 363 |
db.end_session(session_id)
|
| 364 |
|
| 365 |
if __name__ == "__main__":
|
| 366 |
+
import os
|
| 367 |
+
# Hugging Face Spaces and other cloud providers often use the PORT env var
|
| 368 |
+
port = int(os.environ.get("PORT", 8000))
|
| 369 |
+
# In a container/cloud, we must use 0.0.0.0
|
| 370 |
+
host = "0.0.0.0"
|
| 371 |
+
|
| 372 |
+
print(f"🚀 FocusFlow starting on http://{host}:{port}")
|
| 373 |
# Disable reload because writing to the database triggers a server restart loop
|
| 374 |
+
uvicorn.run("src.main:app", host=host, port=port, reload=False)
|