imseldrith commited on
Commit
7dee5de
1 Parent(s): a4094f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -30
app.py CHANGED
@@ -15,13 +15,13 @@ def run(*args):
15
  output = f"./output/{filename}"
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
  )
@@ -29,7 +29,7 @@ def run(*args):
29
  cmd += f" --face-analyser-age {face_analyser_age}"
30
  if face_analyser_gender != 'none':
31
  cmd += f" --face-analyser-gender {face_analyser_gender}"
32
-
33
  if len(rest_args) > 4:
34
  skip_audio = rest_args[4]
35
  keep_fps = rest_args[5]
@@ -40,24 +40,21 @@ def run(*args):
40
  cmd += " --keep-fps"
41
  if keep_temp:
42
  cmd += " --keep-temp"
43
-
44
  try:
45
  print("Started...", cmd)
46
- output_text = sp.run(cmd, shell=True, capture_output=True, text=True).stdout
47
- print(output_text)
48
  return output
49
  except Exception as e:
50
  return f"An error occurred: {str(e)}"
51
- def clear_output():
52
- output_path = "./output"
53
- if os.path.exists(output_path):
54
- for filename in os.listdir(output_path):
55
- file_path = os.path.join(output_path, filename)
56
- if os.path.isfile(file_path):
57
- os.remove(file_path)
58
- return "Output files deleted"
59
  else:
60
- return "Output directory does not exist"
 
61
 
62
  def get_theme() -> gr.Theme:
63
  return gr.themes.Soft(
@@ -81,7 +78,7 @@ with gr.Blocks(theme=get_theme(), title="DeepFakeAI 1.0.0") as ui:
81
  label = 'FRAME PROCESSORS',
82
  value = ['face_swapper'] # Default value
83
  )
84
-
85
  with gr.Box():
86
  with gr.Column(scale=3):
87
  face_analyser_direction_dropdown = gr.Dropdown(
@@ -103,18 +100,16 @@ with gr.Blocks(theme=get_theme(), title="DeepFakeAI 1.0.0") as ui:
103
  source_image = gr.Image(type="filepath", label="SOURCE IMAGE")
104
  target_image = gr.Image(type="filepath", label="TARGET IMAGE")
105
  image_button = gr.Button("START")
106
- clear_button = gr.ClearButton(value="CLEAR")
107
  image_output = gr.Image(label="OUTPUT")
108
- clear_button.add(image_output)
109
-
110
  image_button.click(
111
- run,
112
  inputs=[source_image, target_image, frame_processor_checkbox, face_analyser_direction_dropdown, face_analyser_age_dropdown, face_analyser_gender_dropdown],
113
  outputs=image_output
114
  )
115
- print("Clearing output")
116
- clear_button.click(fn=clear_output)
117
- print("Clearing output Done")
118
  with gr.Tab("Video: "):
119
  source_image_video = gr.Image(type="filepath", label="SOURCE IMAGE")
120
  target_video = gr.Video(label="TARGET VIDEO")
@@ -123,13 +118,13 @@ with gr.Blocks(theme=get_theme(), title="DeepFakeAI 1.0.0") as ui:
123
  keep_fps = gr.Checkbox(label="KEEP FPS")
124
  keep_temp = gr.Checkbox(label="KEEP TEMP")
125
  video_button = gr.Button("START")
126
- clear_video_button = gr.ClearButton(value="CLEAR")
127
- output_video = gr.Video(label="OUTPUT")
128
- clear_video_button.add(output_video)
129
  video_button.click(
130
- run,
131
  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],
132
- outputs=output_video
133
  )
134
- clear_button.click(fn=clear_output)
 
135
  ui.launch(debug=True)
 
15
  output = f"./output/{filename}"
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 cpu -s {source} -t {target} -o {output} "
25
  f"--frame-processors {selected_frame_processors} "
26
  f"--face-analyser-direction {face_analyser_direction} "
27
  )
 
29
  cmd += f" --face-analyser-age {face_analyser_age}"
30
  if face_analyser_gender != 'none':
31
  cmd += f" --face-analyser-gender {face_analyser_gender}"
32
+
33
  if len(rest_args) > 4:
34
  skip_audio = rest_args[4]
35
  keep_fps = rest_args[5]
 
40
  cmd += " --keep-fps"
41
  if keep_temp:
42
  cmd += " --keep-temp"
43
+
44
  try:
45
  print("Started...", cmd)
46
+ sp.run(cmd, shell=True, capture_output=True, text=True).stdout
47
+
48
  return output
49
  except Exception as e:
50
  return f"An error occurred: {str(e)}"
51
+ def clear_output(output):
52
+ if os.path.exists(output):
53
+ os.remove(output)
54
+ return "Output file deleted"
 
 
 
 
55
  else:
56
+ return "Output file does not exist"
57
+
58
 
59
  def get_theme() -> gr.Theme:
60
  return gr.themes.Soft(
 
78
  label = 'FRAME PROCESSORS',
79
  value = ['face_swapper'] # Default value
80
  )
81
+
82
  with gr.Box():
83
  with gr.Column(scale=3):
84
  face_analyser_direction_dropdown = gr.Dropdown(
 
100
  source_image = gr.Image(type="filepath", label="SOURCE IMAGE")
101
  target_image = gr.Image(type="filepath", label="TARGET IMAGE")
102
  image_button = gr.Button("START")
103
+ clear_button = gr.Button("CLEAR")
104
  image_output = gr.Image(label="OUTPUT")
105
+
 
106
  image_button.click(
107
+ run,
108
  inputs=[source_image, target_image, frame_processor_checkbox, face_analyser_direction_dropdown, face_analyser_age_dropdown, face_analyser_gender_dropdown],
109
  outputs=image_output
110
  )
111
+ clear_button.click(clear_output, inputs=[image_output])
112
+
 
113
  with gr.Tab("Video: "):
114
  source_image_video = gr.Image(type="filepath", label="SOURCE IMAGE")
115
  target_video = gr.Video(label="TARGET VIDEO")
 
118
  keep_fps = gr.Checkbox(label="KEEP FPS")
119
  keep_temp = gr.Checkbox(label="KEEP TEMP")
120
  video_button = gr.Button("START")
121
+ clear_video_button = gr.Button("CLEAR")
122
+ video_output = gr.Video(label="OUTPUT")
 
123
  video_button.click(
124
+ run,
125
  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],
126
+ outputs=video_output
127
  )
128
+ clear_video_button.click(clear_output, inputs=[video_output])
129
+
130
  ui.launch(debug=True)