Added custom models option
Browse files
app.py
CHANGED
@@ -34,11 +34,13 @@ for name in names:
|
|
34 |
continue
|
35 |
subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')
|
36 |
|
37 |
-
from model import
|
|
|
|
|
38 |
model = Model()
|
39 |
|
40 |
|
41 |
-
def controlnet(i, prompt, control_task, seed_in, ddim_steps, scale):
|
42 |
img= Image.open(i)
|
43 |
np_img = np.array(img)
|
44 |
|
@@ -48,11 +50,11 @@ def controlnet(i, prompt, control_task, seed_in, ddim_steps, scale):
|
|
48 |
image_resolution = 512
|
49 |
detect_resolution = 512
|
50 |
eta = 0.0
|
51 |
-
low_threshold = 100
|
52 |
-
high_threshold = 200
|
53 |
-
value_threshold = 0.1
|
54 |
-
distance_threshold = 0.1
|
55 |
-
bg_threshold = 0.4
|
56 |
|
57 |
if control_task == 'Canny':
|
58 |
result = model.process_canny(np_img, prompt, a_prompt, n_prompt, num_samples,
|
@@ -87,6 +89,15 @@ def controlnet(i, prompt, control_task, seed_in, ddim_steps, scale):
|
|
87 |
im.save("your_file" + str(i) + ".jpeg")
|
88 |
return "your_file" + str(i) + ".jpeg", "process_" + control_task + "_" + str(i) + ".jpeg"
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
def get_frames(video_in):
|
92 |
frames = []
|
@@ -143,7 +154,7 @@ def create_video(frames, fps, type):
|
|
143 |
return type + "_result.mp4"
|
144 |
|
145 |
|
146 |
-
def infer(prompt,video_in, control_task, seed_in, trim_value, ddim_steps, scale, gif_import):
|
147 |
print(f"""
|
148 |
βββββββββββββββ
|
149 |
{prompt}
|
@@ -165,7 +176,7 @@ def infer(prompt,video_in, control_task, seed_in, trim_value, ddim_steps, scale,
|
|
165 |
print("set stop frames to: " + str(n_frame))
|
166 |
|
167 |
for i in frames_list[0:int(n_frame)]:
|
168 |
-
controlnet_img = controlnet(i, prompt,control_task, seed_in, ddim_steps, scale)
|
169 |
#images = controlnet_img[0]
|
170 |
#rgb_im = images[0].convert("RGB")
|
171 |
|
@@ -239,57 +250,91 @@ article = """
|
|
239 |
with gr.Blocks(css='style.css') as demo:
|
240 |
with gr.Column(elem_id="col-container"):
|
241 |
gr.HTML(title)
|
|
|
|
|
|
|
242 |
with gr.Row():
|
243 |
with gr.Column():
|
244 |
video_inp = gr.Video(label="Video source", source="upload", type="filepath", elem_id="input-vid")
|
245 |
video_out = gr.Video(label="ControlNet video result", elem_id="video-output")
|
246 |
-
|
247 |
-
prep_video_out = gr.Video(label="Preprocessor video result", visible=False, elem_id="prep-video-output")
|
248 |
-
files = gr.File(label="Files can be downloaded ;)", visible=False)
|
249 |
with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
|
250 |
community_icon = gr.HTML(community_icon_html)
|
251 |
loading_icon = gr.HTML(loading_icon_html)
|
252 |
share_button = gr.Button("Share to community", elem_id="share-btn")
|
|
|
|
|
|
|
|
|
|
|
253 |
with gr.Column():
|
254 |
#status = gr.Textbox()
|
255 |
|
256 |
prompt = gr.Textbox(label="Prompt", placeholder="enter prompt", show_label=True, elem_id="prompt-in")
|
|
|
257 |
with gr.Row():
|
258 |
control_task = gr.Dropdown(label="Control Task", choices=["Canny", "Depth", "Hed", "Hough", "Normal", "Pose", "Scribble", "Seg"], value="Pose", multiselect=False, elem_id="controltask-in")
|
259 |
seed_inp = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, value=123456, elem_id="seed-in")
|
|
|
260 |
with gr.Row():
|
261 |
-
|
262 |
-
|
263 |
with gr.Accordion("Advanced Options", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
279 |
-
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
-
gr.
|
282 |
-
<a style="display:inline-block" href="https://huggingface.co/spaces/fffiloni/ControlNet-Video?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
|
283 |
-
work with longer videos / skip the queue:
|
284 |
-
""", elem_id="duplicate-container")
|
285 |
|
286 |
-
inputs = [prompt,video_inp,control_task, seed_inp, trim_in, ddim_steps, scale, gif_import]
|
287 |
outputs = [video_out, detailed_result, prep_video_out, files, share_group]
|
288 |
#outputs = [status]
|
289 |
|
290 |
|
291 |
gr.HTML(article)
|
292 |
-
|
293 |
submit_btn.click(clean, inputs=[], outputs=[detailed_result, prep_video_out, video_out, files, share_group], queue=False)
|
294 |
submit_btn.click(infer, inputs, outputs)
|
295 |
share_button.click(None, [], [], _js=share_js)
|
|
|
34 |
continue
|
35 |
subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')
|
36 |
|
37 |
+
from model import (DEFAULT_BASE_MODEL_FILENAME, DEFAULT_BASE_MODEL_REPO,
|
38 |
+
DEFAULT_BASE_MODEL_URL, Model)
|
39 |
+
|
40 |
model = Model()
|
41 |
|
42 |
|
43 |
+
def controlnet(i, prompt, control_task, seed_in, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold):
|
44 |
img= Image.open(i)
|
45 |
np_img = np.array(img)
|
46 |
|
|
|
50 |
image_resolution = 512
|
51 |
detect_resolution = 512
|
52 |
eta = 0.0
|
53 |
+
#low_threshold = 100
|
54 |
+
#high_threshold = 200
|
55 |
+
#value_threshold = 0.1
|
56 |
+
#distance_threshold = 0.1
|
57 |
+
#bg_threshold = 0.4
|
58 |
|
59 |
if control_task == 'Canny':
|
60 |
result = model.process_canny(np_img, prompt, a_prompt, n_prompt, num_samples,
|
|
|
89 |
im.save("your_file" + str(i) + ".jpeg")
|
90 |
return "your_file" + str(i) + ".jpeg", "process_" + control_task + "_" + str(i) + ".jpeg"
|
91 |
|
92 |
+
def change_task_options(task):
|
93 |
+
if task == "Canny" :
|
94 |
+
return canny_opt.update(visible=True), hough_opt.update(visible=False), normal_opt.update(visible=False)
|
95 |
+
elif task == "Hough" :
|
96 |
+
return canny_opt.update(visible=False),hough_opt.update(visible=True), normal_opt.update(visible=False)
|
97 |
+
elif task == "Normal" :
|
98 |
+
return canny_opt.update(visible=False),hough_opt.update(visible=False), normal_opt.update(visible=True)
|
99 |
+
else :
|
100 |
+
return canny_opt.update(visible=False),hough_opt.update(visible=False), normal_opt.update(visible=False)
|
101 |
|
102 |
def get_frames(video_in):
|
103 |
frames = []
|
|
|
154 |
return type + "_result.mp4"
|
155 |
|
156 |
|
157 |
+
def infer(prompt,video_in, control_task, seed_in, trim_value, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold, gif_import):
|
158 |
print(f"""
|
159 |
βββββββββββββββ
|
160 |
{prompt}
|
|
|
176 |
print("set stop frames to: " + str(n_frame))
|
177 |
|
178 |
for i in frames_list[0:int(n_frame)]:
|
179 |
+
controlnet_img = controlnet(i, prompt,control_task, seed_in, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold)
|
180 |
#images = controlnet_img[0]
|
181 |
#rgb_im = images[0].convert("RGB")
|
182 |
|
|
|
250 |
with gr.Blocks(css='style.css') as demo:
|
251 |
with gr.Column(elem_id="col-container"):
|
252 |
gr.HTML(title)
|
253 |
+
gr.HTML("""
|
254 |
+
<a style="display:inline-block" href="https://huggingface.co/spaces/fffiloni/ControlNet-Video?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
|
255 |
+
""", elem_id="duplicate-container")
|
256 |
with gr.Row():
|
257 |
with gr.Column():
|
258 |
video_inp = gr.Video(label="Video source", source="upload", type="filepath", elem_id="input-vid")
|
259 |
video_out = gr.Video(label="ControlNet video result", elem_id="video-output")
|
260 |
+
|
|
|
|
|
261 |
with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
|
262 |
community_icon = gr.HTML(community_icon_html)
|
263 |
loading_icon = gr.HTML(loading_icon_html)
|
264 |
share_button = gr.Button("Share to community", elem_id="share-btn")
|
265 |
+
|
266 |
+
with gr.Accordion("Detailed results", visible=False) as detailed_result:
|
267 |
+
prep_video_out = gr.Video(label="Preprocessor video result", visible=False, elem_id="prep-video-output")
|
268 |
+
files = gr.File(label="Files can be downloaded ;)", visible=False)
|
269 |
+
|
270 |
with gr.Column():
|
271 |
#status = gr.Textbox()
|
272 |
|
273 |
prompt = gr.Textbox(label="Prompt", placeholder="enter prompt", show_label=True, elem_id="prompt-in")
|
274 |
+
|
275 |
with gr.Row():
|
276 |
control_task = gr.Dropdown(label="Control Task", choices=["Canny", "Depth", "Hed", "Hough", "Normal", "Pose", "Scribble", "Seg"], value="Pose", multiselect=False, elem_id="controltask-in")
|
277 |
seed_inp = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, value=123456, elem_id="seed-in")
|
278 |
+
|
279 |
with gr.Row():
|
280 |
+
trim_in = gr.Slider(label="Cut video at (s)", minimun=1, maximum=10, step=1, value=1)
|
281 |
+
|
282 |
with gr.Accordion("Advanced Options", open=False):
|
283 |
+
with gr.Tab("Diffusion Settings"):
|
284 |
+
with gr.Row(visible=False) as canny_opt:
|
285 |
+
low_threshold = gr.Slider(label='Canny low threshold', minimum=1, maximum=255, value=100, step=1)
|
286 |
+
high_threshold = gr.Slider(label='Canny high threshold', minimum=1, maximum=255, value=200, step=1)
|
287 |
+
|
288 |
+
with gr.Row(visible=False) as hough_opt:
|
289 |
+
value_threshold = gr.Slider(label='Hough value threshold (MLSD)', minimum=0.01, maximum=2.0, value=0.1, step=0.01)
|
290 |
+
distance_threshold = gr.Slider(label='Hough distance threshold (MLSD)', minimum=0.01, maximum=20.0, value=0.1, step=0.01)
|
291 |
+
|
292 |
+
with gr.Row(visible=False) as normal_opt:
|
293 |
+
bg_threshold = gr.Slider(label='Normal background threshold', minimum=0.0, maximum=1.0, value=0.4, step=0.01)
|
294 |
+
|
295 |
+
ddim_steps = gr.Slider(label='Steps', minimum=1, maximum=100, value=20, step=1)
|
296 |
+
scale = gr.Slider(label='Guidance Scale', minimum=0.1, maximum=30.0, value=9.0, step=0.1)
|
297 |
|
298 |
+
with gr.Tab("GIF import"):
|
299 |
+
gif_import = gr.File(label="import a GIF instead", file_types=['.gif'])
|
300 |
+
gif_import.change(convert, gif_import, video_inp, queue=False)
|
301 |
+
|
302 |
+
with gr.Tab("Custom Model"):
|
303 |
+
current_base_model = gr.Text(label='Current base model',
|
304 |
+
value=DEFAULT_BASE_MODEL_URL)
|
305 |
+
with gr.Row():
|
306 |
+
with gr.Column():
|
307 |
+
base_model_repo = gr.Text(label='Base model repo',
|
308 |
+
max_lines=1,
|
309 |
+
placeholder=DEFAULT_BASE_MODEL_REPO,
|
310 |
+
interactive=True)
|
311 |
+
base_model_filename = gr.Text(
|
312 |
+
label='Base model file',
|
313 |
+
max_lines=1,
|
314 |
+
placeholder=DEFAULT_BASE_MODEL_FILENAME,
|
315 |
+
interactive=True)
|
316 |
+
change_base_model_button = gr.Button('Change base model')
|
317 |
+
|
318 |
+
gr.HTML(
|
319 |
+
'''<p>You can use other base models by specifying the repository name and filename.<br />
|
320 |
+
The base model must be compatible with Stable Diffusion v1.5.</p>''')
|
321 |
|
322 |
+
change_base_model_button.click(fn=model.set_base_model,
|
323 |
+
inputs=[
|
324 |
+
base_model_repo,
|
325 |
+
base_model_filename,
|
326 |
+
],
|
327 |
+
outputs=current_base_model, queue=False)
|
328 |
|
329 |
+
submit_btn = gr.Button("Generate ControlNet video")
|
|
|
|
|
|
|
330 |
|
331 |
+
inputs = [prompt,video_inp,control_task, seed_inp, trim_in, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold, gif_import]
|
332 |
outputs = [video_out, detailed_result, prep_video_out, files, share_group]
|
333 |
#outputs = [status]
|
334 |
|
335 |
|
336 |
gr.HTML(article)
|
337 |
+
control_task.change(change_task_options, inputs=[control_task], outputs=[canny_opt, hough_opt, normal_opt], queue=False)
|
338 |
submit_btn.click(clean, inputs=[], outputs=[detailed_result, prep_video_out, video_out, files, share_group], queue=False)
|
339 |
submit_btn.click(infer, inputs, outputs)
|
340 |
share_button.click(None, [], [], _js=share_js)
|