AI-RESEARCHER-2024 commited on
Commit
919d6ca
·
verified ·
1 Parent(s): 42b5b0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -46
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, label):
19
  videos = []
20
  for vid in os.listdir(directory):
21
  if vid.endswith('.mp4'):
22
- videos.append({'path': os.path.join(directory, vid), 'label': label})
23
  return videos
24
 
25
  # Get video paths for each category
26
- original_videos = get_video_paths(original_dir, 'Original')
27
- deepfake_roop_videos = get_video_paths(deepfake_roop_dir, 'DeepfakeRoop')
28
- deepfake_web_videos = get_video_paths(deepfake_web_dir, 'DeepfakeWeb')
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.Tabs():
133
- with gr.TabItem("Original Videos"):
134
- original_input = gr.Video(label="Upload Original Video or Select an Example")
135
- gr.Examples(
136
- examples=[example['path'] for example in original_videos],
137
- inputs=original_input,
138
- label="Original Examples"
139
  )
140
- with gr.TabItem("Deepfake Roop Videos"):
141
- deepfake_roop_input = gr.Video(label="Upload Deepfake Roop Video or Select an Example")
142
- gr.Examples(
143
- examples=[example['path'] for example in deepfake_roop_videos],
144
- inputs=deepfake_roop_input,
145
- label="Deepfake Roop Examples"
146
  )
147
- with gr.TabItem("Deepfake Web Videos"):
148
- deepfake_web_input = gr.Video(label="Upload Deepfake Web Video or Select an Example")
149
- gr.Examples(
150
- examples=[example['path'] for example in deepfake_web_videos],
151
- inputs=deepfake_web_input,
152
- label="Deepfake Web Examples"
153
  )
154
-
155
- predict_button = gr.Button("Predict")
156
- output = gr.Textbox(label="Result")
157
-
158
- # Function to handle input from any tab
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()