Spaces:
Running
on
Zero
Running
on
Zero
刘虹雨
commited on
Commit
·
2b28eee
1
Parent(s):
7009632
update code
Browse files
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
app.py
CHANGED
@@ -394,11 +394,17 @@ def images_to_video(image_folder, output_video, fps=30):
|
|
394 |
# Define input image pattern (expects images named like "%04d.png")
|
395 |
image_pattern = os.path.join(image_folder, "%04d.png")
|
396 |
|
397 |
-
# FFmpeg command to encode video
|
398 |
command = [
|
399 |
-
ffmpeg_exe,
|
400 |
-
'-
|
401 |
-
'-
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
output_video
|
403 |
]
|
404 |
|
@@ -630,9 +636,9 @@ def avatar_generation(items, save_path_base, video_path_input, source_type, is_s
|
|
630 |
images_to_video(save_frames_path_depth, os.path.join(save_path_base, image_name + video_name+ '_depth.mp4'))
|
631 |
|
632 |
logging.info(f"✅ Video generation completed successfully!")
|
633 |
-
return os.path.join(save_path_base, image_name + video_name+ '_out.mp4'), os.path.join(save_path_base, image_name + video_name+'_depth.mp4')
|
634 |
except Exception as e:
|
635 |
-
return None, None
|
636 |
|
637 |
|
638 |
def get_image_base64(path):
|
@@ -802,7 +808,7 @@ def launch_gradio_app():
|
|
802 |
)
|
803 |
gr.HTML(
|
804 |
"""
|
805 |
-
<div style="color:
|
806 |
<strong>🧑🎨 How to use this demo:</strong>
|
807 |
<ol style="margin-top: 10px; padding-left: 20px;">
|
808 |
<li><strong>Select or upload a source image</strong> – this will be the avatar's face.</li>
|
@@ -937,7 +943,7 @@ def launch_gradio_app():
|
|
937 |
label="CFG Scale"
|
938 |
)
|
939 |
strength_slider = gr.Slider(
|
940 |
-
minimum=0.4, maximum=0.85, value=0.
|
941 |
label="SDEdit Strength"
|
942 |
)
|
943 |
style_button = gr.Button("🎨 Apply Style", interactive=False)
|
@@ -975,16 +981,16 @@ def launch_gradio_app():
|
|
975 |
def apply_style_and_mark(processed_image, style_choice, cfg, strength, working_dir, image_name_true):
|
976 |
try:
|
977 |
styled = style_transfer(processed_image, styles[style_choice], cfg, strength, working_dir, image_name_true)
|
978 |
-
return styled, True
|
979 |
except Exception as e:
|
980 |
-
return None, True
|
981 |
|
982 |
def process_image_and_enable_style(input_image, source_type, is_styled, wd):
|
983 |
try:
|
984 |
processed_result, updated_source_type, image_name_true = process_image(input_image, source_type, is_styled, wd)
|
985 |
-
return processed_result, updated_source_type, gr.update(interactive=True), gr.update(interactive=True), image_name_true
|
986 |
except Exception as e:
|
987 |
-
return None, updated_source_type, gr.update(interactive=False), gr.update(interactive=False), image_name_true
|
988 |
|
989 |
processed_image_button.click(
|
990 |
fn=prepare_working_dir,
|
@@ -994,18 +1000,18 @@ def launch_gradio_app():
|
|
994 |
).success(
|
995 |
fn=process_image_and_enable_style,
|
996 |
inputs=[input_image, source_type, is_styled, working_dir],
|
997 |
-
outputs=[processed_image, source_type, style_button, submit, image_name_true
|
998 |
queue=True
|
999 |
)
|
1000 |
style_button.click(
|
1001 |
fn=apply_style_and_mark,
|
1002 |
inputs=[processed_image, style_choice, cfg_slider, strength_slider, working_dir, image_name_true],
|
1003 |
-
outputs=[style_image, is_styled
|
1004 |
)
|
1005 |
submit.click(
|
1006 |
fn=avatar_generation,
|
1007 |
inputs=[processed_image, working_dir, video_input, source_type, is_styled, style_image, image_name_true],
|
1008 |
-
outputs=[output_video, output_video_1
|
1009 |
queue=True
|
1010 |
)
|
1011 |
|
|
|
394 |
# Define input image pattern (expects images named like "%04d.png")
|
395 |
image_pattern = os.path.join(image_folder, "%04d.png")
|
396 |
|
397 |
+
# FFmpeg command to encode video (with -y to overwrite)
|
398 |
command = [
|
399 |
+
ffmpeg_exe,
|
400 |
+
'-y', # ✅ Overwrite output file without asking
|
401 |
+
'-framerate', str(fps),
|
402 |
+
'-i', image_pattern,
|
403 |
+
'-c:v', 'libx264',
|
404 |
+
'-preset', 'slow',
|
405 |
+
'-crf', '18',
|
406 |
+
'-pix_fmt', 'yuv420p',
|
407 |
+
'-b:v', '5000k',
|
408 |
output_video
|
409 |
]
|
410 |
|
|
|
636 |
images_to_video(save_frames_path_depth, os.path.join(save_path_base, image_name + video_name+ '_depth.mp4'))
|
637 |
|
638 |
logging.info(f"✅ Video generation completed successfully!")
|
639 |
+
return os.path.join(save_path_base, image_name + video_name+ '_out.mp4'), os.path.join(save_path_base, image_name + video_name+'_depth.mp4')
|
640 |
except Exception as e:
|
641 |
+
return None, None
|
642 |
|
643 |
|
644 |
def get_image_base64(path):
|
|
|
808 |
)
|
809 |
gr.HTML(
|
810 |
"""
|
811 |
+
<div style="color: inherit; text-align: left; font-size: 16px; line-height: 1.6; margin-top: 20px; padding: 16px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.1); background-color: rgba(240, 240, 240, 0.6); backdrop-filter: blur(2px);">
|
812 |
<strong>🧑🎨 How to use this demo:</strong>
|
813 |
<ol style="margin-top: 10px; padding-left: 20px;">
|
814 |
<li><strong>Select or upload a source image</strong> – this will be the avatar's face.</li>
|
|
|
943 |
label="CFG Scale"
|
944 |
)
|
945 |
strength_slider = gr.Slider(
|
946 |
+
minimum=0.4, maximum=0.85, value=0.75, step=0.05,
|
947 |
label="SDEdit Strength"
|
948 |
)
|
949 |
style_button = gr.Button("🎨 Apply Style", interactive=False)
|
|
|
981 |
def apply_style_and_mark(processed_image, style_choice, cfg, strength, working_dir, image_name_true):
|
982 |
try:
|
983 |
styled = style_transfer(processed_image, styles[style_choice], cfg, strength, working_dir, image_name_true)
|
984 |
+
return styled, True
|
985 |
except Exception as e:
|
986 |
+
return None, True
|
987 |
|
988 |
def process_image_and_enable_style(input_image, source_type, is_styled, wd):
|
989 |
try:
|
990 |
processed_result, updated_source_type, image_name_true = process_image(input_image, source_type, is_styled, wd)
|
991 |
+
return processed_result, updated_source_type, gr.update(interactive=True), gr.update(interactive=True), image_name_true
|
992 |
except Exception as e:
|
993 |
+
return None, updated_source_type, gr.update(interactive=False), gr.update(interactive=False), image_name_true
|
994 |
|
995 |
processed_image_button.click(
|
996 |
fn=prepare_working_dir,
|
|
|
1000 |
).success(
|
1001 |
fn=process_image_and_enable_style,
|
1002 |
inputs=[input_image, source_type, is_styled, working_dir],
|
1003 |
+
outputs=[processed_image, source_type, style_button, submit, image_name_true],
|
1004 |
queue=True
|
1005 |
)
|
1006 |
style_button.click(
|
1007 |
fn=apply_style_and_mark,
|
1008 |
inputs=[processed_image, style_choice, cfg_slider, strength_slider, working_dir, image_name_true],
|
1009 |
+
outputs=[style_image, is_styled]
|
1010 |
)
|
1011 |
submit.click(
|
1012 |
fn=avatar_generation,
|
1013 |
inputs=[processed_image, working_dir, video_input, source_type, is_styled, style_image, image_name_true],
|
1014 |
+
outputs=[output_video, output_video_1], # ⏳ 稍后展示视频
|
1015 |
queue=True
|
1016 |
)
|
1017 |
|