Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,11 +34,34 @@ pipe.to("cuda")
|
|
34 |
|
35 |
#pipe.enable_model_cpu_offload()
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def infer(use_custom_model, model_name, custom_lora_weight, image_in, prompt, negative_prompt, preprocessor, controlnet_conditioning_scale, guidance_scale, inf_steps, seed, progress=gr.Progress(track_tqdm=True)):
|
38 |
prompt = prompt
|
39 |
negative_prompt = negative_prompt
|
40 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
41 |
|
|
|
|
|
42 |
if preprocessor == "canny":
|
43 |
|
44 |
image = load_image(image_in)
|
|
|
34 |
|
35 |
#pipe.enable_model_cpu_offload()
|
36 |
|
37 |
+
from PIL import Image
|
38 |
+
|
39 |
+
def resize_image(input_path, output_path, target_height):
|
40 |
+
# Open the input image
|
41 |
+
img = Image.open(input_path)
|
42 |
+
|
43 |
+
# Calculate the aspect ratio of the original image
|
44 |
+
original_width, original_height = img.size
|
45 |
+
original_aspect_ratio = original_width / original_height
|
46 |
+
|
47 |
+
# Calculate the new width while maintaining the aspect ratio and the target height
|
48 |
+
new_width = int(target_height * original_aspect_ratio)
|
49 |
+
|
50 |
+
# Resize the image while maintaining the aspect ratio and fixing the height
|
51 |
+
img = img.resize((new_width, target_height), Image.LANCZOS)
|
52 |
+
|
53 |
+
# Save the resized image
|
54 |
+
img.save(output_path)
|
55 |
+
|
56 |
+
return output_path
|
57 |
+
|
58 |
def infer(use_custom_model, model_name, custom_lora_weight, image_in, prompt, negative_prompt, preprocessor, controlnet_conditioning_scale, guidance_scale, inf_steps, seed, progress=gr.Progress(track_tqdm=True)):
|
59 |
prompt = prompt
|
60 |
negative_prompt = negative_prompt
|
61 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
62 |
|
63 |
+
image_in = resize_image(image_in, "resized_input.jpg", 1024)
|
64 |
+
|
65 |
if preprocessor == "canny":
|
66 |
|
67 |
image = load_image(image_in)
|