Spaces:
Running
on
Zero
Running
on
Zero
Alexander Bagus
commited on
Commit
·
ffc2074
1
Parent(s):
078f16b
22
Browse files- app.py +5 -3
- utils/image_utils.py +8 -2
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from videox_fun.pipeline import ZImageControlPipeline
|
|
| 6 |
from videox_fun.models import ZImageControlTransformer2DModel
|
| 7 |
from transformers import AutoTokenizer, Qwen3ForCausalLM
|
| 8 |
from diffusers import AutoencoderKL
|
| 9 |
-
from utils.image_utils import get_image_latent,
|
| 10 |
from utils.prompt_utils import polish_prompt
|
| 11 |
# from controlnet_aux import HEDdetector, MLSDdetector, OpenposeDetector, CannyDetector, MidasDetector
|
| 12 |
from controlnet_aux.processor import Processor
|
|
@@ -86,7 +86,7 @@ def inference(
|
|
| 86 |
prompt,
|
| 87 |
input_image,
|
| 88 |
image_scale=1.0,
|
| 89 |
-
control_mode='Canny'
|
| 90 |
control_context_scale = 0.75,
|
| 91 |
seed=42,
|
| 92 |
randomize_seed=True,
|
|
@@ -114,7 +114,9 @@ def inference(
|
|
| 114 |
else:
|
| 115 |
processor = Processor('canny')
|
| 116 |
|
| 117 |
-
|
|
|
|
|
|
|
| 118 |
control_image = control_image.resize((512, 512))
|
| 119 |
|
| 120 |
print("DEBUG: processor running")
|
|
|
|
| 6 |
from videox_fun.models import ZImageControlTransformer2DModel
|
| 7 |
from transformers import AutoTokenizer, Qwen3ForCausalLM
|
| 8 |
from diffusers import AutoencoderKL
|
| 9 |
+
from utils.image_utils import get_image_latent, rescale_image
|
| 10 |
from utils.prompt_utils import polish_prompt
|
| 11 |
# from controlnet_aux import HEDdetector, MLSDdetector, OpenposeDetector, CannyDetector, MidasDetector
|
| 12 |
from controlnet_aux.processor import Processor
|
|
|
|
| 86 |
prompt,
|
| 87 |
input_image,
|
| 88 |
image_scale=1.0,
|
| 89 |
+
control_mode='Canny',
|
| 90 |
control_context_scale = 0.75,
|
| 91 |
seed=42,
|
| 92 |
randomize_seed=True,
|
|
|
|
| 114 |
else:
|
| 115 |
processor = Processor('canny')
|
| 116 |
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
control_image, width, height = rescale_image(input_image, image_scale, 8)
|
| 120 |
control_image = control_image.resize((512, 512))
|
| 121 |
|
| 122 |
print("DEBUG: processor running")
|
utils/image_utils.py
CHANGED
|
@@ -2,12 +2,18 @@ import torch
|
|
| 2 |
from PIL import Image
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
def
|
| 6 |
w, h = img.size
|
| 7 |
new_w = int(w * scale)
|
| 8 |
new_h = int(h * scale)
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
new_w = (new_w // nearest) * nearest
|
| 12 |
new_h = (new_h // nearest) * nearest
|
| 13 |
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
def rescale_image(img, scale, nearest=32, max_size=1280):
|
| 6 |
w, h = img.size
|
| 7 |
new_w = int(w * scale)
|
| 8 |
new_h = int(h * scale)
|
| 9 |
|
| 10 |
+
if new_w > max_size or new_h > max_size:
|
| 11 |
+
# Calculate new size keeping aspect ratio
|
| 12 |
+
scale = min(max_size / new_w, max_size / new_h)
|
| 13 |
+
new_w = int(new_w * scale)
|
| 14 |
+
new_w = int(new_w * scale)
|
| 15 |
+
|
| 16 |
+
# Adjust to nearest multiple
|
| 17 |
new_w = (new_w // nearest) * nearest
|
| 18 |
new_h = (new_h // nearest) * nearest
|
| 19 |
|