Spaces:
Running
Running
Commit
·
6a28782
1
Parent(s):
37ea042
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import gradio
|
| 3 |
import subprocess as sp
|
| 4 |
import os
|
| 5 |
|
|
@@ -17,12 +16,22 @@ def run(*args):
|
|
| 17 |
frame_processor = rest_args[0]
|
| 18 |
selected_frame_processors = ' '.join(frame_processor)
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
if skip_audio:
|
| 27 |
cmd += " --skip-audio"
|
| 28 |
if keep_fps:
|
|
@@ -36,6 +45,13 @@ def run(*args):
|
|
| 36 |
return output
|
| 37 |
except Exception as e:
|
| 38 |
return f"An error occurred: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def get_theme() -> gr.Theme:
|
| 41 |
return gr.themes.Soft(
|
|
@@ -53,55 +69,59 @@ with gr.Blocks(theme=get_theme(), title="DeepFakeAI 1.0.0") as ui:
|
|
| 53 |
gr.HTML('<center><a href="codegenius.me">DeepFakeAI 1.0.0</a></center>')
|
| 54 |
|
| 55 |
with gr.Box():
|
| 56 |
-
|
|
|
|
| 57 |
choices = ['face_swapper', 'face_enhancer', 'frame_enhancer'],
|
| 58 |
label = 'FRAME PROCESSORS',
|
| 59 |
value = ['face_swapper'] # Default value
|
| 60 |
)
|
| 61 |
-
|
| 62 |
-
with gr.Tab("Image:"):
|
| 63 |
-
source_image = gr.Image(type="filepath", label="Source Image")
|
| 64 |
-
target_image = gr.Image(type="filepath", label="Target Image")
|
| 65 |
-
image_button = gr.Button("Start")
|
| 66 |
-
image_output = gr.Image()
|
| 67 |
|
| 68 |
-
image_button.click(
|
| 69 |
-
run,
|
| 70 |
-
inputs=[source_image, target_image, frame_processor_checkbox],
|
| 71 |
-
outputs=image_output
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
with gr.Tab("Video:"):
|
| 75 |
-
source_image_video = gr.Image(type="filepath", label="Source Image")
|
| 76 |
-
target_video = gr.Video(label="Target Video")
|
| 77 |
-
with gr.Box():
|
| 78 |
-
skip_audio = gr.Checkbox(label="SKIP AUDIO")
|
| 79 |
-
keep_fps = gr.Checkbox(label="KEEP FPS")
|
| 80 |
-
keep_temp = gr.Checkbox(label="KEEP TEMP")
|
| 81 |
-
video_button = gr.Button("Start")
|
| 82 |
-
video_output = gr.Video()
|
| 83 |
-
video_button.click(
|
| 84 |
-
run,
|
| 85 |
-
inputs=[source_image_video, target_video, frame_processor_checkbox, skip_audio, keep_fps, keep_temp],
|
| 86 |
-
outputs=video_output
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
# Additional UI components ...
|
| 90 |
with gr.Box():
|
|
|
|
| 91 |
face_analyser_direction_dropdown = gr.Dropdown(
|
| 92 |
-
label = '
|
| 93 |
choices = ['left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small'],
|
| 94 |
value = 'left-right'
|
| 95 |
)
|
| 96 |
face_analyser_age_dropdown = gr.Dropdown(
|
| 97 |
-
label = '
|
| 98 |
choices = ['none'] + ['child', 'young', 'adult', 'old'],
|
| 99 |
value = 'none'
|
| 100 |
)
|
| 101 |
face_analyser_gender_dropdown = gr.Dropdown(
|
| 102 |
-
label = '
|
| 103 |
choices = ['none'] + ['male', 'female'],
|
| 104 |
value = 'none'
|
| 105 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
ui.launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import subprocess as sp
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 16 |
frame_processor = rest_args[0]
|
| 17 |
selected_frame_processors = ' '.join(frame_processor)
|
| 18 |
|
| 19 |
+
face_analyser_direction = rest_args[1]
|
| 20 |
+
face_analyser_age = rest_args[2]
|
| 21 |
+
face_analyser_gender = rest_args[3]
|
| 22 |
|
| 23 |
+
cmd = (
|
| 24 |
+
f"python run.py --execution-providers cuda -s {source} -t {target} -o {output} "
|
| 25 |
+
f"--frame-processors {selected_frame_processors} "
|
| 26 |
+
f"--face-analyser-direction {face_analyser_direction} "
|
| 27 |
+
f"--face-analyser-age {face_analyser_age} "
|
| 28 |
+
f"--face-analyser-gender {face_analyser_gender}"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if len(rest_args) > 4:
|
| 32 |
+
skip_audio = rest_args[4]
|
| 33 |
+
keep_fps = rest_args[5]
|
| 34 |
+
keep_temp = rest_args[6]
|
| 35 |
if skip_audio:
|
| 36 |
cmd += " --skip-audio"
|
| 37 |
if keep_fps:
|
|
|
|
| 45 |
return output
|
| 46 |
except Exception as e:
|
| 47 |
return f"An error occurred: {str(e)}"
|
| 48 |
+
def clear_output(output):
|
| 49 |
+
if os.path.exists(output):
|
| 50 |
+
os.remove(output)
|
| 51 |
+
return "Output file deleted"
|
| 52 |
+
else:
|
| 53 |
+
return "Output file does not exist"
|
| 54 |
+
|
| 55 |
|
| 56 |
def get_theme() -> gr.Theme:
|
| 57 |
return gr.themes.Soft(
|
|
|
|
| 69 |
gr.HTML('<center><a href="codegenius.me">DeepFakeAI 1.0.0</a></center>')
|
| 70 |
|
| 71 |
with gr.Box():
|
| 72 |
+
with gr.Column(scale=3):
|
| 73 |
+
frame_processor_checkbox = gr.CheckboxGroup(
|
| 74 |
choices = ['face_swapper', 'face_enhancer', 'frame_enhancer'],
|
| 75 |
label = 'FRAME PROCESSORS',
|
| 76 |
value = ['face_swapper'] # Default value
|
| 77 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
with gr.Box():
|
| 80 |
+
with gr.Column(scale=3):
|
| 81 |
face_analyser_direction_dropdown = gr.Dropdown(
|
| 82 |
+
label = 'FACE ANALYSER DIRECTION',
|
| 83 |
choices = ['left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small'],
|
| 84 |
value = 'left-right'
|
| 85 |
)
|
| 86 |
face_analyser_age_dropdown = gr.Dropdown(
|
| 87 |
+
label = 'FACE ANALYSER AGE',
|
| 88 |
choices = ['none'] + ['child', 'young', 'adult', 'old'],
|
| 89 |
value = 'none'
|
| 90 |
)
|
| 91 |
face_analyser_gender_dropdown = gr.Dropdown(
|
| 92 |
+
label = 'FACE ANALYSER GENDER',
|
| 93 |
choices = ['none'] + ['male', 'female'],
|
| 94 |
value = 'none'
|
| 95 |
)
|
| 96 |
+
with gr.Tab("Image: "):
|
| 97 |
+
source_image = gr.Image(type="filepath", label="SOURCE IMAGE")
|
| 98 |
+
target_image = gr.Image(type="filepath", label="TARGET IMAGE")
|
| 99 |
+
image_button = gr.Button("START")
|
| 100 |
+
clear_button = gr.Button("CLEAR")
|
| 101 |
+
image_output = gr.Image(label="OUTPUT")
|
| 102 |
+
|
| 103 |
+
image_button.click(
|
| 104 |
+
run,
|
| 105 |
+
inputs=[source_image, target_image, frame_processor_checkbox, face_analyser_direction_dropdown, face_analyser_age_dropdown, face_analyser_gender_dropdown],
|
| 106 |
+
outputs=image_output
|
| 107 |
+
)
|
| 108 |
+
clear_button.click(clear_output, inputs=[image_output])
|
| 109 |
+
|
| 110 |
+
with gr.Tab("Video: "):
|
| 111 |
+
source_image_video = gr.Image(type="filepath", label="SOURCE IMAGE")
|
| 112 |
+
target_video = gr.Video(label="TARGET VIDEO")
|
| 113 |
+
with gr.Box():
|
| 114 |
+
skip_audio = gr.Checkbox(label="SKIP AUDIO")
|
| 115 |
+
keep_fps = gr.Checkbox(label="KEEP FPS")
|
| 116 |
+
keep_temp = gr.Checkbox(label="KEEP TEMP")
|
| 117 |
+
video_button = gr.Button("START")
|
| 118 |
+
clear_video_button = gr.Button("CLEAR")
|
| 119 |
+
video_output = gr.Video(label="OUTPUT")
|
| 120 |
+
video_button.click(
|
| 121 |
+
run,
|
| 122 |
+
inputs=[source_image_video, target_video, frame_processor_checkbox, face_analyser_direction_dropdown, face_analyser_age_dropdown, face_analyser_gender_dropdown, skip_audio, keep_fps, keep_temp],
|
| 123 |
+
outputs=video_output
|
| 124 |
+
)
|
| 125 |
+
clear_video_button.click(clear_output, inputs=[video_output])
|
| 126 |
|
| 127 |
ui.launch(debug=True)
|