Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,61 @@
|
|
| 1 |
import os
|
| 2 |
-
import
|
|
|
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
-
# Clone the GitHub repository
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Define the Gradio function to analyze the video
|
| 21 |
def analyze_video(video_file):
|
|
|
|
| 1 |
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import importlib.util
|
| 4 |
import gradio as gr
|
| 5 |
+
import logging
|
| 6 |
|
| 7 |
+
# Clone the GitHub repository containing the backend
|
| 8 |
+
def clone_repo():
|
| 9 |
+
"""Clone the GitHub repository containing the backend."""
|
| 10 |
+
repo_url = "https://github.com/NeeravSood/AllMark-MVP.git" # Update if necessary
|
| 11 |
+
repo_path = "./repository"
|
| 12 |
|
| 13 |
+
# Retrieve the GitHub Personal Access Token (GITHUB_PAT) from environment variables
|
| 14 |
+
github_pat = os.getenv("GITHUB_PAT")
|
| 15 |
+
if not github_pat:
|
| 16 |
+
raise RuntimeError("GitHub Personal Access Token (GITHUB_PAT) not found in environment variables.")
|
| 17 |
|
| 18 |
+
# Modify the repository URL to include the token for authentication
|
| 19 |
+
authenticated_repo_url = f"https://{github_pat}@github.com/NeeravSood/AllMark-MVP.git"
|
| 20 |
|
| 21 |
+
if os.path.exists(repo_path):
|
| 22 |
+
print("Repository already cloned.")
|
| 23 |
+
else:
|
| 24 |
+
try:
|
| 25 |
+
# Clone the repository using the authenticated URL
|
| 26 |
+
subprocess.run(
|
| 27 |
+
["git", "clone", authenticated_repo_url, repo_path],
|
| 28 |
+
check=True,
|
| 29 |
+
text=True,
|
| 30 |
+
capture_output=True
|
| 31 |
+
)
|
| 32 |
+
print("Repository cloned successfully.")
|
| 33 |
+
except subprocess.CalledProcessError as e:
|
| 34 |
+
print("Output:", e.stdout)
|
| 35 |
+
print("Error:", e.stderr)
|
| 36 |
+
raise RuntimeError(f"Failed to clone repository: {e.stderr}")
|
| 37 |
+
|
| 38 |
+
def import_backend_script(script_name):
|
| 39 |
+
"""Dynamically import the backend script."""
|
| 40 |
+
try:
|
| 41 |
+
script_path = os.path.join("./repository", script_name)
|
| 42 |
+
if not os.path.exists(script_path):
|
| 43 |
+
raise FileNotFoundError(f"Script {script_name} not found in the repository.")
|
| 44 |
+
|
| 45 |
+
spec = importlib.util.spec_from_file_location("backend_module", script_path)
|
| 46 |
+
backend_module = importlib.util.module_from_spec(spec)
|
| 47 |
+
spec.loader.exec_module(backend_module)
|
| 48 |
+
return backend_module
|
| 49 |
+
except Exception as e:
|
| 50 |
+
logging.error(f"Error importing backend script: {str(e)}")
|
| 51 |
+
raise RuntimeError(f"Failed to import backend script: {str(e)}")
|
| 52 |
+
|
| 53 |
+
# Clone the repository and import the backend module
|
| 54 |
+
clone_repo()
|
| 55 |
+
backend = import_backend_script("app.py") # Import app.py from the cloned repository
|
| 56 |
+
|
| 57 |
+
# Initialize the analyzer instance from the imported module
|
| 58 |
+
analyzer = backend.DeepfakeAnalyzer() # Use the imported module's class or function
|
| 59 |
|
| 60 |
# Define the Gradio function to analyze the video
|
| 61 |
def analyze_video(video_file):
|