Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,16 @@ import subprocess
|
|
| 3 |
import importlib.util
|
| 4 |
import gradio as gr
|
| 5 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Clone the GitHub repository containing the backend
|
| 8 |
def clone_repo():
|
|
@@ -57,9 +67,14 @@ backend = import_backend_script("app.py") # Import app.py from the cloned repos
|
|
| 57 |
# Initialize the analyzer instance from the imported module
|
| 58 |
analyzer = backend.DeepfakeAnalyzer() # Use the imported module's class or function
|
| 59 |
|
|
|
|
| 60 |
# Define the Gradio function to analyze the video
|
| 61 |
def analyze_video(video_file):
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
combined_probability = results['combined_assessment']
|
| 64 |
audio_analysis = results["audio_analysis"]
|
| 65 |
video_probability = results['video_analysis']['probability']
|
|
@@ -74,11 +89,6 @@ def analyze_video(video_file):
|
|
| 74 |
"Frames Analyzed": frame_count,
|
| 75 |
"Frame Analysis Summary": [
|
| 76 |
{
|
| 77 |
-
"Frame Number": frame_result["frame_number"],
|
| 78 |
-
"Noise Level": frame_result["noise"],
|
| 79 |
-
"Edge Density": frame_result["edge_density"],
|
| 80 |
-
"Color Consistency": frame_result["color_consistency"],
|
| 81 |
-
"Temporal Difference": frame_result["temporal_difference"],
|
| 82 |
"Probability": frame_result["probability"]
|
| 83 |
}
|
| 84 |
for frame_result in results['video_analysis']['frame_results']
|
|
@@ -87,12 +97,13 @@ def analyze_video(video_file):
|
|
| 87 |
}
|
| 88 |
return output
|
| 89 |
|
|
|
|
| 90 |
# Define the Gradio interface
|
| 91 |
interface = gr.Interface(
|
| 92 |
fn=analyze_video,
|
| 93 |
inputs=gr.Video(label="Upload Video"),
|
| 94 |
outputs="json",
|
| 95 |
-
title="Deepfake Analyzer",
|
| 96 |
description="Upload a video to analyze for deepfake content."
|
| 97 |
)
|
| 98 |
|
|
|
|
| 3 |
import importlib.util
|
| 4 |
import gradio as gr
|
| 5 |
import logging
|
| 6 |
+
from moviepy.editor import VideoFileClip
|
| 7 |
+
|
| 8 |
+
# Function to truncate video to 15 seconds
|
| 9 |
+
def truncate_video(video_file):
|
| 10 |
+
"""Truncates video to 15 seconds and saves it as a temporary file."""
|
| 11 |
+
clip = VideoFileClip(video_file)
|
| 12 |
+
truncated_clip = clip.subclip(0, min(15, clip.duration))
|
| 13 |
+
truncated_video_file = "temp_truncated_video.mp4"
|
| 14 |
+
truncated_clip.write_videofile(truncated_video_file, codec="libx264", audio_codec="aac")
|
| 15 |
+
return truncated_video_file
|
| 16 |
|
| 17 |
# Clone the GitHub repository containing the backend
|
| 18 |
def clone_repo():
|
|
|
|
| 67 |
# Initialize the analyzer instance from the imported module
|
| 68 |
analyzer = backend.DeepfakeAnalyzer() # Use the imported module's class or function
|
| 69 |
|
| 70 |
+
# Define the Gradio function to analyze the video
|
| 71 |
# Define the Gradio function to analyze the video
|
| 72 |
def analyze_video(video_file):
|
| 73 |
+
# Truncate the video to 15 seconds
|
| 74 |
+
truncated_video = truncate_video(video_file)
|
| 75 |
+
|
| 76 |
+
# Pass the truncated video to the analyzer
|
| 77 |
+
results = analyzer.analyze_media(truncated_video)
|
| 78 |
combined_probability = results['combined_assessment']
|
| 79 |
audio_analysis = results["audio_analysis"]
|
| 80 |
video_probability = results['video_analysis']['probability']
|
|
|
|
| 89 |
"Frames Analyzed": frame_count,
|
| 90 |
"Frame Analysis Summary": [
|
| 91 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
"Probability": frame_result["probability"]
|
| 93 |
}
|
| 94 |
for frame_result in results['video_analysis']['frame_results']
|
|
|
|
| 97 |
}
|
| 98 |
return output
|
| 99 |
|
| 100 |
+
|
| 101 |
# Define the Gradio interface
|
| 102 |
interface = gr.Interface(
|
| 103 |
fn=analyze_video,
|
| 104 |
inputs=gr.Video(label="Upload Video"),
|
| 105 |
outputs="json",
|
| 106 |
+
title="AllMark - Deepfake Analyzer",
|
| 107 |
description="Upload a video to analyze for deepfake content."
|
| 108 |
)
|
| 109 |
|