Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -68,6 +68,8 @@ backend = import_backend_script("app.py") # Import app.py from the cloned repos
|
|
68 |
analyzer = backend.DeepfakeAnalyzer() # Use the imported module's class or function
|
69 |
|
70 |
# Define the Gradio function to analyze the video
|
|
|
|
|
71 |
def analyze_video(video_file):
|
72 |
try:
|
73 |
# Truncate the video to 15 seconds
|
@@ -76,41 +78,31 @@ def analyze_video(video_file):
|
|
76 |
# Pass the truncated video to the analyzer
|
77 |
results = analyzer.analyze_media(truncated_video)
|
78 |
|
79 |
-
#
|
80 |
combined_probability = results.get('combined_assessment', 0)
|
81 |
analysis_result = "genuine/original" if combined_probability < 50 else "a deepfake"
|
82 |
|
83 |
-
#
|
84 |
-
|
85 |
-
f"According to our analysis, the video you uploaded appears to be {analysis_result} "
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
|
90 |
-
return
|
91 |
|
92 |
except Exception as e:
|
93 |
-
# Log the error and return a
|
94 |
logging.error(f"Error during analysis: {e}")
|
95 |
-
return "An error occurred during video analysis. Please check your input and try again."
|
96 |
-
|
97 |
-
|
98 |
-
# Define the Gradio interface with a text output for readability
|
99 |
-
interface = gr.Interface(
|
100 |
-
fn=analyze_video,
|
101 |
-
inputs=gr.Video(label="Upload Video"),
|
102 |
-
outputs="text",
|
103 |
-
title="AllMark - Deepfake Analyzer",
|
104 |
-
description="Upload a video to analyze for deepfake content. Get an assessment of the likelihood that the video is genuine or a deepfake."
|
105 |
-
)
|
106 |
|
107 |
-
# Define the Gradio interface
|
108 |
interface = gr.Interface(
|
109 |
fn=analyze_video,
|
110 |
inputs=gr.Video(label="Upload Video"),
|
111 |
outputs="json",
|
112 |
title="AllMark - Deepfake Analyzer",
|
113 |
-
description="Upload a video to analyze for deepfake content.
|
114 |
)
|
115 |
|
116 |
# Launch Gradio app
|
|
|
68 |
analyzer = backend.DeepfakeAnalyzer() # Use the imported module's class or function
|
69 |
|
70 |
# Define the Gradio function to analyze the video
|
71 |
+
import json # Ensure imports include json for dictionary-to-JSON string handling
|
72 |
+
|
73 |
def analyze_video(video_file):
|
74 |
try:
|
75 |
# Truncate the video to 15 seconds
|
|
|
78 |
# Pass the truncated video to the analyzer
|
79 |
results = analyzer.analyze_media(truncated_video)
|
80 |
|
81 |
+
# Get the combined probability and interpret the result
|
82 |
combined_probability = results.get('combined_assessment', 0)
|
83 |
analysis_result = "genuine/original" if combined_probability < 50 else "a deepfake"
|
84 |
|
85 |
+
# Prepare JSON output
|
86 |
+
output = {
|
87 |
+
"message": f"According to our analysis, the video you uploaded appears to be {analysis_result} "
|
88 |
+
f"with a {combined_probability:.2f}% probability. "
|
89 |
+
f"{len(results['video_analysis']['frame_results'])} frames were analyzed in total."
|
90 |
+
}
|
91 |
|
92 |
+
return output
|
93 |
|
94 |
except Exception as e:
|
95 |
+
# Log the error and return a JSON-compatible error message
|
96 |
logging.error(f"Error during analysis: {e}")
|
97 |
+
return {"error": "An error occurred during video analysis. Please check your input and try again."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
# Define the Gradio interface with json output to handle dictionaries
|
100 |
interface = gr.Interface(
|
101 |
fn=analyze_video,
|
102 |
inputs=gr.Video(label="Upload Video"),
|
103 |
outputs="json",
|
104 |
title="AllMark - Deepfake Analyzer",
|
105 |
+
description="Upload a video to analyze for deepfake content. Get an assessment of the likelihood that the video is genuine or a deepfake."
|
106 |
)
|
107 |
|
108 |
# Launch Gradio app
|