Spaces:
Sleeping
Sleeping
Remove Open3D dependencies and simplify for HF Spaces deployment - Use trimesh-only mode with FORCE_TRIMESH flag - Remove OpenGL system dependencies - Simplify requirements.txt and Dockerfile
Browse files- Dockerfile +4 -22
- models/depth_processor.py +23 -14
- packages.txt +1 -13
- requirements.txt +1 -2
Dockerfile
CHANGED
|
@@ -2,24 +2,9 @@ FROM python:3.9-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
git \
|
| 8 |
-
libgl1-mesa-glx \
|
| 9 |
-
libglib2.0-0 \
|
| 10 |
-
libsm6 \
|
| 11 |
-
libxext6 \
|
| 12 |
-
libxrender-dev \
|
| 13 |
-
libgomp1 \
|
| 14 |
-
libglu1-mesa \
|
| 15 |
-
libegl1-mesa \
|
| 16 |
-
libxrandr2 \
|
| 17 |
-
libxss1 \
|
| 18 |
-
libxcursor1 \
|
| 19 |
-
libxcomposite1 \
|
| 20 |
-
libasound2 \
|
| 21 |
-
libxi6 \
|
| 22 |
-
libxtst6 \
|
| 23 |
&& rm -rf /var/lib/apt/lists/*
|
| 24 |
|
| 25 |
# Copy requirements and install Python dependencies
|
|
@@ -29,18 +14,15 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 29 |
# Copy application code
|
| 30 |
COPY . .
|
| 31 |
|
| 32 |
-
# Set environment variables for API-based image generation and
|
| 33 |
ENV HF_HOME=/tmp/huggingface
|
| 34 |
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
|
| 35 |
ENV HF_DATASETS_CACHE=/tmp/huggingface_datasets
|
| 36 |
ENV TORCH_HOME=/tmp/torch
|
| 37 |
ENV HUGGINGFACE_API_TOKEN=""
|
| 38 |
-
ENV
|
| 39 |
-
ENV OPEN3D_ML_ROOT=""
|
| 40 |
-
ENV MESA_GL_VERSION_OVERRIDE=3.3
|
| 41 |
|
| 42 |
-
# Note:
|
| 43 |
-
# This avoids build-time resource constraints and allows for proper authentication
|
| 44 |
|
| 45 |
EXPOSE 7860
|
| 46 |
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install git only - removing OpenGL dependencies to avoid build issues
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
git \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
# Copy requirements and install Python dependencies
|
|
|
|
| 14 |
# Copy application code
|
| 15 |
COPY . .
|
| 16 |
|
| 17 |
+
# Set environment variables for API-based image generation and trimesh-only operation
|
| 18 |
ENV HF_HOME=/tmp/huggingface
|
| 19 |
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
|
| 20 |
ENV HF_DATASETS_CACHE=/tmp/huggingface_datasets
|
| 21 |
ENV TORCH_HOME=/tmp/torch
|
| 22 |
ENV HUGGINGFACE_API_TOKEN=""
|
| 23 |
+
ENV FORCE_TRIMESH=1
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# Note: Using trimesh-only mode for reliable deployment without OpenGL dependencies
|
|
|
|
| 26 |
|
| 27 |
EXPOSE 7860
|
| 28 |
|
models/depth_processor.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Depth processing module for converting 2D images to depth maps and 3D models
|
| 3 |
-
Using
|
| 4 |
"""
|
| 5 |
|
| 6 |
import os
|
|
@@ -12,23 +12,32 @@ from PIL import Image
|
|
| 12 |
from transformers import DPTImageProcessor, DPTForDepthEstimation
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
os.
|
| 17 |
-
os.environ['DISPLAY'] = ''
|
| 18 |
|
| 19 |
-
|
| 20 |
-
import open3d as o3d
|
| 21 |
-
# Force headless mode for Open3D
|
| 22 |
-
if hasattr(o3d.visualization, 'gui'):
|
| 23 |
-
o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Error)
|
| 24 |
logger = logging.getLogger(__name__)
|
| 25 |
-
logger.info("
|
| 26 |
-
OPEN3D_AVAILABLE = True
|
| 27 |
-
except ImportError as e:
|
| 28 |
-
logger = logging.getLogger(__name__)
|
| 29 |
-
logger.warning(f"⚠️ Open3D not available: {str(e)}, falling back to trimesh")
|
| 30 |
OPEN3D_AVAILABLE = False
|
| 31 |
import trimesh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
logger = logging.getLogger(__name__)
|
| 34 |
|
|
|
|
| 1 |
"""
|
| 2 |
Depth processing module for converting 2D images to depth maps and 3D models
|
| 3 |
+
Using trimesh for reliable deployment
|
| 4 |
"""
|
| 5 |
|
| 6 |
import os
|
|
|
|
| 12 |
from transformers import DPTImageProcessor, DPTForDepthEstimation
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
|
| 15 |
+
# Check if we should force trimesh-only mode
|
| 16 |
+
FORCE_TRIMESH = os.getenv('FORCE_TRIMESH', '').lower() in ('1', 'true', 'yes')
|
|
|
|
| 17 |
|
| 18 |
+
if FORCE_TRIMESH:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
+
logger.info("🔧 FORCE_TRIMESH enabled - using trimesh-only mode for reliable deployment")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
OPEN3D_AVAILABLE = False
|
| 22 |
import trimesh
|
| 23 |
+
else:
|
| 24 |
+
# Configure Open3D for headless mode (HuggingFace Spaces compatibility)
|
| 25 |
+
os.environ['OPEN3D_ML_ROOT'] = ''
|
| 26 |
+
os.environ['DISPLAY'] = ''
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
import open3d as o3d
|
| 30 |
+
# Force headless mode for Open3D
|
| 31 |
+
if hasattr(o3d.visualization, 'gui'):
|
| 32 |
+
o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Error)
|
| 33 |
+
logger = logging.getLogger(__name__)
|
| 34 |
+
logger.info("✅ Open3D loaded successfully in headless mode")
|
| 35 |
+
OPEN3D_AVAILABLE = True
|
| 36 |
+
except ImportError as e:
|
| 37 |
+
logger = logging.getLogger(__name__)
|
| 38 |
+
logger.warning(f"⚠️ Open3D not available: {str(e)}, falling back to trimesh")
|
| 39 |
+
OPEN3D_AVAILABLE = False
|
| 40 |
+
import trimesh
|
| 41 |
|
| 42 |
logger = logging.getLogger(__name__)
|
| 43 |
|
packages.txt
CHANGED
|
@@ -1,15 +1,3 @@
|
|
| 1 |
libgl1-mesa-glx
|
| 2 |
libglib2.0-0
|
| 3 |
-
|
| 4 |
-
libxext6
|
| 5 |
-
libxrender-dev
|
| 6 |
-
libgomp1
|
| 7 |
-
libglu1-mesa
|
| 8 |
-
libegl1-mesa
|
| 9 |
-
libxrandr2
|
| 10 |
-
libxss1
|
| 11 |
-
libxcursor1
|
| 12 |
-
libxcomposite1
|
| 13 |
-
libasound2
|
| 14 |
-
libxi6
|
| 15 |
-
libxtst6
|
|
|
|
| 1 |
libgl1-mesa-glx
|
| 2 |
libglib2.0-0
|
| 3 |
+
libgomp1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -12,5 +12,4 @@ python-dotenv==1.0.0
|
|
| 12 |
requests==2.31.0
|
| 13 |
trimesh==4.0.5
|
| 14 |
scipy==1.11.4
|
| 15 |
-
huggingface_hub==0.19.4
|
| 16 |
-
open3d==0.18.0
|
|
|
|
| 12 |
requests==2.31.0
|
| 13 |
trimesh==4.0.5
|
| 14 |
scipy==1.11.4
|
| 15 |
+
huggingface_hub==0.19.4
|
|
|