NeeravS commited on
Commit
2dc47c6
·
verified ·
1 Parent(s): 4b5e7a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -12
app.py CHANGED
@@ -1,21 +1,61 @@
1
  import os
2
- import sys
 
3
  import gradio as gr
 
4
 
5
- # Clone the GitHub repository securely using the token from Hugging Face secret
6
- REPO_URL = "https://github.com/NeeravSood/AllMark-MVP.git"
7
- GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Get the token from Hugging Face secret
8
- if not os.path.exists("AllMark-MVP"):
9
- os.system(f"git clone https://{GITHUB_TOKEN}:x-oauth-basic@{REPO_URL.split('https://')[1]}")
10
 
11
- # Add the cloned repository to the Python path
12
- sys.path.append("AllMark-MVP")
 
 
13
 
14
- # Now you can import any module from the entire repository
15
- import app # Assuming app.py is the main file, or use `from app import *` if needed
16
 
17
- # Initialize the DeepfakeAnalyzer (or any other component from the repo)
18
- analyzer = app.DeepfakeAnalyzer()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):