Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,14 +31,42 @@ pipe = StableDiffusion3CommonPipeline.from_pretrained(
|
|
| 31 |
)
|
| 32 |
pipe.to('cuda:0', torch.float16)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def infer(image_in, prompt):
|
| 35 |
prompt = 'Anime style illustration of a girl wearing a suit. A moon in sky. In the background we see a big rain approaching. text "InstantX" on image'
|
| 36 |
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# controlnet config
|
| 38 |
controlnet_conditioning = [
|
| 39 |
dict(
|
| 40 |
control_index=0,
|
| 41 |
-
control_image=
|
| 42 |
control_weight=0.7,
|
| 43 |
control_pooled_projections='zeros'
|
| 44 |
)
|
|
|
|
| 31 |
)
|
| 32 |
pipe.to('cuda:0', torch.float16)
|
| 33 |
|
| 34 |
+
def resize_image(input_path, output_path, target_height):
|
| 35 |
+
# Open the input image
|
| 36 |
+
img = Image.open(input_path)
|
| 37 |
+
|
| 38 |
+
# Calculate the aspect ratio of the original image
|
| 39 |
+
original_width, original_height = img.size
|
| 40 |
+
original_aspect_ratio = original_width / original_height
|
| 41 |
+
|
| 42 |
+
# Calculate the new width while maintaining the aspect ratio and the target height
|
| 43 |
+
new_width = int(target_height * original_aspect_ratio)
|
| 44 |
+
|
| 45 |
+
# Resize the image while maintaining the aspect ratio and fixing the height
|
| 46 |
+
img = img.resize((new_width, target_height), Image.LANCZOS)
|
| 47 |
+
|
| 48 |
+
# Save the resized image
|
| 49 |
+
img.save(output_path)
|
| 50 |
+
|
| 51 |
+
return output_path
|
| 52 |
+
|
| 53 |
def infer(image_in, prompt):
|
| 54 |
prompt = 'Anime style illustration of a girl wearing a suit. A moon in sky. In the background we see a big rain approaching. text "InstantX" on image'
|
| 55 |
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
| 56 |
+
|
| 57 |
+
image_to_canny = load_image(image_in)
|
| 58 |
+
|
| 59 |
+
image_to_canny = np.array(image_to_canny)
|
| 60 |
+
image_to_canny = cv2.Canny(image_to_canny, 100, 200)
|
| 61 |
+
image_to_canny = image_to_canny[:, :, None]
|
| 62 |
+
image_to_canny = np.concatenate([image_to_canny, image_to_canny, image_to_canny], axis=2)
|
| 63 |
+
image_to_canny = Image.fromarray(image_to_canny)
|
| 64 |
+
|
| 65 |
# controlnet config
|
| 66 |
controlnet_conditioning = [
|
| 67 |
dict(
|
| 68 |
control_index=0,
|
| 69 |
+
control_image=image_to_canny,
|
| 70 |
control_weight=0.7,
|
| 71 |
control_pooled_projections='zeros'
|
| 72 |
)
|