File size: 1,094 Bytes
e6494c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a24f19
 
e6494c6
 
 
 
 
 
 
 
 
 
 
 
70a9d87
b4785f3
70a9d87
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)