Fix: add opencv-python + optional spaces import for Runpod compatibility
Browse files
app.py
CHANGED
|
@@ -3,24 +3,20 @@ import numpy as np
|
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
import torch
|
|
|
|
| 6 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Опциональный импорт spaces
|
| 9 |
try:
|
| 10 |
import spaces
|
| 11 |
-
|
| 12 |
except ImportError:
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def GPU(duration=None):
|
| 17 |
-
def decorator(func):
|
| 18 |
-
return func
|
| 19 |
-
return decorator
|
| 20 |
-
|
| 21 |
-
import os
|
| 22 |
-
import time
|
| 23 |
-
import logging
|
| 24 |
|
| 25 |
from diffusers import (
|
| 26 |
DiffusionPipeline,
|
|
@@ -239,7 +235,15 @@ AVAILABLE_LORAS = {
|
|
| 239 |
|
| 240 |
MAX_SEED = np.iinfo(np.int32).max
|
| 241 |
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
def generate_text2img(
|
| 244 |
prompt,
|
| 245 |
negative_prompt=" ",
|
|
@@ -309,7 +313,7 @@ def generate_text2img(
|
|
| 309 |
logger.error(f" ❌ Error: {e}")
|
| 310 |
raise
|
| 311 |
|
| 312 |
-
@
|
| 313 |
def generate_img2img(
|
| 314 |
input_image,
|
| 315 |
prompt,
|
|
@@ -383,7 +387,7 @@ def generate_img2img(
|
|
| 383 |
logger.error(f" ❌ Error: {e}")
|
| 384 |
raise
|
| 385 |
|
| 386 |
-
@
|
| 387 |
def generate_controlnet(
|
| 388 |
input_image,
|
| 389 |
prompt,
|
|
|
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
import torch
|
| 6 |
+
import cv2
|
| 7 |
from PIL import Image
|
| 8 |
+
import os
|
| 9 |
+
import time
|
| 10 |
+
import logging
|
| 11 |
|
| 12 |
+
# Опциональный импорт spaces для работы в Runpod
|
| 13 |
try:
|
| 14 |
import spaces
|
| 15 |
+
SPACES_AVAILABLE = True
|
| 16 |
except ImportError:
|
| 17 |
+
SPACES_AVAILABLE = False
|
| 18 |
+
logger = logging.getLogger(__name__)
|
| 19 |
+
logger.warning("⚠️ spaces module not available - running without ZeroGPU support")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
from diffusers import (
|
| 22 |
DiffusionPipeline,
|
|
|
|
| 235 |
|
| 236 |
MAX_SEED = np.iinfo(np.int32).max
|
| 237 |
|
| 238 |
+
# Декоратор для spaces если доступен
|
| 239 |
+
def gpu_decorator(duration=180):
|
| 240 |
+
def decorator(func):
|
| 241 |
+
if SPACES_AVAILABLE:
|
| 242 |
+
return spaces.GPU(duration=duration)(func)
|
| 243 |
+
return func
|
| 244 |
+
return decorator
|
| 245 |
+
|
| 246 |
+
@gpu_decorator(duration=180)
|
| 247 |
def generate_text2img(
|
| 248 |
prompt,
|
| 249 |
negative_prompt=" ",
|
|
|
|
| 313 |
logger.error(f" ❌ Error: {e}")
|
| 314 |
raise
|
| 315 |
|
| 316 |
+
@gpu_decorator(duration=180)
|
| 317 |
def generate_img2img(
|
| 318 |
input_image,
|
| 319 |
prompt,
|
|
|
|
| 387 |
logger.error(f" ❌ Error: {e}")
|
| 388 |
raise
|
| 389 |
|
| 390 |
+
@gpu_decorator(duration=180)
|
| 391 |
def generate_controlnet(
|
| 392 |
input_image,
|
| 393 |
prompt,
|