NeeravS commited on
Commit
1534cde
·
verified ·
1 Parent(s): 1c50e66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -6,7 +6,6 @@ import logging
6
  from moviepy.editor import VideoFileClip
7
  import torch
8
 
9
-
10
  ACCESS_KEY = os.getenv("ACCESS_KEY")
11
 
12
  torch.set_num_threads(1)
@@ -18,7 +17,6 @@ torch.backends.cuda.matmul.allow_tf32 = False
18
  torch.backends.cudnn.allow_tf32 = False
19
 
20
  def truncate_video(video_file):
21
-
22
  clip = VideoFileClip(video_file)
23
  truncated_clip = clip.subclip(0, min(15, clip.duration))
24
  truncated_video_file = "temp_truncated_video.mp4"
@@ -51,6 +49,7 @@ def clone_repo():
51
  raise RuntimeError(f"Failed to clone repository: {e.stderr}")
52
 
53
  def import_backend_script(script_name):
 
54
  try:
55
  script_path = os.path.join("./repository", script_name)
56
  if not os.path.exists(script_path):
@@ -64,26 +63,21 @@ def import_backend_script(script_name):
64
  logging.error(f"Error importing backend script: {str(e)}")
65
  raise RuntimeError(f"Failed to import backend script: {str(e)}")
66
 
67
-
68
  clone_repo()
69
  backend = import_backend_script("app.py")
70
  analyzer = backend.DeepfakeAnalyzer()
71
 
72
  def analyze_video(video_file):
73
- # Validate the access key at runtime
74
  if ACCESS_KEY is None:
75
  logging.error("Access key not set in environment variables.")
76
  return {"error": "Server misconfiguration. Access key not set."}
77
 
78
- expected_key = ACCESS_KEY # Directly using the environment variable
79
- if ACCESS_KEY != expected_key:
80
- logging.error("Unauthorized access attempt.")
81
- return {"error": "Unauthorized access. Invalid key provided."}
82
-
83
  try:
84
  truncated_video = truncate_video(video_file)
85
  results = analyzer.analyze_media(truncated_video)
86
 
 
87
  combined_assessment = results.get('combined_assessment', 0)
88
  if isinstance(combined_assessment, str) and combined_assessment.lower() == "deepfake":
89
  analysis_result = "a deepfake"
@@ -111,4 +105,4 @@ interface = gr.Interface(
111
  )
112
 
113
  if __name__ == "__main__":
114
- interface.launch()
 
6
  from moviepy.editor import VideoFileClip
7
  import torch
8
 
 
9
  ACCESS_KEY = os.getenv("ACCESS_KEY")
10
 
11
  torch.set_num_threads(1)
 
17
  torch.backends.cudnn.allow_tf32 = False
18
 
19
  def truncate_video(video_file):
 
20
  clip = VideoFileClip(video_file)
21
  truncated_clip = clip.subclip(0, min(15, clip.duration))
22
  truncated_video_file = "temp_truncated_video.mp4"
 
49
  raise RuntimeError(f"Failed to clone repository: {e.stderr}")
50
 
51
  def import_backend_script(script_name):
52
+ """Dynamically import the backend script."""
53
  try:
54
  script_path = os.path.join("./repository", script_name)
55
  if not os.path.exists(script_path):
 
63
  logging.error(f"Error importing backend script: {str(e)}")
64
  raise RuntimeError(f"Failed to import backend script: {str(e)}")
65
 
66
+ # Run repository setup and model import
67
  clone_repo()
68
  backend = import_backend_script("app.py")
69
  analyzer = backend.DeepfakeAnalyzer()
70
 
71
  def analyze_video(video_file):
 
72
  if ACCESS_KEY is None:
73
  logging.error("Access key not set in environment variables.")
74
  return {"error": "Server misconfiguration. Access key not set."}
75
 
 
 
 
 
 
76
  try:
77
  truncated_video = truncate_video(video_file)
78
  results = analyzer.analyze_media(truncated_video)
79
 
80
+
81
  combined_assessment = results.get('combined_assessment', 0)
82
  if isinstance(combined_assessment, str) and combined_assessment.lower() == "deepfake":
83
  analysis_result = "a deepfake"
 
105
  )
106
 
107
  if __name__ == "__main__":
108
+ interface.launch()