NeeravS commited on
Commit
cc2ac2b
·
verified ·
1 Parent(s): 5520756

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -76,25 +76,36 @@ def analyze_video(video_file):
76
  return {"error": "Server misconfiguration. Access key not set."}
77
 
78
  try:
79
- truncated_video = truncate_video(video_file) # Truncate the video for faster analysis, if required.
80
  results = analyzer.analyze_media(truncated_video)
81
 
82
- # Retrieve the final combined assessment result from the analysis
83
- combined_assessment = results.get('combined_assessment', "Genuine")
84
-
85
- # Determine the analysis result based on the combined assessment
86
- if combined_assessment.lower() == "deepfake":
87
- analysis_result = "a deepfake"
 
 
 
 
 
88
  else:
89
- analysis_result = "genuine/original"
 
 
 
 
 
 
 
90
 
91
- # Construct output with the analysis result and detailed breakdown
92
  output = {
93
- "message": f"According to our analysis, the video you uploaded appears to be {analysis_result}. "
94
- f"{len(results['video_analysis']['frame_results'])} frames were analyzed in total.",
95
  "details": {
96
- "video_probability": results['video_analysis']['probability'], # Video probability score
97
- "combined_assessment": combined_assessment # Final assessment (Deepfake or Genuine)
98
  }
99
  }
100
  return output
@@ -105,6 +116,7 @@ def analyze_video(video_file):
105
 
106
 
107
 
 
108
  interface = gr.Interface(
109
  fn=analyze_video,
110
  inputs=gr.Video(label="Upload Video"),
 
76
  return {"error": "Server misconfiguration. Access key not set."}
77
 
78
  try:
79
+ truncated_video = truncate_video(video_file) # Truncate the video for faster analysis
80
  results = analyzer.analyze_media(truncated_video)
81
 
82
+ # Extract frame count and video probability
83
+ frame_count = len(results['video_analysis']['frame_results'])
84
+ video_probability = results['video_analysis']['probability']
85
+ combined_assessment = results.get('combined_assessment', "Inconclusive")
86
+
87
+ # Reapply combined_results logic for front-end clarity
88
+ if frame_count < 300:
89
+ assessment = "Inconclusive due to lack of sufficient frames"
90
+ elif frame_count < 500:
91
+ threshold = 0.4
92
+ assessment = "Deepfake" if video_probability >= threshold else "Genuine"
93
  else:
94
+ threshold = 0.5
95
+ assessment = "Deepfake" if video_probability >= threshold else "Genuine"
96
+
97
+ # Construct output message
98
+ message = (
99
+ f"According to our analysis, the video you uploaded appears to be {assessment}. "
100
+ f"{frame_count} frames were analyzed in total."
101
+ )
102
 
103
+ # Return the final output
104
  output = {
105
+ "message": message,
 
106
  "details": {
107
+ "video_probability": video_probability,
108
+ "combined_assessment": assessment # Final assessment based on reapplied logic
109
  }
110
  }
111
  return output
 
116
 
117
 
118
 
119
+
120
  interface = gr.Interface(
121
  fn=analyze_video,
122
  inputs=gr.Video(label="Upload Video"),