Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import torch.nn.functional as F
|
|
5 |
from facenet_pytorch import MTCNN, InceptionResnetV1
|
6 |
import os
|
7 |
import numpy as np
|
8 |
-
from PIL import Image
|
9 |
import zipfile
|
10 |
import cv2
|
11 |
from pytorch_grad_cam import GradCAM
|
@@ -104,8 +104,8 @@ def analyze_video(input_video: str):
|
|
104 |
cap.release()
|
105 |
|
106 |
# Calculate metrics
|
107 |
-
fake_percentage = (sum(frame_predictions) / len(frame_predictions)) * 100
|
108 |
-
avg_confidence = np.mean(frame_confidences)
|
109 |
|
110 |
# Create graphs
|
111 |
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
|
@@ -159,12 +159,16 @@ def format_results(results):
|
|
159 |
- Total Frames: {results['total_frames']}
|
160 |
- Processed Frames: {results['processed_frames']}
|
161 |
"""
|
162 |
-
|
163 |
@spaces.GPU
|
164 |
def analyze_and_format(input_video):
|
165 |
results = analyze_video(input_video)
|
166 |
text_results = format_results(results)
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
interface = gr.Interface(
|
170 |
fn=analyze_and_format,
|
|
|
5 |
from facenet_pytorch import MTCNN, InceptionResnetV1
|
6 |
import os
|
7 |
import numpy as np
|
8 |
+
from PIL import Image as PILImage
|
9 |
import zipfile
|
10 |
import cv2
|
11 |
from pytorch_grad_cam import GradCAM
|
|
|
104 |
cap.release()
|
105 |
|
106 |
# Calculate metrics
|
107 |
+
fake_percentage = (sum(frame_predictions) / len(frame_predictions)) * 100 if frame_predictions else 0
|
108 |
+
avg_confidence = np.mean(frame_confidences) if frame_confidences else 0
|
109 |
|
110 |
# Create graphs
|
111 |
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
|
|
|
159 |
- Total Frames: {results['total_frames']}
|
160 |
- Processed Frames: {results['processed_frames']}
|
161 |
"""
|
|
|
162 |
@spaces.GPU
|
163 |
def analyze_and_format(input_video):
|
164 |
results = analyze_video(input_video)
|
165 |
text_results = format_results(results)
|
166 |
+
|
167 |
+
# Convert BytesIO to PIL Images
|
168 |
+
analysis_plot = PILImage.open(results['analysis_plot'])
|
169 |
+
progress_bar = PILImage.open(results['progress_bar'])
|
170 |
+
|
171 |
+
return text_results, analysis_plot, progress_bar
|
172 |
|
173 |
interface = gr.Interface(
|
174 |
fn=analyze_and_format,
|