fcakyon's picture
Update app.py
b4785f3 verified
raw
history blame
1.09 kB
import os
import shutil
from pathlib import Path
from urllib.parse import urlparse
os.system("pip install GitPython")
from git import Repo
token = os.getenv('GH_TOKEN')
repo_url = os.getenv('REPO')
REPO_URL, BRANCH_NAME = repo_url.split('@')
OWNER_REPO_NAME = urlparse(REPO_URL).path.lstrip("/")
REPO_DIR_NAME = Path(urlparse(REPO_URL).path).stem
Repo.clone_from(f"https://{token}@github.com/{OWNER_REPO_NAME}", REPO_DIR_NAME, branch=BRANCH_NAME)
for item in Path(REPO_DIR_NAME).iterdir():
if item.name in ['README.md']:
continue
shutil.copytree(item, Path.cwd() / item.name, dirs_exist_ok=True) if item.is_dir() else shutil.copy2(item, Path.cwd())
def del_error_handler(func, path, exc_info):
if not os.access(path, os.W_OK):
os.chmod(path, 0o600)
func(path)
else:
raise
shutil.rmtree(REPO_DIR_NAME, onerror=del_error_handler)
os.system("pip install -r requirements.txt")
if __name__ == "__main__":
from gradio_app import demo
demo.queue(default_concurrency_limit=1, max_size=5).launch(server_name="0.0.0.0", server_port=7860)