Spaces:
Sleeping
Sleeping
Olivia
commited on
Commit
·
378e285
1
Parent(s):
ae8e74c
Add ZeroGPU support with spaces decorator
Browse files- app.py +18 -1
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -37,12 +37,22 @@ except ImportError:
|
|
| 37 |
PLOTLY_AVAILABLE = False
|
| 38 |
print("Plotly not available, charts will be disabled")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# ============================================================================
|
| 41 |
# Configuration
|
| 42 |
# ============================================================================
|
| 43 |
|
| 44 |
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 45 |
print(f"Device: {DEVICE}")
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Check CUDA kernels availability
|
| 48 |
try:
|
|
@@ -961,7 +971,7 @@ def create_benchmark_comparison(style: str) -> str:
|
|
| 961 |
# Gradio Interface Functions
|
| 962 |
# ============================================================================
|
| 963 |
|
| 964 |
-
def
|
| 965 |
input_image: Optional[Image.Image],
|
| 966 |
style: str,
|
| 967 |
backend: str,
|
|
@@ -1077,6 +1087,13 @@ def stylize_image(
|
|
| 1077 |
return None, error_msg, None
|
| 1078 |
|
| 1079 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1080 |
def process_webcam_frame(image: Image.Image, style: str, backend: str) -> Image.Image:
|
| 1081 |
"""Process webcam frame in real-time."""
|
| 1082 |
if image is None:
|
|
|
|
| 37 |
PLOTLY_AVAILABLE = False
|
| 38 |
print("Plotly not available, charts will be disabled")
|
| 39 |
|
| 40 |
+
# Try to import spaces for ZeroGPU support
|
| 41 |
+
try:
|
| 42 |
+
from spaces import GPU
|
| 43 |
+
SPACES_AVAILABLE = True
|
| 44 |
+
except ImportError:
|
| 45 |
+
SPACES_AVAILABLE = False
|
| 46 |
+
print("HuggingFace spaces not available (running locally)")
|
| 47 |
+
|
| 48 |
# ============================================================================
|
| 49 |
# Configuration
|
| 50 |
# ============================================================================
|
| 51 |
|
| 52 |
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 53 |
print(f"Device: {DEVICE}")
|
| 54 |
+
if SPACES_AVAILABLE:
|
| 55 |
+
print("ZeroGPU support enabled")
|
| 56 |
|
| 57 |
# Check CUDA kernels availability
|
| 58 |
try:
|
|
|
|
| 971 |
# Gradio Interface Functions
|
| 972 |
# ============================================================================
|
| 973 |
|
| 974 |
+
def stylize_image_impl(
|
| 975 |
input_image: Optional[Image.Image],
|
| 976 |
style: str,
|
| 977 |
backend: str,
|
|
|
|
| 1087 |
return None, error_msg, None
|
| 1088 |
|
| 1089 |
|
| 1090 |
+
# Wrap with GPU decorator for ZeroGPU if available
|
| 1091 |
+
if SPACES_AVAILABLE:
|
| 1092 |
+
stylize_image = GPU(stylize_image_impl)
|
| 1093 |
+
else:
|
| 1094 |
+
stylize_image = stylize_image_impl
|
| 1095 |
+
|
| 1096 |
+
|
| 1097 |
def process_webcam_frame(image: Image.Image, style: str, backend: str) -> Image.Image:
|
| 1098 |
"""Process webcam frame in real-time."""
|
| 1099 |
if image is None:
|
requirements.txt
CHANGED
|
@@ -3,6 +3,7 @@ torch>=2.0.0
|
|
| 3 |
torchvision>=0.15.0
|
| 4 |
gradio==4.32.0
|
| 5 |
huggingface_hub==0.20.0
|
|
|
|
| 6 |
Pillow>=9.5.0
|
| 7 |
numpy>=1.24.0
|
| 8 |
|
|
|
|
| 3 |
torchvision>=0.15.0
|
| 4 |
gradio==4.32.0
|
| 5 |
huggingface_hub==0.20.0
|
| 6 |
+
spaces
|
| 7 |
Pillow>=9.5.0
|
| 8 |
numpy>=1.24.0
|
| 9 |
|