Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,9 @@ import logging
|
|
6 |
from moviepy.editor import VideoFileClip
|
7 |
import torch
|
8 |
|
9 |
-
|
10 |
ACCESS_KEY = os.getenv("ACCESS_KEY")
|
11 |
|
12 |
-
# Configure PyTorch for deterministic behavior
|
13 |
torch.set_num_threads(1)
|
14 |
torch.set_num_interop_threads(1)
|
15 |
torch.use_deterministic_algorithms(True)
|
@@ -19,7 +18,7 @@ torch.backends.cuda.matmul.allow_tf32 = False
|
|
19 |
torch.backends.cudnn.allow_tf32 = False
|
20 |
|
21 |
def truncate_video(video_file):
|
22 |
-
|
23 |
clip = VideoFileClip(video_file)
|
24 |
truncated_clip = clip.subclip(0, min(15, clip.duration))
|
25 |
truncated_video_file = "temp_truncated_video.mp4"
|
@@ -27,7 +26,6 @@ def truncate_video(video_file):
|
|
27 |
return truncated_video_file
|
28 |
|
29 |
def clone_repo():
|
30 |
-
"""Clone the GitHub repository containing the backend."""
|
31 |
repo_url = "https://github.com/NeeravSood/AllMark-MVP.git"
|
32 |
repo_path = "./repository"
|
33 |
|
@@ -53,7 +51,6 @@ def clone_repo():
|
|
53 |
raise RuntimeError(f"Failed to clone repository: {e.stderr}")
|
54 |
|
55 |
def import_backend_script(script_name):
|
56 |
-
"""Dynamically import the backend script."""
|
57 |
try:
|
58 |
script_path = os.path.join("./repository", script_name)
|
59 |
if not os.path.exists(script_path):
|
@@ -67,7 +64,7 @@ def import_backend_script(script_name):
|
|
67 |
logging.error(f"Error importing backend script: {str(e)}")
|
68 |
raise RuntimeError(f"Failed to import backend script: {str(e)}")
|
69 |
|
70 |
-
|
71 |
clone_repo()
|
72 |
backend = import_backend_script("app.py")
|
73 |
analyzer = backend.DeepfakeAnalyzer()
|
@@ -78,8 +75,7 @@ def analyze_video(video_file):
|
|
78 |
logging.error("Access key not set in environment variables.")
|
79 |
return {"error": "Server misconfiguration. Access key not set."}
|
80 |
|
81 |
-
|
82 |
-
expected_key = "expected_internal_key_here"
|
83 |
if ACCESS_KEY != expected_key:
|
84 |
logging.error("Unauthorized access attempt.")
|
85 |
return {"error": "Unauthorized access. Invalid key provided."}
|
@@ -88,7 +84,6 @@ def analyze_video(video_file):
|
|
88 |
truncated_video = truncate_video(video_file)
|
89 |
results = analyzer.analyze_media(truncated_video)
|
90 |
|
91 |
-
# Get combined_assessment and handle non-numeric values
|
92 |
combined_assessment = results.get('combined_assessment', 0)
|
93 |
if isinstance(combined_assessment, str) and combined_assessment.lower() == "deepfake":
|
94 |
analysis_result = "a deepfake"
|
|
|
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)
|
13 |
torch.set_num_interop_threads(1)
|
14 |
torch.use_deterministic_algorithms(True)
|
|
|
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"
|
|
|
26 |
return truncated_video_file
|
27 |
|
28 |
def clone_repo():
|
|
|
29 |
repo_url = "https://github.com/NeeravSood/AllMark-MVP.git"
|
30 |
repo_path = "./repository"
|
31 |
|
|
|
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 |
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()
|
|
|
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."}
|
|
|
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"
|