Spaces:
Running
on
Zero
Adopt working configuration from ronedgecomb/ml-sharp Space
Browse filesMajor changes based on successful implementation:
1. Python 3.13.11 Support:
- Add python_version: 3.13.11 to README.md
- Update Dockerfile to use Python 3.13
- ml-sharp now compatible with HF Spaces
2. Updated Dependencies:
- Gradio: 5.9.1 -> 6.2.0
- Spaces: (unversioned) -> 0.44.0
- SHARP: specific commit (cdb4ddc) for stability
- Simplified requirements (removed unused deps)
3. Space Configuration:
- Add startup_duration_timeout: 1h for model download
- Add preload_from_hub for apple/Sharp checkpoint
- Add models section referencing apple/Sharp
- Add short_description
4. ZeroGPU Implementation:
- Fix spaces.GPU decorator usage (module-level function)
- Increase GPU duration: 60s -> 180s
- Avoid pickling issues with proper function wrapping
- Add detailed comments on ZeroGPU multiprocessing
5. Code Improvements:
- Rename process_image to _process_image_impl
- Apply decorator at module level: spaces.GPU(duration=180)
- Better model initialization in GPU worker
- Enhanced logging for debugging
This implementation is based on the working example at:
https://huggingface.co/spaces/ronedgecomb/ml-sharp
All changes ensure compatibility with ZeroGPU and Python 3.13.
- Dockerfile +7 -7
- README.md +17 -11
- app.py +13 -3
- requirements.txt +9 -21
|
@@ -10,7 +10,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
|
|
| 10 |
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 11 |
GRADIO_SERVER_PORT=7860
|
| 12 |
|
| 13 |
-
# システムパッケージの更新とPython 3.
|
| 14 |
RUN apt-get update && apt-get install -y \
|
| 15 |
software-properties-common \
|
| 16 |
wget \
|
|
@@ -18,15 +18,15 @@ RUN apt-get update && apt-get install -y \
|
|
| 18 |
&& add-apt-repository ppa:deadsnakes/ppa \
|
| 19 |
&& apt-get update \
|
| 20 |
&& apt-get install -y \
|
| 21 |
-
python3.
|
| 22 |
-
python3.
|
| 23 |
-
python3.
|
| 24 |
python3-pip \
|
| 25 |
&& rm -rf /var/lib/apt/lists/*
|
| 26 |
|
| 27 |
-
# Python 3.
|
| 28 |
-
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.
|
| 29 |
-
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.
|
| 30 |
|
| 31 |
# pipのアップグレード
|
| 32 |
RUN python3 -m pip install --upgrade pip setuptools wheel
|
|
|
|
| 10 |
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 11 |
GRADIO_SERVER_PORT=7860
|
| 12 |
|
| 13 |
+
# システムパッケージの更新とPython 3.13のインストール
|
| 14 |
RUN apt-get update && apt-get install -y \
|
| 15 |
software-properties-common \
|
| 16 |
wget \
|
|
|
|
| 18 |
&& add-apt-repository ppa:deadsnakes/ppa \
|
| 19 |
&& apt-get update \
|
| 20 |
&& apt-get install -y \
|
| 21 |
+
python3.13 \
|
| 22 |
+
python3.13-dev \
|
| 23 |
+
python3.13-venv \
|
| 24 |
python3-pip \
|
| 25 |
&& rm -rf /var/lib/apt/lists/*
|
| 26 |
|
| 27 |
+
# Python 3.13をデフォルトに設定
|
| 28 |
+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.13 1 \
|
| 29 |
+
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.13 1
|
| 30 |
|
| 31 |
# pipのアップグレード
|
| 32 |
RUN python3 -m pip install --upgrade pip setuptools wheel
|
|
@@ -4,10 +4,17 @@ emoji: 🎨
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
tags:
|
| 12 |
- 3d
|
| 13 |
- gaussian-splatting
|
|
@@ -15,7 +22,6 @@ tags:
|
|
| 15 |
- apple
|
| 16 |
- sharp
|
| 17 |
- three.js
|
| 18 |
-
- zerogpu
|
| 19 |
---
|
| 20 |
|
| 21 |
# 🎨 SHARP: 3D Gaussian Splats Generator
|
|
@@ -75,18 +81,18 @@ PLYファイルをダウンロードして、Blender、CloudCompare、MeshLabな
|
|
| 75 |
|
| 76 |
### フレームワーク
|
| 77 |
- **モデル**: Apple SHARP
|
| 78 |
-
- **UI**: Gradio
|
| 79 |
- **3Dレンダリング**: Three.js + PLYLoader
|
| 80 |
-
- **GPU**: ZeroGPU (
|
| 81 |
-
- **SDK**: Gradio SDK
|
| 82 |
-
- **言語**: Python 3.
|
| 83 |
|
| 84 |
### 主要ライブラリ
|
| 85 |
```
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
```
|
| 91 |
|
| 92 |
---
|
|
@@ -117,7 +123,7 @@ spaces (ZeroGPU)
|
|
| 117 |
## 🌐 ローカル実行
|
| 118 |
|
| 119 |
### 前提条件
|
| 120 |
-
- Python 3.
|
| 121 |
- CUDA 12.4+ (GPU使用の場合)
|
| 122 |
- 8GB以上のVRAM推奨
|
| 123 |
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.2.0
|
| 8 |
+
python_version: 3.13.11
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
| 12 |
+
short_description: Sharp Monocular View Synthesis - Generate 3D Gaussian Splats from a single image
|
| 13 |
+
models:
|
| 14 |
+
- apple/Sharp
|
| 15 |
+
startup_duration_timeout: 1h
|
| 16 |
+
preload_from_hub:
|
| 17 |
+
- apple/Sharp sharp_2572gikvuh.pt
|
| 18 |
tags:
|
| 19 |
- 3d
|
| 20 |
- gaussian-splatting
|
|
|
|
| 22 |
- apple
|
| 23 |
- sharp
|
| 24 |
- three.js
|
|
|
|
| 25 |
---
|
| 26 |
|
| 27 |
# 🎨 SHARP: 3D Gaussian Splats Generator
|
|
|
|
| 81 |
|
| 82 |
### フレームワーク
|
| 83 |
- **モデル**: Apple SHARP
|
| 84 |
+
- **UI**: Gradio 6.2.0
|
| 85 |
- **3Dレンダリング**: Three.js + PLYLoader
|
| 86 |
+
- **GPU**: ZeroGPU (Spaces 0.44.0)
|
| 87 |
+
- **SDK**: Gradio SDK
|
| 88 |
+
- **言語**: Python 3.13.11
|
| 89 |
|
| 90 |
### 主要ライブラリ
|
| 91 |
```
|
| 92 |
+
gradio==6.2.0
|
| 93 |
+
spaces==0.44.0
|
| 94 |
+
torch (latest)
|
| 95 |
+
sharp @ git+https://github.com/apple/ml-sharp.git
|
| 96 |
```
|
| 97 |
|
| 98 |
---
|
|
|
|
| 123 |
## 🌐 ローカル実行
|
| 124 |
|
| 125 |
### 前提条件
|
| 126 |
+
- Python 3.13+ (ml-sharpの要件)
|
| 127 |
- CUDA 12.4+ (GPU使用の場合)
|
| 128 |
- 8GB以上のVRAM推奨
|
| 129 |
|
|
@@ -28,17 +28,23 @@ except Exception as e:
|
|
| 28 |
traceback.print_exc()
|
| 29 |
|
| 30 |
# グローバルモデルインスタンス (メモリ効率のため)
|
|
|
|
| 31 |
_model = None
|
| 32 |
|
| 33 |
def get_model():
|
| 34 |
-
"""モデルインスタンスを取得(キャッシング)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
global _model
|
| 36 |
if _model is None and SHARP_AVAILABLE:
|
|
|
|
| 37 |
_model = Sharp()
|
|
|
|
| 38 |
return _model
|
| 39 |
|
| 40 |
-
|
| 41 |
-
def process_image(image) -> tuple[Optional[str], str, str]:
|
| 42 |
"""
|
| 43 |
画像から3D Gaussian Splatsを生成
|
| 44 |
|
|
@@ -105,6 +111,10 @@ def process_image(image) -> tuple[Optional[str], str, str]:
|
|
| 105 |
print(error_msg)
|
| 106 |
return None, error_msg, ""
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
# Three.js ビューアのHTMLテンプレート
|
| 109 |
def create_viewer_html(ply_base64: str) -> str:
|
| 110 |
"""Three.js + GaussianSplats3D ビューアのHTMLを生成"""
|
|
|
|
| 28 |
traceback.print_exc()
|
| 29 |
|
| 30 |
# グローバルモデルインスタンス (メモリ効率のため)
|
| 31 |
+
# 注意: ZeroGPUのマルチプロセッシングに対応するため、モジュールレベルで管理
|
| 32 |
_model = None
|
| 33 |
|
| 34 |
def get_model():
|
| 35 |
+
"""モデルインスタンスを取得(キャッシング)
|
| 36 |
+
|
| 37 |
+
GPU workerプロセス内でモデルを初期化してキャッシュします。
|
| 38 |
+
これによりpickling問題を回避します。
|
| 39 |
+
"""
|
| 40 |
global _model
|
| 41 |
if _model is None and SHARP_AVAILABLE:
|
| 42 |
+
print("🔄 Initializing SHARP model in GPU worker...")
|
| 43 |
_model = Sharp()
|
| 44 |
+
print("✅ SHARP model initialized successfully")
|
| 45 |
return _model
|
| 46 |
|
| 47 |
+
def _process_image_impl(image) -> tuple[Optional[str], str, str]:
|
|
|
|
| 48 |
"""
|
| 49 |
画像から3D Gaussian Splatsを生成
|
| 50 |
|
|
|
|
| 111 |
print(error_msg)
|
| 112 |
return None, error_msg, ""
|
| 113 |
|
| 114 |
+
# ZeroGPUデコレータを適用 (180秒のGPUタイムアウト)
|
| 115 |
+
# 注意: モジュールレベル関数に適用することでpickling問題を回避
|
| 116 |
+
process_image = spaces.GPU(duration=180)(_process_image_impl)
|
| 117 |
+
|
| 118 |
# Three.js ビューアのHTMLテンプレート
|
| 119 |
def create_viewer_html(ply_base64: str) -> str:
|
| 120 |
"""Three.js + GaussianSplats3D ビューアのHTMLを生成"""
|
|
@@ -1,23 +1,11 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
gsplat>=1.5.0
|
| 6 |
-
scipy>=1.14.0
|
| 7 |
-
numpy>=2.1.0,<3.0.0
|
| 8 |
-
pillow>=11.0.0
|
| 9 |
-
pillow-heif>=0.20.0
|
| 10 |
-
imageio>=2.37.0
|
| 11 |
-
imageio-ffmpeg>=0.6.0
|
| 12 |
-
click>=8.1.0
|
| 13 |
-
plyfile>=1.1.0
|
| 14 |
-
huggingface-hub>=0.27.0
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# SHARP package from GitHub (compatible with Python 3.10+)
|
| 23 |
-
git+https://github.com/apple/ml-sharp.git
|
|
|
|
| 1 |
+
# Gradio and Spaces (matching working example)
|
| 2 |
+
gradio==6.2.0
|
| 3 |
+
spaces==0.44.0
|
| 4 |
+
huggingface_hub>=1.2.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# PyTorch (latest versions for Python 3.13)
|
| 7 |
+
torch
|
| 8 |
+
torchvision
|
| 9 |
|
| 10 |
+
# SHARP package from GitHub (specific commit for stability)
|
| 11 |
+
sharp @ git+https://github.com/apple/ml-sharp.git@cdb4ddc6796402bee5487c7312260f2edd8bd5f0
|
|
|
|
|
|
|
|
|