Spaces:
Build error
Build error
Multi prompts feature
Browse files
zoom.py
CHANGED
|
@@ -16,26 +16,25 @@ inpaint_model_list = [
|
|
| 16 |
]
|
| 17 |
default_prompt = "A psychedelic jungle with trees that have glowing, fractal-like patterns, Simon stalenhag poster 1920s style, street level view, hyper futuristic, 8k resolution, hyper realistic"
|
| 18 |
default_negative_prompt = "frames, borderline, text, charachter, duplicate, error, out of frame, watermark, low quality, ugly, deformed, blur"
|
| 19 |
-
# TODO:
|
| 20 |
-
# prompts = {
|
| 21 |
-
# 0: "prompt1",
|
| 22 |
-
# 7: "prompt2"
|
| 23 |
-
# }
|
| 24 |
-
|
| 25 |
-
custom_init_image = False
|
| 26 |
-
init_image_address = "/init/image.jpeg"
|
| 27 |
|
| 28 |
|
| 29 |
def zoom(
|
| 30 |
model_id,
|
| 31 |
-
|
| 32 |
negative_prompt,
|
| 33 |
num_outpainting_steps,
|
| 34 |
guidance_scale,
|
| 35 |
num_inference_steps,
|
| 36 |
custom_init_image
|
| 37 |
):
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 40 |
model_id,
|
| 41 |
torch_dtype=torch.float16,
|
|
@@ -57,18 +56,19 @@ def zoom(
|
|
| 57 |
mask_image = np.array(current_image)[:, :, 3]
|
| 58 |
mask_image = Image.fromarray(255-mask_image).convert("RGB")
|
| 59 |
current_image = current_image.convert("RGB")
|
| 60 |
-
if(custom_init_image):
|
| 61 |
-
|
|
|
|
| 62 |
else:
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
mask_width = 128
|
| 73 |
num_interpol_frames = 30
|
| 74 |
|
|
@@ -91,7 +91,7 @@ def zoom(
|
|
| 91 |
|
| 92 |
# inpainting step
|
| 93 |
current_image = current_image.convert("RGB")
|
| 94 |
-
images = pipe(prompt=
|
| 95 |
negative_prompt=negative_prompt,
|
| 96 |
image=current_image,
|
| 97 |
guidance_scale=guidance_scale,
|
|
@@ -125,8 +125,8 @@ def zoom(
|
|
| 125 |
interpol_image.paste(prev_image_fix_crop, mask=prev_image_fix_crop)
|
| 126 |
|
| 127 |
all_frames.append(interpol_image)
|
| 128 |
-
|
| 129 |
all_frames.append(current_image)
|
|
|
|
| 130 |
video_file_name = "infinite_zoom_" + str(time.time())
|
| 131 |
fps = 30
|
| 132 |
save_path = video_file_name + ".mp4"
|
|
@@ -137,15 +137,20 @@ def zoom(
|
|
| 137 |
start_frame_dupe_amount, last_frame_dupe_amount)
|
| 138 |
return save_path
|
| 139 |
|
|
|
|
| 140 |
def zoom_app():
|
| 141 |
with gr.Blocks():
|
| 142 |
with gr.Row():
|
| 143 |
with gr.Column():
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
)
|
| 150 |
|
| 151 |
outpaint_negative_prompt = gr.Textbox(
|
|
@@ -185,7 +190,7 @@ def zoom_app():
|
|
| 185 |
)
|
| 186 |
init_image = gr.Image(type="pil")
|
| 187 |
generate_btn = gr.Button(value='Generate video')
|
| 188 |
-
|
| 189 |
with gr.Column():
|
| 190 |
output_image = gr.Video(label='Output', format="mp4").style(
|
| 191 |
width=512, height=512)
|
|
@@ -194,7 +199,7 @@ def zoom_app():
|
|
| 194 |
fn=zoom,
|
| 195 |
inputs=[
|
| 196 |
model_id,
|
| 197 |
-
|
| 198 |
outpaint_negative_prompt,
|
| 199 |
outpaint_steps,
|
| 200 |
guidance_scale,
|
|
|
|
| 16 |
]
|
| 17 |
default_prompt = "A psychedelic jungle with trees that have glowing, fractal-like patterns, Simon stalenhag poster 1920s style, street level view, hyper futuristic, 8k resolution, hyper realistic"
|
| 18 |
default_negative_prompt = "frames, borderline, text, charachter, duplicate, error, out of frame, watermark, low quality, ugly, deformed, blur"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def zoom(
|
| 22 |
model_id,
|
| 23 |
+
prompts_array,
|
| 24 |
negative_prompt,
|
| 25 |
num_outpainting_steps,
|
| 26 |
guidance_scale,
|
| 27 |
num_inference_steps,
|
| 28 |
custom_init_image
|
| 29 |
):
|
| 30 |
+
prompts = {}
|
| 31 |
+
for x in prompts_array:
|
| 32 |
+
try:
|
| 33 |
+
key = int(x[0])
|
| 34 |
+
value = str(x[1])
|
| 35 |
+
prompts[key] = value
|
| 36 |
+
except ValueError:
|
| 37 |
+
pass
|
| 38 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 39 |
model_id,
|
| 40 |
torch_dtype=torch.float16,
|
|
|
|
| 56 |
mask_image = np.array(current_image)[:, :, 3]
|
| 57 |
mask_image = Image.fromarray(255-mask_image).convert("RGB")
|
| 58 |
current_image = current_image.convert("RGB")
|
| 59 |
+
if (custom_init_image):
|
| 60 |
+
current_image = custom_init_image.resize(
|
| 61 |
+
(width, height), resample=Image.LANCZOS)
|
| 62 |
else:
|
| 63 |
+
init_images = pipe(prompt=prompts[min(k for k in prompts.keys() if k >= 0)],
|
| 64 |
+
negative_prompt=negative_prompt,
|
| 65 |
+
image=current_image,
|
| 66 |
+
guidance_scale=guidance_scale,
|
| 67 |
+
height=height,
|
| 68 |
+
width=width,
|
| 69 |
+
mask_image=mask_image,
|
| 70 |
+
num_inference_steps=num_inference_steps)[0]
|
| 71 |
+
current_image = init_images[0]
|
| 72 |
mask_width = 128
|
| 73 |
num_interpol_frames = 30
|
| 74 |
|
|
|
|
| 91 |
|
| 92 |
# inpainting step
|
| 93 |
current_image = current_image.convert("RGB")
|
| 94 |
+
images = pipe(prompt=prompts[max(k for k in prompts.keys() if k <= i)],
|
| 95 |
negative_prompt=negative_prompt,
|
| 96 |
image=current_image,
|
| 97 |
guidance_scale=guidance_scale,
|
|
|
|
| 125 |
interpol_image.paste(prev_image_fix_crop, mask=prev_image_fix_crop)
|
| 126 |
|
| 127 |
all_frames.append(interpol_image)
|
|
|
|
| 128 |
all_frames.append(current_image)
|
| 129 |
+
# interpol_image.show()
|
| 130 |
video_file_name = "infinite_zoom_" + str(time.time())
|
| 131 |
fps = 30
|
| 132 |
save_path = video_file_name + ".mp4"
|
|
|
|
| 137 |
start_frame_dupe_amount, last_frame_dupe_amount)
|
| 138 |
return save_path
|
| 139 |
|
| 140 |
+
|
| 141 |
def zoom_app():
|
| 142 |
with gr.Blocks():
|
| 143 |
with gr.Row():
|
| 144 |
with gr.Column():
|
| 145 |
|
| 146 |
+
outpaint_prompts = gr.Dataframe(
|
| 147 |
+
type="array",
|
| 148 |
+
headers=["outpaint steps", "prompt"],
|
| 149 |
+
datatype=["number", "str"],
|
| 150 |
+
row_count=1,
|
| 151 |
+
col_count=(2, "fixed"),
|
| 152 |
+
value=[[0, default_prompt]],
|
| 153 |
+
wrap=True
|
| 154 |
)
|
| 155 |
|
| 156 |
outpaint_negative_prompt = gr.Textbox(
|
|
|
|
| 190 |
)
|
| 191 |
init_image = gr.Image(type="pil")
|
| 192 |
generate_btn = gr.Button(value='Generate video')
|
| 193 |
+
|
| 194 |
with gr.Column():
|
| 195 |
output_image = gr.Video(label='Output', format="mp4").style(
|
| 196 |
width=512, height=512)
|
|
|
|
| 199 |
fn=zoom,
|
| 200 |
inputs=[
|
| 201 |
model_id,
|
| 202 |
+
outpaint_prompts,
|
| 203 |
outpaint_negative_prompt,
|
| 204 |
outpaint_steps,
|
| 205 |
guidance_scale,
|