Update app.py
Browse files
app.py
CHANGED
@@ -15,23 +15,17 @@ deepfake_roop_dir = os.path.join(examples_dir, 'DeepfakeRoop')
|
|
15 |
deepfake_web_dir = os.path.join(examples_dir, 'DeepfakeWeb')
|
16 |
|
17 |
# Function to get video paths from a directory
|
18 |
-
def get_video_paths(directory
|
19 |
videos = []
|
20 |
for vid in os.listdir(directory):
|
21 |
if vid.endswith('.mp4'):
|
22 |
-
videos.append(
|
23 |
return videos
|
24 |
|
25 |
# Get video paths for each category
|
26 |
-
original_videos = get_video_paths(original_dir
|
27 |
-
deepfake_roop_videos = get_video_paths(deepfake_roop_dir
|
28 |
-
deepfake_web_videos = get_video_paths(deepfake_web_dir
|
29 |
-
|
30 |
-
# Combine all examples
|
31 |
-
examples = original_videos + deepfake_roop_videos + deepfake_web_videos
|
32 |
-
|
33 |
-
# Map from example video path to label
|
34 |
-
example_videos_dict = {example['path']: example['label'] for example in examples}
|
35 |
|
36 |
def process_video(video_path, true_label=None):
|
37 |
cap = cv2.VideoCapture(video_path)
|
@@ -128,42 +122,28 @@ def predict(video_input):
|
|
128 |
with gr.Blocks() as demo:
|
129 |
gr.HTML("<h1 style='text-align: center;'>Quanvolutional Neural Networks for Deepfake Detection</h1>")
|
130 |
gr.HTML("<h2 style='text-align: center;'>Steven Fernandes, Ph.D.</h2>")
|
131 |
-
|
132 |
-
with gr.
|
133 |
-
with gr.
|
134 |
-
|
135 |
-
gr.Examples(
|
136 |
-
|
137 |
-
inputs=
|
138 |
-
|
139 |
)
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
examples=
|
144 |
-
inputs=deepfake_roop_input,
|
145 |
-
label="Deepfake Roop Examples"
|
146 |
)
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
examples=
|
151 |
-
inputs=deepfake_web_input,
|
152 |
-
label="Deepfake Web Examples"
|
153 |
)
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
def predict_combined(original_video, deepfake_roop_video, deepfake_web_video):
|
160 |
-
video_input = original_video or deepfake_roop_video or deepfake_web_video
|
161 |
-
return predict(video_input)
|
162 |
-
|
163 |
-
predict_button.click(
|
164 |
-
fn=predict_combined,
|
165 |
-
inputs=[original_input, deepfake_roop_input, deepfake_web_input],
|
166 |
-
outputs=output
|
167 |
-
)
|
168 |
-
|
169 |
demo.launch()
|
|
|
15 |
deepfake_web_dir = os.path.join(examples_dir, 'DeepfakeWeb')
|
16 |
|
17 |
# Function to get video paths from a directory
|
18 |
+
def get_video_paths(directory):
|
19 |
videos = []
|
20 |
for vid in os.listdir(directory):
|
21 |
if vid.endswith('.mp4'):
|
22 |
+
videos.append(os.path.join(directory, vid))
|
23 |
return videos
|
24 |
|
25 |
# Get video paths for each category
|
26 |
+
original_videos = get_video_paths(original_dir)
|
27 |
+
deepfake_roop_videos = get_video_paths(deepfake_roop_dir)
|
28 |
+
deepfake_web_videos = get_video_paths(deepfake_web_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
def process_video(video_path, true_label=None):
|
31 |
cap = cv2.VideoCapture(video_path)
|
|
|
122 |
with gr.Blocks() as demo:
|
123 |
gr.HTML("<h1 style='text-align: center;'>Quanvolutional Neural Networks for Deepfake Detection</h1>")
|
124 |
gr.HTML("<h2 style='text-align: center;'>Steven Fernandes, Ph.D.</h2>")
|
125 |
+
|
126 |
+
with gr.Row():
|
127 |
+
with gr.Column():
|
128 |
+
video_input = gr.Video(label="Upload Video", type="file")
|
129 |
+
examples_original = gr.Examples(
|
130 |
+
label="Original Videos",
|
131 |
+
inputs=video_input,
|
132 |
+
examples=original_videos
|
133 |
)
|
134 |
+
examples_deepfake_roop = gr.Examples(
|
135 |
+
label="Deepfake Roop Videos",
|
136 |
+
inputs=video_input,
|
137 |
+
examples=deepfake_roop_videos
|
|
|
|
|
138 |
)
|
139 |
+
examples_deepfake_web = gr.Examples(
|
140 |
+
label="Deepfake Web Videos",
|
141 |
+
inputs=video_input,
|
142 |
+
examples=deepfake_web_videos
|
|
|
|
|
143 |
)
|
144 |
+
predict_button = gr.Button("Predict")
|
145 |
+
with gr.Column():
|
146 |
+
output = gr.Textbox(label="Result")
|
147 |
+
|
148 |
+
predict_button.click(fn=predict, inputs=video_input, outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
demo.launch()
|