Spaces:
Running
on
Zero
Running
on
Zero
Rename app.py to app_ori.py
Browse files- app.py → app_ori.py +163 -139
app.py → app_ori.py
RENAMED
|
@@ -19,6 +19,30 @@ import cv2
|
|
| 19 |
# folder_url = f"https://drive.google.com/drive/folders/1UtKgzKjFAOmZkhNK-OYT0caJ_w2XAnib"
|
| 20 |
# gdown.download_folder(url=folder_url, output="pretrained_weights", quiet=False)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def partial_fields(target_class, kwargs):
|
| 23 |
return target_class(**{k: v for k, v in kwargs.items() if hasattr(target_class, k)})
|
| 24 |
|
|
@@ -79,145 +103,145 @@ output_image_paste_back = gr.Image(type="numpy")
|
|
| 79 |
output_video = gr.Video()
|
| 80 |
output_video_concat = gr.Video()
|
| 81 |
|
| 82 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
|
| 222 |
demo.launch(
|
| 223 |
server_port=args.server_port,
|
|
|
|
| 19 |
# folder_url = f"https://drive.google.com/drive/folders/1UtKgzKjFAOmZkhNK-OYT0caJ_w2XAnib"
|
| 20 |
# gdown.download_folder(url=folder_url, output="pretrained_weights", quiet=False)
|
| 21 |
|
| 22 |
+
|
| 23 |
+
import sys
|
| 24 |
+
sys.path.append('/home/user/.local/lib/python3.10/site-packages')
|
| 25 |
+
sys.path.append('/home/user/.local/lib/python3.10/site-packages/stf_alternative/src/stf_alternative')
|
| 26 |
+
sys.path.append('/home/user/.local/lib/python3.10/site-packages/stf_tools/src/stf_tools')
|
| 27 |
+
sys.path.append('/home/user/app/')
|
| 28 |
+
sys.path.append('/home/user/app/stf/')
|
| 29 |
+
sys.path.append('/home/user/app/stf/stf_alternative/')
|
| 30 |
+
sys.path.append('/home/user/app/stf/stf_alternative/src/stf_alternative')
|
| 31 |
+
sys.path.append('/home/user/app/stf/stf_tools')
|
| 32 |
+
sys.path.append('/home/user/app/stf/stf_tools/src/stf_tools')
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# CUDA 경로를 환경 변수로 설정
|
| 37 |
+
os.environ['PATH'] = '/usr/local/cuda/bin:' + os.environ.get('PATH', '')
|
| 38 |
+
os.environ['LD_LIBRARY_PATH'] = '/usr/local/cuda/lib64:' + os.environ.get('LD_LIBRARY_PATH', '')
|
| 39 |
+
# 확인용 출력
|
| 40 |
+
print("PATH:", os.environ['PATH'])
|
| 41 |
+
print("LD_LIBRARY_PATH:", os.environ['LD_LIBRARY_PATH'])
|
| 42 |
+
|
| 43 |
+
from stf_utils import STFPipeline
|
| 44 |
+
|
| 45 |
+
|
| 46 |
def partial_fields(target_class, kwargs):
|
| 47 |
return target_class(**{k: v for k, v in kwargs.items() if hasattr(target_class, k)})
|
| 48 |
|
|
|
|
| 103 |
output_video = gr.Video()
|
| 104 |
output_video_concat = gr.Video()
|
| 105 |
|
| 106 |
+
# with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 107 |
+
# gr.HTML(load_description(title_md))
|
| 108 |
+
# gr.Markdown(load_description("assets/gradio_description_upload.md"))
|
| 109 |
+
# with gr.Row():
|
| 110 |
+
# with gr.Accordion(open=True, label="Source Portrait"):
|
| 111 |
+
# image_input = gr.Image(type="filepath")
|
| 112 |
+
# gr.Examples(
|
| 113 |
+
# examples=[
|
| 114 |
+
# [osp.join(example_portrait_dir, "s9.jpg")],
|
| 115 |
+
# [osp.join(example_portrait_dir, "s6.jpg")],
|
| 116 |
+
# [osp.join(example_portrait_dir, "s10.jpg")],
|
| 117 |
+
# [osp.join(example_portrait_dir, "s5.jpg")],
|
| 118 |
+
# [osp.join(example_portrait_dir, "s7.jpg")],
|
| 119 |
+
# [osp.join(example_portrait_dir, "s12.jpg")],
|
| 120 |
+
# [osp.join(example_portrait_dir, "s22.jpg")],
|
| 121 |
+
# ],
|
| 122 |
+
# inputs=[image_input],
|
| 123 |
+
# cache_examples=False,
|
| 124 |
+
# )
|
| 125 |
+
# with gr.Accordion(open=True, label="Driving Video"):
|
| 126 |
+
# video_input = gr.Video()
|
| 127 |
+
# gr.Examples(
|
| 128 |
+
# examples=[
|
| 129 |
+
# [osp.join(example_video_dir, "d0.mp4")],
|
| 130 |
+
# [osp.join(example_video_dir, "d18.mp4")],
|
| 131 |
+
# [osp.join(example_video_dir, "d19.mp4")],
|
| 132 |
+
# [osp.join(example_video_dir, "d14_trim.mp4")],
|
| 133 |
+
# [osp.join(example_video_dir, "d6_trim.mp4")],
|
| 134 |
+
# ],
|
| 135 |
+
# inputs=[video_input],
|
| 136 |
+
# cache_examples=False,
|
| 137 |
+
# )
|
| 138 |
+
# with gr.Row():
|
| 139 |
+
# with gr.Accordion(open=False, label="Animation Instructions and Options"):
|
| 140 |
+
# gr.Markdown(load_description("assets/gradio_description_animation.md"))
|
| 141 |
+
# with gr.Row():
|
| 142 |
+
# flag_relative_input = gr.Checkbox(value=True, label="relative motion")
|
| 143 |
+
# flag_do_crop_input = gr.Checkbox(value=True, label="do crop")
|
| 144 |
+
# flag_remap_input = gr.Checkbox(value=True, label="paste-back")
|
| 145 |
+
# gr.Markdown(load_description("assets/gradio_description_animate_clear.md"))
|
| 146 |
+
# with gr.Row():
|
| 147 |
+
# with gr.Column():
|
| 148 |
+
# process_button_animation = gr.Button("🚀 Animate", variant="primary")
|
| 149 |
+
# with gr.Column():
|
| 150 |
+
# process_button_reset = gr.ClearButton([image_input, video_input, output_video, output_video_concat], value="🧹 Clear")
|
| 151 |
+
# with gr.Row():
|
| 152 |
+
# with gr.Column():
|
| 153 |
+
# with gr.Accordion(open=True, label="The animated video in the original image space"):
|
| 154 |
+
# output_video.render()
|
| 155 |
+
# with gr.Column():
|
| 156 |
+
# with gr.Accordion(open=True, label="The animated video"):
|
| 157 |
+
# output_video_concat.render()
|
| 158 |
+
# with gr.Row():
|
| 159 |
+
# # Examples
|
| 160 |
+
# gr.Markdown("## You could also choose the examples below by one click ⬇️")
|
| 161 |
+
# with gr.Row():
|
| 162 |
+
# gr.Examples(
|
| 163 |
+
# examples=data_examples,
|
| 164 |
+
# fn=gpu_wrapped_execute_video,
|
| 165 |
+
# inputs=[
|
| 166 |
+
# image_input,
|
| 167 |
+
# video_input,
|
| 168 |
+
# flag_relative_input,
|
| 169 |
+
# flag_do_crop_input,
|
| 170 |
+
# flag_remap_input
|
| 171 |
+
# ],
|
| 172 |
+
# outputs=[output_image, output_image_paste_back],
|
| 173 |
+
# examples_per_page=6,
|
| 174 |
+
# cache_examples=False,
|
| 175 |
+
# )
|
| 176 |
+
# gr.Markdown(load_description("assets/gradio_description_retargeting.md"), visible=True)
|
| 177 |
+
# with gr.Row(visible=True):
|
| 178 |
+
# eye_retargeting_slider.render()
|
| 179 |
+
# lip_retargeting_slider.render()
|
| 180 |
+
# with gr.Row(visible=True):
|
| 181 |
+
# process_button_retargeting = gr.Button("🚗 Retargeting", variant="primary")
|
| 182 |
+
# process_button_reset_retargeting = gr.ClearButton(
|
| 183 |
+
# [
|
| 184 |
+
# eye_retargeting_slider,
|
| 185 |
+
# lip_retargeting_slider,
|
| 186 |
+
# retargeting_input_image,
|
| 187 |
+
# output_image,
|
| 188 |
+
# output_image_paste_back
|
| 189 |
+
# ],
|
| 190 |
+
# value="🧹 Clear"
|
| 191 |
+
# )
|
| 192 |
+
# with gr.Row(visible=True):
|
| 193 |
+
# with gr.Column():
|
| 194 |
+
# with gr.Accordion(open=True, label="Retargeting Input"):
|
| 195 |
+
# retargeting_input_image.render()
|
| 196 |
+
# gr.Examples(
|
| 197 |
+
# examples=[
|
| 198 |
+
# [osp.join(example_portrait_dir, "s9.jpg")],
|
| 199 |
+
# [osp.join(example_portrait_dir, "s6.jpg")],
|
| 200 |
+
# [osp.join(example_portrait_dir, "s10.jpg")],
|
| 201 |
+
# [osp.join(example_portrait_dir, "s5.jpg")],
|
| 202 |
+
# [osp.join(example_portrait_dir, "s7.jpg")],
|
| 203 |
+
# [osp.join(example_portrait_dir, "s12.jpg")],
|
| 204 |
+
# [osp.join(example_portrait_dir, "s22.jpg")],
|
| 205 |
+
# ],
|
| 206 |
+
# inputs=[retargeting_input_image],
|
| 207 |
+
# cache_examples=False,
|
| 208 |
+
# )
|
| 209 |
+
# with gr.Column():
|
| 210 |
+
# with gr.Accordion(open=True, label="Retargeting Result"):
|
| 211 |
+
# output_image.render()
|
| 212 |
+
# with gr.Column():
|
| 213 |
+
# with gr.Accordion(open=True, label="Paste-back Result"):
|
| 214 |
+
# output_image_paste_back.render()
|
| 215 |
+
# # binding functions for buttons
|
| 216 |
+
# process_button_retargeting.click(
|
| 217 |
+
# # fn=gradio_pipeline.execute_image,
|
| 218 |
+
# fn=gpu_wrapped_execute_image,
|
| 219 |
+
# inputs=[eye_retargeting_slider, lip_retargeting_slider, retargeting_input_image, flag_do_crop_input],
|
| 220 |
+
# outputs=[output_image, output_image_paste_back],
|
| 221 |
+
# show_progress=True
|
| 222 |
+
# )
|
| 223 |
+
# process_button_animation.click(
|
| 224 |
+
# fn=gpu_wrapped_execute_video,
|
| 225 |
+
# inputs=[
|
| 226 |
+
# image_input,
|
| 227 |
+
# video_input,
|
| 228 |
+
# flag_relative_input,
|
| 229 |
+
# flag_do_crop_input,
|
| 230 |
+
# flag_remap_input
|
| 231 |
+
# ],
|
| 232 |
+
# outputs=[output_video, output_video_concat],
|
| 233 |
+
# show_progress=True
|
| 234 |
+
# )
|
| 235 |
+
# # image_input.change(
|
| 236 |
+
# # fn=gradio_pipeline.prepare_retargeting,
|
| 237 |
+
# # inputs=image_input,
|
| 238 |
+
# # outputs=[eye_retargeting_slider, lip_retargeting_slider, retargeting_input_image]
|
| 239 |
+
# # )
|
| 240 |
+
# video_input.upload(
|
| 241 |
+
# fn=is_square_video,
|
| 242 |
+
# inputs=video_input,
|
| 243 |
+
# outputs=video_input
|
| 244 |
+
# )
|
| 245 |
|
| 246 |
demo.launch(
|
| 247 |
server_port=args.server_port,
|