NeeravS commited on
Commit
7b57752
·
verified ·
1 Parent(s): 269547c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -69,29 +69,31 @@ analyzer = backend.DeepfakeAnalyzer() # Use the imported module's class or func
69
 
70
  # Define the Gradio function to analyze the video
71
  def analyze_video(video_file):
72
- # Truncate the video to 15 seconds
73
- truncated_video = truncate_video(video_file)
74
-
75
- # Pass the truncated video to the analyzer
76
- results = analyzer.analyze_media(truncated_video)
77
-
78
- # Get the combined assessment probability
79
- combined_probability = results['combined_assessment']
80
-
81
- # Interpret the result as genuine or deepfake based on probability threshold
82
- if combined_probability < 50:
83
- analysis_result = "genuine/original"
84
- else:
85
- analysis_result = "a deepfake"
86
-
87
- # Create a readable output message
88
- output_text = (
89
- f"According to our analysis, the video you uploaded appears to be {analysis_result} "
90
- f"with a {combined_probability:.2f}% probability. "
91
- f"{len(results['video_analysis']['frame_results'])} frames were analyzed in total."
92
- )
93
-
94
- return output_text
 
 
95
 
96
  # Define the Gradio interface with a text output for readability
97
  interface = gr.Interface(
 
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
74
+ truncated_video = truncate_video(video_file)
75
+
76
+ # Pass the truncated video to the analyzer
77
+ results = analyzer.analyze_media(truncated_video)
78
+
79
+ # Check combined probability to interpret the result
80
+ combined_probability = results.get('combined_assessment', 0)
81
+ analysis_result = "genuine/original" if combined_probability < 50 else "a deepfake"
82
+
83
+ # Construct the output message
84
+ output_text = (
85
+ f"According to our analysis, the video you uploaded appears to be {analysis_result} "
86
+ f"with a {combined_probability:.2f}% probability. "
87
+ f"{len(results['video_analysis']['frame_results'])} frames were analyzed in total."
88
+ )
89
+
90
+ return output_text
91
+
92
+ except Exception as e:
93
+ # Log the error and return a user-friendly message
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(