Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,7 +80,7 @@ def swap_video_fct(video_path, output_path, source_face, destination_face, toler
|
|
| 80 |
dest_face = sorted(dest_face, key = lambda x : x.bbox[0])
|
| 81 |
|
| 82 |
if(len(dest_face) == 0):
|
| 83 |
-
print("No dest face found")
|
| 84 |
return -1
|
| 85 |
|
| 86 |
dest_face_feats = []
|
|
@@ -91,7 +91,7 @@ def swap_video_fct(video_path, output_path, source_face, destination_face, toler
|
|
| 91 |
src_face = app.get(source_face)
|
| 92 |
src_face = sorted(src_face, key = lambda x : x.bbox[0])
|
| 93 |
if(len(src_face) == 0):
|
| 94 |
-
print("No source face found")
|
| 95 |
return -1
|
| 96 |
|
| 97 |
cap = cv2.VideoCapture(video_path)
|
|
@@ -115,7 +115,7 @@ def swap_video_fct(video_path, output_path, source_face, destination_face, toler
|
|
| 115 |
for_range = range(preview-1,preview)
|
| 116 |
|
| 117 |
for i in for_range:
|
| 118 |
-
progress(i/frame_count, desc="Processing")
|
| 119 |
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
| 120 |
ret, frame = cap.read()
|
| 121 |
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
@@ -170,44 +170,44 @@ def show_preview(video_path, frame_number):
|
|
| 170 |
return frame
|
| 171 |
|
| 172 |
def create_interface():
|
| 173 |
-
title = 'Face Swap UI'
|
| 174 |
with gr.Blocks(analytics_enabled=False, title=title) as face_swap_ui:
|
| 175 |
-
with gr.Tab("Swap Face Image"):
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column():
|
| 178 |
-
image_input = gr.Image(label='Input Image (Click to select a face)', scale=0.5)
|
| 179 |
with gr.Row():
|
| 180 |
-
analyze_button = gr.Button("Analyze")
|
| 181 |
with gr.Row():
|
| 182 |
with gr.Column():
|
| 183 |
-
face_num = gr.Number(label='Recognized Faces')
|
| 184 |
-
face_index_num = gr.Number(label='Face Index', precision=0)
|
| 185 |
-
selected_face = gr.Image(label='Face to swap', interactive=False)
|
| 186 |
-
swap_face = gr.Image(label='Swap Face')
|
| 187 |
-
swap_button = gr.Button("Swap")
|
| 188 |
with gr.Column():
|
| 189 |
-
image_output = gr.Image(label='Output Image',interactive=False)
|
| 190 |
#text_output = gr.Textbox(placeholder="What is your name?")
|
| 191 |
swap_button.click(fn=swap_face_fct, inputs=[image_input, face_index_num, swap_face], outputs=[image_output])
|
| 192 |
image_input.select(select_handler, image_input, [selected_face, face_index_num])
|
| 193 |
analyze_button.click(fn=get_faces, inputs=image_input, outputs=[image_input,face_num])
|
| 194 |
-
with gr.Tab("Swap Face Video"):
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column():
|
| 197 |
source_video = gr.Video()
|
| 198 |
-
video_info = gr.Textbox(label="Video Information")
|
| 199 |
-
gr.Markdown("Select a frame for preview with the slider. Then select the face which should be swapped by clicking on it with the cursor")
|
| 200 |
-
video_position = gr.Slider(label="Frame preview",interactive=True)
|
| 201 |
-
frame_preview = gr.Image(label="Frame preview")
|
| 202 |
-
face_index = gr.Textbox(label="Face-Index",interactive=False)
|
| 203 |
with gr.Row():
|
| 204 |
-
dest_face_vid = gr.Image(label="Face
|
| 205 |
-
source_face_vid = gr.Image(label="New Face")
|
| 206 |
-
gr.Markdown("The higher the tolerance the more likely a wrong face will be swapped. 30-40 is a good starting point.")
|
| 207 |
-
face_tolerance = gr.Slider(label="Tolerance",value=40,interactive=True)
|
| 208 |
-
preview_video = gr.Button("Preview")
|
| 209 |
-
video_file_path = gr.Text(label="Output Video path incl. file.mp4 (when left empty it will be put in the gradio temp dir)")
|
| 210 |
-
process_video = gr.Button("Process")
|
| 211 |
with gr.Column():
|
| 212 |
with gr.Column(scale=1):
|
| 213 |
image_output = gr.Image()
|
|
|
|
| 80 |
dest_face = sorted(dest_face, key = lambda x : x.bbox[0])
|
| 81 |
|
| 82 |
if(len(dest_face) == 0):
|
| 83 |
+
print("๐ก No dest face found")
|
| 84 |
return -1
|
| 85 |
|
| 86 |
dest_face_feats = []
|
|
|
|
| 91 |
src_face = app.get(source_face)
|
| 92 |
src_face = sorted(src_face, key = lambda x : x.bbox[0])
|
| 93 |
if(len(src_face) == 0):
|
| 94 |
+
print("๐จ No source face found")
|
| 95 |
return -1
|
| 96 |
|
| 97 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
| 115 |
for_range = range(preview-1,preview)
|
| 116 |
|
| 117 |
for i in for_range:
|
| 118 |
+
progress(i/frame_count, desc="โณProcessing")
|
| 119 |
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
| 120 |
ret, frame = cap.read()
|
| 121 |
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
|
|
| 170 |
return frame
|
| 171 |
|
| 172 |
def create_interface():
|
| 173 |
+
title = '๐งธ ๐งธFace Swap UI'
|
| 174 |
with gr.Blocks(analytics_enabled=False, title=title) as face_swap_ui:
|
| 175 |
+
with gr.Tab("๐ Swap Face Image"):
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column():
|
| 178 |
+
image_input = gr.Image(label='๐๏ธInput Image (๐บ Click to select a face)', scale=0.5)
|
| 179 |
with gr.Row():
|
| 180 |
+
analyze_button = gr.Button("โ Analyze")
|
| 181 |
with gr.Row():
|
| 182 |
with gr.Column():
|
| 183 |
+
face_num = gr.Number(label='๐น Recognized Faces')
|
| 184 |
+
face_index_num = gr.Number(label='๐ Face Index', precision=0)
|
| 185 |
+
selected_face = gr.Image(label='๐Face to swap', interactive=False)
|
| 186 |
+
swap_face = gr.Image(label='๐งชSwap Face')
|
| 187 |
+
swap_button = gr.Button("๐งฉ Swap")
|
| 188 |
with gr.Column():
|
| 189 |
+
image_output = gr.Image(label='๐คOutput Image',interactive=False)
|
| 190 |
#text_output = gr.Textbox(placeholder="What is your name?")
|
| 191 |
swap_button.click(fn=swap_face_fct, inputs=[image_input, face_index_num, swap_face], outputs=[image_output])
|
| 192 |
image_input.select(select_handler, image_input, [selected_face, face_index_num])
|
| 193 |
analyze_button.click(fn=get_faces, inputs=image_input, outputs=[image_input,face_num])
|
| 194 |
+
with gr.Tab("๐บSwap Face Video"):
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column():
|
| 197 |
source_video = gr.Video()
|
| 198 |
+
video_info = gr.Textbox(label="๐กVideo Information")
|
| 199 |
+
gr.Markdown("๐ ๏ธSelect a frame for preview with the slider. Then select the face which should be swapped by clicking on it with the cursor")
|
| 200 |
+
video_position = gr.Slider(label="๐Frame preview",interactive=True)
|
| 201 |
+
frame_preview = gr.Image(label="๐Frame preview")
|
| 202 |
+
face_index = gr.Textbox(label="๐Face-Index",interactive=False)
|
| 203 |
with gr.Row():
|
| 204 |
+
dest_face_vid = gr.Image(label="๐Face to swap",interactive=True)
|
| 205 |
+
source_face_vid = gr.Image(label="๐ฎNew Face")
|
| 206 |
+
gr.Markdown("๐The higher the tolerance the more likely a wrong face will be swapped. 30-40 is a good starting point.")
|
| 207 |
+
face_tolerance = gr.Slider(label="โณTolerance",value=40,interactive=True)
|
| 208 |
+
preview_video = gr.Button("๐ชPreview")
|
| 209 |
+
video_file_path = gr.Text(label="๐ณ๏ธOutput Video path incl. file.mp4 (when left empty it will be put in the gradio temp dir)")
|
| 210 |
+
process_video = gr.Button("โProcess")
|
| 211 |
with gr.Column():
|
| 212 |
with gr.Column(scale=1):
|
| 213 |
image_output = gr.Image()
|