NeeravS's picture
Update app.py
e75dea4 verified
raw
history blame
1.32 kB
import streamlit as st
import os
from git import Repo
import sys
# GitHub Reposi tory and Directory Setup
repo_url = st.secrets["REPO_URL"] # The private repository URL
github_token = st.secrets["GITHUB_PAT"] # GitHub Personal Access Token
local_dir = "repo"
# Clone the private repository if it doesn't exist locally
if not os.path.exists(local_dir):
try:
repo_url = repo_url.replace("https://", f"https://{github_token}@")
st.write("Cloning the repository...")
Repo.clone_from(repo_url, local_dir)
st.success("Repository cloned successfully!")
# Add the repo directory to the system path
sys.path.insert(0, local_dir)
except Exception as e:
st.error(f"Error cloning repository: {e}")
st.stop() # Stop the app if the repo can't be cloned
# Dynamically import and execute the app.py from the cloned repository
try:
import importlib.util
spec = importlib.util.spec_from_file_location("cloned_app", os.path.join(local_dir, "app.py"))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception as e:
st.error(f"Error running the app from the cloned repo: {e}")
st.stop() # Stop the app if the cloned app can't be executed
st.error(f"Failed to process video: {str(e)}")