Spaces:
Running
Running
raylander
commited on
Commit
·
f090b19
0
Parent(s):
Duplicate from raylander/mountdrive
Browse files- .gitattributes +35 -0
- README.md +11 -0
- app.py +242 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Mountdrive
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.9
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
duplicated_from: raylander/mountdrive
|
11 |
+
---
|
app.py
ADDED
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
os.system(f"pip install gradio > /dev/null 2>&1")
|
4 |
+
os.system(f"pip install -qq transformers scipy ftfy accelerate > /dev/null 2>&1")
|
5 |
+
os.system(f"pip install -qq --upgrade diffusers[torch] > /dev/null 2>&1")
|
6 |
+
os.system(f"git clone https://github.com/v8hid/infinite-zoom-stable-diffusion.git")
|
7 |
+
os.system(f"pip install imageio")
|
8 |
+
os.system(f"pip install diffusers")
|
9 |
+
|
10 |
+
|
11 |
+
import sys
|
12 |
+
sys.path.extend(['infinite-zoom-stable-diffusion/'])
|
13 |
+
from helpers import *
|
14 |
+
from diffusers import StableDiffusionInpaintPipeline, EulerAncestralDiscreteScheduler
|
15 |
+
from PIL import Image
|
16 |
+
import gradio as gr
|
17 |
+
import numpy as np
|
18 |
+
import torch
|
19 |
+
import os
|
20 |
+
import time
|
21 |
+
|
22 |
+
|
23 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
24 |
+
inpaint_model_list = [
|
25 |
+
"stabilityai/stable-diffusion-2-inpainting",
|
26 |
+
"runwayml/stable-diffusion-inpainting",
|
27 |
+
"parlance/dreamlike-diffusion-1.0-inpainting",
|
28 |
+
"ghunkins/stable-diffusion-liberty-inpainting",
|
29 |
+
"ImNoOne/f222-inpainting-diffusers"
|
30 |
+
]
|
31 |
+
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"
|
32 |
+
default_negative_prompt = "frames, borderline, text, charachter, duplicate, error, out of frame, watermark, low quality, ugly, deformed, blur"
|
33 |
+
|
34 |
+
|
35 |
+
def zoom(
|
36 |
+
model_id,
|
37 |
+
prompts_array,
|
38 |
+
negative_prompt,
|
39 |
+
num_outpainting_steps,
|
40 |
+
guidance_scale,
|
41 |
+
num_inference_steps,
|
42 |
+
custom_init_image
|
43 |
+
):
|
44 |
+
prompts = {}
|
45 |
+
for x in prompts_array:
|
46 |
+
try:
|
47 |
+
key = int(x[0])
|
48 |
+
value = str(x[1])
|
49 |
+
prompts[key] = value
|
50 |
+
except ValueError:
|
51 |
+
pass
|
52 |
+
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
53 |
+
model_id,
|
54 |
+
torch_dtype=torch.float16,
|
55 |
+
)
|
56 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(
|
57 |
+
pipe.scheduler.config)
|
58 |
+
pipe = pipe.to("cuda")
|
59 |
+
|
60 |
+
pipe.safety_checker = None
|
61 |
+
pipe.enable_attention_slicing()
|
62 |
+
g_cuda = torch.Generator(device='cuda')
|
63 |
+
|
64 |
+
height = 512
|
65 |
+
width = height
|
66 |
+
|
67 |
+
current_image = Image.new(mode="RGBA", size=(height, width))
|
68 |
+
mask_image = np.array(current_image)[:, :, 3]
|
69 |
+
mask_image = Image.fromarray(255-mask_image).convert("RGB")
|
70 |
+
current_image = current_image.convert("RGB")
|
71 |
+
if (custom_init_image):
|
72 |
+
current_image = custom_init_image.resize(
|
73 |
+
(width, height), resample=Image.LANCZOS)
|
74 |
+
else:
|
75 |
+
init_images = pipe(prompt=prompts[min(k for k in prompts.keys() if k >= 0)],
|
76 |
+
negative_prompt=negative_prompt,
|
77 |
+
image=current_image,
|
78 |
+
guidance_scale=guidance_scale,
|
79 |
+
height=height,
|
80 |
+
width=width,
|
81 |
+
mask_image=mask_image,
|
82 |
+
num_inference_steps=num_inference_steps)[0]
|
83 |
+
current_image = init_images[0]
|
84 |
+
mask_width = 128
|
85 |
+
num_interpol_frames = 30
|
86 |
+
|
87 |
+
all_frames = []
|
88 |
+
all_frames.append(current_image)
|
89 |
+
|
90 |
+
for i in range(num_outpainting_steps):
|
91 |
+
print('Outpaint step: ' + str(i+1) +
|
92 |
+
' / ' + str(num_outpainting_steps))
|
93 |
+
|
94 |
+
prev_image_fix = current_image
|
95 |
+
|
96 |
+
prev_image = shrink_and_paste_on_blank(current_image, mask_width)
|
97 |
+
|
98 |
+
current_image = prev_image
|
99 |
+
|
100 |
+
# create mask (black image with white mask_width width edges)
|
101 |
+
mask_image = np.array(current_image)[:, :, 3]
|
102 |
+
mask_image = Image.fromarray(255-mask_image).convert("RGB")
|
103 |
+
|
104 |
+
# inpainting step
|
105 |
+
current_image = current_image.convert("RGB")
|
106 |
+
images = pipe(prompt=prompts[max(k for k in prompts.keys() if k <= i)],
|
107 |
+
negative_prompt=negative_prompt,
|
108 |
+
image=current_image,
|
109 |
+
guidance_scale=guidance_scale,
|
110 |
+
height=height,
|
111 |
+
width=width,
|
112 |
+
# generator = g_cuda.manual_seed(seed),
|
113 |
+
mask_image=mask_image,
|
114 |
+
num_inference_steps=num_inference_steps)[0]
|
115 |
+
current_image = images[0]
|
116 |
+
current_image.paste(prev_image, mask=prev_image)
|
117 |
+
|
118 |
+
# interpolation steps bewteen 2 inpainted images (=sequential zoom and crop)
|
119 |
+
for j in range(num_interpol_frames - 1):
|
120 |
+
interpol_image = current_image
|
121 |
+
interpol_width = round(
|
122 |
+
(1 - (1-2*mask_width/height)**(1-(j+1)/num_interpol_frames))*height/2
|
123 |
+
)
|
124 |
+
interpol_image = interpol_image.crop((interpol_width,
|
125 |
+
interpol_width,
|
126 |
+
width - interpol_width,
|
127 |
+
height - interpol_width))
|
128 |
+
|
129 |
+
interpol_image = interpol_image.resize((height, width))
|
130 |
+
|
131 |
+
# paste the higher resolution previous image in the middle to avoid drop in quality caused by zooming
|
132 |
+
interpol_width2 = round(
|
133 |
+
(1 - (height-2*mask_width) / (height-2*interpol_width)) / 2*height
|
134 |
+
)
|
135 |
+
prev_image_fix_crop = shrink_and_paste_on_blank(
|
136 |
+
prev_image_fix, interpol_width2)
|
137 |
+
interpol_image.paste(prev_image_fix_crop, mask=prev_image_fix_crop)
|
138 |
+
|
139 |
+
all_frames.append(interpol_image)
|
140 |
+
all_frames.append(current_image)
|
141 |
+
interpol_image.show()
|
142 |
+
video_file_name = "infinite_zoom_" + str(time.time())
|
143 |
+
fps = 30
|
144 |
+
save_path = video_file_name + ".mp4"
|
145 |
+
start_frame_dupe_amount = 15
|
146 |
+
last_frame_dupe_amount = 15
|
147 |
+
|
148 |
+
write_video(save_path, all_frames, fps, False,
|
149 |
+
start_frame_dupe_amount, last_frame_dupe_amount)
|
150 |
+
return save_path
|
151 |
+
|
152 |
+
|
153 |
+
def zoom_app():
|
154 |
+
with gr.Blocks():
|
155 |
+
with gr.Row():
|
156 |
+
with gr.Column():
|
157 |
+
|
158 |
+
outpaint_prompts = gr.Dataframe(
|
159 |
+
type="array",
|
160 |
+
headers=["outpaint steps", "prompt"],
|
161 |
+
datatype=["number", "str"],
|
162 |
+
row_count=1,
|
163 |
+
col_count=(2, "fixed"),
|
164 |
+
value=[[0, default_prompt]],
|
165 |
+
wrap=True
|
166 |
+
)
|
167 |
+
|
168 |
+
outpaint_negative_prompt = gr.Textbox(
|
169 |
+
lines=1,
|
170 |
+
value=default_negative_prompt,
|
171 |
+
label='Negative Prompt'
|
172 |
+
)
|
173 |
+
|
174 |
+
outpaint_steps = gr.Slider(
|
175 |
+
minimum=5,
|
176 |
+
maximum=25,
|
177 |
+
step=1,
|
178 |
+
value=12,
|
179 |
+
label='Total Outpaint Steps'
|
180 |
+
)
|
181 |
+
with gr.Accordion("Advanced Options", open=False):
|
182 |
+
model_id = gr.Dropdown(
|
183 |
+
choices=inpaint_model_list,
|
184 |
+
value=inpaint_model_list[0],
|
185 |
+
label='Pre-trained Model ID'
|
186 |
+
)
|
187 |
+
|
188 |
+
guidance_scale = gr.Slider(
|
189 |
+
minimum=0.1,
|
190 |
+
maximum=15,
|
191 |
+
step=0.1,
|
192 |
+
value=7,
|
193 |
+
label='Guidance Scale'
|
194 |
+
)
|
195 |
+
|
196 |
+
sampling_step = gr.Slider(
|
197 |
+
minimum=1,
|
198 |
+
maximum=100,
|
199 |
+
step=1,
|
200 |
+
value=50,
|
201 |
+
label='Sampling Steps for each outpaint'
|
202 |
+
)
|
203 |
+
init_image = gr.Image(type="pil",label="custom initial image")
|
204 |
+
generate_btn = gr.Button(value='Generate video')
|
205 |
+
|
206 |
+
with gr.Column():
|
207 |
+
output_image = gr.Video(label='Output', format="mp4").style(
|
208 |
+
width=512, height=512)
|
209 |
+
|
210 |
+
generate_btn.click(
|
211 |
+
fn=zoom,
|
212 |
+
inputs=[
|
213 |
+
model_id,
|
214 |
+
outpaint_prompts,
|
215 |
+
outpaint_negative_prompt,
|
216 |
+
outpaint_steps,
|
217 |
+
guidance_scale,
|
218 |
+
sampling_step,
|
219 |
+
init_image
|
220 |
+
],
|
221 |
+
outputs=output_image,
|
222 |
+
)
|
223 |
+
|
224 |
+
|
225 |
+
import gradio as gr
|
226 |
+
|
227 |
+
app = gr.Blocks()
|
228 |
+
with app:
|
229 |
+
gr.HTML(
|
230 |
+
"""
|
231 |
+
<h2 style='text-align: center'>
|
232 |
+
<a href="https://github.com/v8hid/infinite-zoom-stable-diffusion/" style="display:inline-block;">
|
233 |
+
<img src="https://img.shields.io/static/v1?label=github&message=repository&color=blue&style=for-the-badge&logo=github&logoColor=white" alt="build status">
|
234 |
+
</a>
|
235 |
+
<br>
|
236 |
+
Text to Video - Infinite zoom effect
|
237 |
+
</h2>
|
238 |
+
"""
|
239 |
+
)
|
240 |
+
zoom_app()
|
241 |
+
|
242 |
+
app.launch(debug=True,enable_queue=True)
|