Commit Β·
37195d8
1
Parent(s): 3454374
d1
Browse files- .dockerignore +10 -21
- DEPLOYMENT_FIX.md +99 -0
- Dockerfile +5 -3
- requirements.txt +4 -1
.dockerignore
CHANGED
|
@@ -3,27 +3,16 @@ __pycache__
|
|
| 3 |
*.pyo
|
| 4 |
*.pyd
|
| 5 |
.Python
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
venv/
|
| 8 |
-
|
| 9 |
-
pip-delete-this-directory.txt
|
| 10 |
-
.tox/
|
| 11 |
-
.coverage
|
| 12 |
-
.coverage.*
|
| 13 |
-
.cache
|
| 14 |
-
nosetests.xml
|
| 15 |
-
coverage.xml
|
| 16 |
-
*.cover
|
| 17 |
-
*.log
|
| 18 |
.git
|
| 19 |
.gitignore
|
| 20 |
-
.
|
| 21 |
-
.
|
| 22 |
-
.hypothesis
|
| 23 |
-
*.egg-info/
|
| 24 |
-
dist/
|
| 25 |
-
build/
|
| 26 |
-
*.egg
|
| 27 |
-
data/*.html
|
| 28 |
-
data/recognition_log.csv
|
| 29 |
-
app.py
|
|
|
|
| 3 |
*.pyo
|
| 4 |
*.pyd
|
| 5 |
.Python
|
| 6 |
+
*.so
|
| 7 |
+
*.egg
|
| 8 |
+
*.egg-info
|
| 9 |
+
dist
|
| 10 |
+
build
|
| 11 |
+
.env
|
| 12 |
+
.venv
|
| 13 |
venv/
|
| 14 |
+
ENV/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
.git
|
| 16 |
.gitignore
|
| 17 |
+
*.md
|
| 18 |
+
.DS_Store
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEPLOYMENT_FIX.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deployment Fix Summary
|
| 2 |
+
|
| 3 |
+
## Problem
|
| 4 |
+
Your Hugging Face Space deployment failed due to dependency resolution conflicts, specifically:
|
| 5 |
+
- PyYAML 5.4.1 build failure
|
| 6 |
+
- Incompatible version constraints between packages (uvicorn, httpx, supabase, etc.)
|
| 7 |
+
- Missing build dependencies in Docker image
|
| 8 |
+
|
| 9 |
+
## Changes Made
|
| 10 |
+
|
| 11 |
+
### 1. Updated `requirements.txt`
|
| 12 |
+
**Key Changes:**
|
| 13 |
+
- β
Updated `uvicorn[standard]` from 0.27.0 to 0.27.1
|
| 14 |
+
- β
Added explicit `torchvision==0.16.2` (compatible with torch 2.1.2)
|
| 15 |
+
- β
Added `pyyaml>=6.0` to force newer version (avoids build errors)
|
| 16 |
+
- β
Added `httpx>=0.24.0,<0.26.0` to constrain supabase dependency
|
| 17 |
+
|
| 18 |
+
**Why:** The supabase package requires `httpx<0.26`, but newer versions of other packages were pulling in incompatible httpx versions, causing pip's dependency resolver to backtrack endlessly.
|
| 19 |
+
|
| 20 |
+
### 2. Updated `Dockerfile`
|
| 21 |
+
**Key Changes:**
|
| 22 |
+
- β
Added `build-essential` package (provides gcc, make, etc.)
|
| 23 |
+
- β
Upgraded pip, setuptools, and wheel before installing dependencies
|
| 24 |
+
- β
Combined RUN commands for better layer caching
|
| 25 |
+
|
| 26 |
+
**Why:** Some Python packages need C compilers to build. The newer pip also has better dependency resolution.
|
| 27 |
+
|
| 28 |
+
### 3. Created `.dockerignore`
|
| 29 |
+
**Purpose:** Excludes unnecessary files from Docker build context, making builds faster and smaller.
|
| 30 |
+
|
| 31 |
+
## Next Steps
|
| 32 |
+
|
| 33 |
+
### Deploy to Hugging Face Space
|
| 34 |
+
|
| 35 |
+
1. **Commit and push your changes:**
|
| 36 |
+
```bash
|
| 37 |
+
cd greenai
|
| 38 |
+
git add requirements.txt Dockerfile .dockerignore
|
| 39 |
+
git commit -m "Fix dependency conflicts and Docker build"
|
| 40 |
+
git push
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
2. **If not using Git, manually upload:**
|
| 44 |
+
- Go to your Space on Hugging Face
|
| 45 |
+
- Upload the updated files via the web interface
|
| 46 |
+
|
| 47 |
+
3. **Set Environment Variables (if needed):**
|
| 48 |
+
- Go to your Space Settings β Variables and secrets
|
| 49 |
+
- Add:
|
| 50 |
+
- `OPENROUTER_API_KEY` (for VLM fallback)
|
| 51 |
+
- `PLANTNET_API_KEY` (for plant identification)
|
| 52 |
+
- `SUPABASE_URL` (if using Supabase)
|
| 53 |
+
- `SUPABASE_KEY` (if using Supabase)
|
| 54 |
+
|
| 55 |
+
4. **Monitor the build:**
|
| 56 |
+
- Watch the build logs in your Space
|
| 57 |
+
- The build should now complete successfully
|
| 58 |
+
|
| 59 |
+
## Alternative: Test Locally First
|
| 60 |
+
|
| 61 |
+
Before deploying, you can test the Docker build locally:
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
cd greenai
|
| 65 |
+
docker build -t greenai-test .
|
| 66 |
+
docker run -p 7860:7860 greenai-test
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
Then visit http://localhost:7860 to test the API.
|
| 70 |
+
|
| 71 |
+
## If Issues Persist
|
| 72 |
+
|
| 73 |
+
If you still encounter problems, try this minimal requirements.txt:
|
| 74 |
+
|
| 75 |
+
```
|
| 76 |
+
fastapi==0.109.0
|
| 77 |
+
uvicorn==0.27.1
|
| 78 |
+
python-multipart==0.0.9
|
| 79 |
+
pandas==2.1.4
|
| 80 |
+
pillow==10.2.0
|
| 81 |
+
torch==2.1.2
|
| 82 |
+
torchvision==0.16.2
|
| 83 |
+
open-clip-torch==2.24.0
|
| 84 |
+
python-dotenv==1.0.1
|
| 85 |
+
requests==2.31.0
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
And install supabase separately if needed, or use the supabase REST API directly via requests.
|
| 89 |
+
|
| 90 |
+
## Expected Build Time
|
| 91 |
+
- First build: 5-10 minutes (downloading PyTorch and dependencies)
|
| 92 |
+
- Subsequent builds: 1-2 minutes (cached layers)
|
| 93 |
+
|
| 94 |
+
## Verification
|
| 95 |
+
Once deployed, test these endpoints:
|
| 96 |
+
- `GET /` - API info
|
| 97 |
+
- `GET /health` - Health check
|
| 98 |
+
- `GET /docs` - Swagger documentation
|
| 99 |
+
- `POST /recognize` - Upload test image
|
Dockerfile
CHANGED
|
@@ -2,16 +2,18 @@ FROM python:3.10-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
git \
|
|
|
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
# Copy requirements first for better caching
|
| 11 |
COPY requirements.txt .
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
RUN pip install --
|
|
|
|
| 15 |
|
| 16 |
# Copy application files
|
| 17 |
COPY api.py .
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install system dependencies including build tools
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
git \
|
| 8 |
+
build-essential \
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
# Copy requirements first for better caching
|
| 12 |
COPY requirements.txt .
|
| 13 |
|
| 14 |
+
# Upgrade pip and install Python dependencies
|
| 15 |
+
RUN pip install --upgrade pip setuptools wheel && \
|
| 16 |
+
pip install --no-cache-dir -r requirements.txt
|
| 17 |
|
| 18 |
# Copy application files
|
| 19 |
COPY api.py .
|
requirements.txt
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
fastapi==0.109.0
|
| 2 |
-
uvicorn[standard]==0.27.
|
| 3 |
python-multipart==0.0.9
|
| 4 |
pandas==2.1.4
|
| 5 |
pillow==10.2.0
|
| 6 |
torch==2.1.2
|
|
|
|
| 7 |
open-clip-torch==2.24.0
|
| 8 |
python-dotenv==1.0.1
|
| 9 |
requests==2.31.0
|
| 10 |
supabase==2.3.4
|
|
|
|
|
|
|
|
|
| 1 |
fastapi==0.109.0
|
| 2 |
+
uvicorn[standard]==0.27.1
|
| 3 |
python-multipart==0.0.9
|
| 4 |
pandas==2.1.4
|
| 5 |
pillow==10.2.0
|
| 6 |
torch==2.1.2
|
| 7 |
+
torchvision==0.16.2
|
| 8 |
open-clip-torch==2.24.0
|
| 9 |
python-dotenv==1.0.1
|
| 10 |
requests==2.31.0
|
| 11 |
supabase==2.3.4
|
| 12 |
+
pyyaml>=6.0
|
| 13 |
+
httpx>=0.24.0,<0.26.0
|