NeeravS commited on
Commit
c050703
·
verified ·
1 Parent(s): a9d2de0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -28
app.py CHANGED
@@ -1,35 +1,43 @@
1
- import streamlit as st
2
  import os
3
- from git import Repo
4
  import sys
 
 
 
 
 
 
 
 
5
 
6
- # GitHub Reposi tory and Directory Setup
7
- repo_url = st.secrets["REPO_URL"] # The private repository URL
8
- github_token = st.secrets["GITHUB_PAT"] # GitHub Personal Access Token
9
- local_dir = "repo"
 
 
 
 
 
 
 
 
 
 
10
 
11
- # Clone the private repository if it doesn't exist locally
12
- if not os.path.exists(local_dir):
13
  try:
14
- repo_url = repo_url.replace("https://", f"https://{github_token}@")
15
- st.write("Cloning the repository...")
16
- Repo.clone_from(repo_url, local_dir)
17
- st.success("Repository cloned successfully!")
18
-
19
- # Add the repo directory to the system path
20
- sys.path.insert(0, local_dir)
21
- except Exception as e:
22
- st.error(f"Error cloning repository: {e}")
23
- st.stop() # Stop the app if the repo can't be cloned
24
 
25
- # Dynamically import and execute the app.py from the cloned repository
26
- try:
27
- import importlib.util
28
- spec = importlib.util.spec_from_file_location("cloned_app", os.path.join(local_dir, "app.py"))
29
- module = importlib.util.module_from_spec(spec)
30
- spec.loader.exec_module(module)
 
 
31
 
32
- except Exception as e:
33
- st.error(f"Error running the app from the cloned repo: {e}")
34
- st.stop() # Stop the app if the cloned app can't be executed
35
- st.error(f"Failed to process video: {str(e)}")
 
 
1
  import os
 
2
  import sys
3
+ from git import Repo
4
+ import importlib.util
5
+
6
+ def main():
7
+ # GitHub Repository and Directory Setup
8
+ repo_url = os.getenv("REPO_URL") # The private repository URL from environment variables
9
+ github_token = os.getenv("GITHUB_PAT") # GitHub Personal Access Token from environment variables
10
+ local_dir = "repo"
11
 
12
+ # Clone the private repository if it doesn't exist locally
13
+ if not os.path.exists(local_dir):
14
+ try:
15
+ # Prepare the repo URL with the token for authentication
16
+ repo_url = repo_url.replace("https://", f"https://{github_token}@")
17
+ print("Cloning the repository...")
18
+ Repo.clone_from(repo_url, local_dir)
19
+ print("Repository cloned successfully!")
20
+
21
+ # Add the repo directory to the system path
22
+ sys.path.insert(0, local_dir)
23
+ except Exception as e:
24
+ print(f"Error cloning repository: {e}")
25
+ sys.exit(1) # Exit the script if the repo can't be cloned
26
 
27
+ # Dynamically import and execute the app.py from the cloned repository
 
28
  try:
29
+ spec = importlib.util.spec_from_file_location("cloned_app", os.path.join(local_dir, "app.py"))
30
+ module = importlib.util.module_from_spec(spec)
31
+ spec.loader.exec_module(module)
 
 
 
 
 
 
 
32
 
33
+ # If the module has a 'main' function, call it (for apps like FastAPI or Gradio)
34
+ if hasattr(module, "main"):
35
+ module.main()
36
+ else:
37
+ print("No main function found in the cloned app.")
38
+ except Exception as e:
39
+ print(f"Error running the app from the cloned repo: {e}")
40
+ sys.exit(1) # Exit the script if the cloned app can't be executed
41
 
42
+ if __name__ == "__main__":
43
+ main()