yerang commited on
Commit
c072e5f
1 Parent(s): 670db78

Rename app.py to app_ori.py

Browse files
Files changed (1) hide show
  1. 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
- gr.HTML(load_description(title_md))
84
- gr.Markdown(load_description("assets/gradio_description_upload.md"))
85
- with gr.Row():
86
- with gr.Accordion(open=True, label="Source Portrait"):
87
- image_input = gr.Image(type="filepath")
88
- gr.Examples(
89
- examples=[
90
- [osp.join(example_portrait_dir, "s9.jpg")],
91
- [osp.join(example_portrait_dir, "s6.jpg")],
92
- [osp.join(example_portrait_dir, "s10.jpg")],
93
- [osp.join(example_portrait_dir, "s5.jpg")],
94
- [osp.join(example_portrait_dir, "s7.jpg")],
95
- [osp.join(example_portrait_dir, "s12.jpg")],
96
- [osp.join(example_portrait_dir, "s22.jpg")],
97
- ],
98
- inputs=[image_input],
99
- cache_examples=False,
100
- )
101
- with gr.Accordion(open=True, label="Driving Video"):
102
- video_input = gr.Video()
103
- gr.Examples(
104
- examples=[
105
- [osp.join(example_video_dir, "d0.mp4")],
106
- [osp.join(example_video_dir, "d18.mp4")],
107
- [osp.join(example_video_dir, "d19.mp4")],
108
- [osp.join(example_video_dir, "d14_trim.mp4")],
109
- [osp.join(example_video_dir, "d6_trim.mp4")],
110
- ],
111
- inputs=[video_input],
112
- cache_examples=False,
113
- )
114
- with gr.Row():
115
- with gr.Accordion(open=False, label="Animation Instructions and Options"):
116
- gr.Markdown(load_description("assets/gradio_description_animation.md"))
117
- with gr.Row():
118
- flag_relative_input = gr.Checkbox(value=True, label="relative motion")
119
- flag_do_crop_input = gr.Checkbox(value=True, label="do crop")
120
- flag_remap_input = gr.Checkbox(value=True, label="paste-back")
121
- gr.Markdown(load_description("assets/gradio_description_animate_clear.md"))
122
- with gr.Row():
123
- with gr.Column():
124
- process_button_animation = gr.Button("🚀 Animate", variant="primary")
125
- with gr.Column():
126
- process_button_reset = gr.ClearButton([image_input, video_input, output_video, output_video_concat], value="🧹 Clear")
127
- with gr.Row():
128
- with gr.Column():
129
- with gr.Accordion(open=True, label="The animated video in the original image space"):
130
- output_video.render()
131
- with gr.Column():
132
- with gr.Accordion(open=True, label="The animated video"):
133
- output_video_concat.render()
134
- with gr.Row():
135
- # Examples
136
- gr.Markdown("## You could also choose the examples below by one click ⬇️")
137
- with gr.Row():
138
- gr.Examples(
139
- examples=data_examples,
140
- fn=gpu_wrapped_execute_video,
141
- inputs=[
142
- image_input,
143
- video_input,
144
- flag_relative_input,
145
- flag_do_crop_input,
146
- flag_remap_input
147
- ],
148
- outputs=[output_image, output_image_paste_back],
149
- examples_per_page=6,
150
- cache_examples=False,
151
- )
152
- gr.Markdown(load_description("assets/gradio_description_retargeting.md"), visible=True)
153
- with gr.Row(visible=True):
154
- eye_retargeting_slider.render()
155
- lip_retargeting_slider.render()
156
- with gr.Row(visible=True):
157
- process_button_retargeting = gr.Button("🚗 Retargeting", variant="primary")
158
- process_button_reset_retargeting = gr.ClearButton(
159
- [
160
- eye_retargeting_slider,
161
- lip_retargeting_slider,
162
- retargeting_input_image,
163
- output_image,
164
- output_image_paste_back
165
- ],
166
- value="🧹 Clear"
167
- )
168
- with gr.Row(visible=True):
169
- with gr.Column():
170
- with gr.Accordion(open=True, label="Retargeting Input"):
171
- retargeting_input_image.render()
172
- gr.Examples(
173
- examples=[
174
- [osp.join(example_portrait_dir, "s9.jpg")],
175
- [osp.join(example_portrait_dir, "s6.jpg")],
176
- [osp.join(example_portrait_dir, "s10.jpg")],
177
- [osp.join(example_portrait_dir, "s5.jpg")],
178
- [osp.join(example_portrait_dir, "s7.jpg")],
179
- [osp.join(example_portrait_dir, "s12.jpg")],
180
- [osp.join(example_portrait_dir, "s22.jpg")],
181
- ],
182
- inputs=[retargeting_input_image],
183
- cache_examples=False,
184
- )
185
- with gr.Column():
186
- with gr.Accordion(open=True, label="Retargeting Result"):
187
- output_image.render()
188
- with gr.Column():
189
- with gr.Accordion(open=True, label="Paste-back Result"):
190
- output_image_paste_back.render()
191
- # binding functions for buttons
192
- process_button_retargeting.click(
193
- # fn=gradio_pipeline.execute_image,
194
- fn=gpu_wrapped_execute_image,
195
- inputs=[eye_retargeting_slider, lip_retargeting_slider, retargeting_input_image, flag_do_crop_input],
196
- outputs=[output_image, output_image_paste_back],
197
- show_progress=True
198
- )
199
- process_button_animation.click(
200
- fn=gpu_wrapped_execute_video,
201
- inputs=[
202
- image_input,
203
- video_input,
204
- flag_relative_input,
205
- flag_do_crop_input,
206
- flag_remap_input
207
- ],
208
- outputs=[output_video, output_video_concat],
209
- show_progress=True
210
- )
211
- # image_input.change(
212
- # fn=gradio_pipeline.prepare_retargeting,
213
- # inputs=image_input,
214
- # outputs=[eye_retargeting_slider, lip_retargeting_slider, retargeting_input_image]
215
- # )
216
- video_input.upload(
217
- fn=is_square_video,
218
- inputs=video_input,
219
- outputs=video_input
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,