imseldrith commited on
Commit
359a784
1 Parent(s): 714aac9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import gradio
3
+ import subprocess as sp
4
+ import os
5
+
6
+ os.makedirs("./output", exist_ok=True)
7
+
8
+ def run(*args):
9
+ source, target, *rest_args = args
10
+ if not os.path.exists(source):
11
+ return "Source file does not exist"
12
+ if not os.path.exists(target):
13
+ return "Target file does not exist"
14
+
15
+ filename = os.path.basename(target)
16
+ output = f"./output/{filename}"
17
+ frame_processor = rest_args[0]
18
+ selected_frame_processors = ' '.join(frame_processor)
19
+
20
+ cmd = f"python run.py --execution-providers cpu -s {source} -t {target} -o {output} --frame-processors {selected_frame_processors}"
21
+
22
+ if len(rest_args) > 1:
23
+ skip_audio = rest_args[1]
24
+ keep_fps = rest_args[2]
25
+ keep_temp = rest_args[3]
26
+ if skip_audio:
27
+ cmd += " --skip-audio"
28
+ if keep_fps:
29
+ cmd += " --keep-fps"
30
+ if keep_temp:
31
+ cmd += " --keep-temp"
32
+
33
+ try:
34
+ print("Started...", cmd)
35
+ sp.run(cmd, shell=True, capture_output=True, text=True).stdout
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(
42
+ primary_hue = gr.themes.colors.red,
43
+ secondary_hue = gr.themes.colors.gray,
44
+ font = gr.themes.GoogleFont('Inter')
45
+ ).set(
46
+ background_fill_primary = '*neutral_50',
47
+ block_label_text_size = '*text_sm',
48
+ block_title_text_size = '*text_sm'
49
+ )
50
+
51
+ with gr.Blocks(theme=get_theme(), title="DeepFakeAI 1.0.0") as ui:
52
+ with gr.Box():
53
+ gr.HTML('<center><a href="codegenius.me">DeepFakeAI 1.0.0</a></center>')
54
+
55
+ with gr.Box():
56
+ frame_processor_checkbox = gr.CheckboxGroup(
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 = 'Face Analyser Direction',
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 = 'Face Analyser Age',
98
+ choices = ['none'] + ['child', 'young', 'adult', 'old'],
99
+ value = 'none'
100
+ )
101
+ face_analyser_gender_dropdown = gr.Dropdown(
102
+ label = 'Face Analyser Gender',
103
+ choices = ['none'] + ['male', 'female'],
104
+ value = 'none'
105
+ )
106
+
107
+ ui.launch(debug=True)