-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
75 lines (62 loc) · 3.08 KB
/
start.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from VenvManager import VenvManager
from os.path import exists
from os import mkdir
from argparse import ArgumentParser
from subprocess import call
from shutil import rmtree
def CheckAndCreateDirectory(foldername : str):
if exists(foldername) is False:
mkdir(foldername)
def CreateDirectories():
CheckAndCreateDirectory("dataset")
CheckAndCreateDirectory("prompts")
CheckAndCreateDirectory("upscaleInput")
CheckAndCreateDirectory("upscaleOutput")
def CreateEnvironmentForRealESRGAN(osName : str):
if exists("Real-ESRGAN"):
return
print("Cloning repository ...")
process = call("git clone https://github.com/xinntao/Real-ESRGAN.git", shell=True)
print("Installing required packages ...")
command = ""
if osName == 'Windows':
command += "venv\Scripts\\activate.bat && "
command += "venv\Scripts\pip.exe install basicsr facexlib gfpgan && "
command += "venv\Scripts\pip.exe install -r Real-ESRGAN\\requirements.txt && "
command += "cd Real-ESRGAN && call ..\\venv\Scripts\python.exe setup.py develop && "
command += "..\\venv\Scripts\pip.exe uninstall torch torchvision --yes && "
command += "..\\venv\Scripts\pip.exe install torch torchvision --index-url https://download.pytorch.org/whl/cu117 && "
command += "cd .. && venv\Scripts\\deactivate.bat"
elif osName == 'Linux':
command += "source venv/Scripts/activate && "
command += "pip3 install basicsr facexlib gfpgan && "
command += "pip3 install -r Real-ESRGAN/requirements.txt && "
command += "cd Real-ESRGAN && python setup.py develop && "
command += "pip3 uninstall torch torchvision --yes && "
command += "pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu117 && "
command += "cd .. && deactivate"
process = call(command, shell=True)
print("Installation is completed!!! You can continue")
def CreateEnvrionment(venvManager : VenvManager, isRecreate : bool):
if venvManager.IsEnvironmentCreated() is True and isRecreate is False:
print(f"{venvManager.venvName} virtual environment is already exists")
return
if exists("Real-ESRGAN"):
rmtree("Real-ESRGAN")
venvManager.CreateEnvironmentWPackageNames("packages.txt", isRecreate)
venvManager.ReInstallTorch()
def ReInstall(venvManager : VenvManager):
venvManager.InstallWPackageNames("packages.txt")
venvManager.ReInstallTorch()
if __name__ == '__main__':
parser = ArgumentParser(description="Prompt Tools WebUI")
parser.add_argument("--reinstall", action="store_true", help="Reinstall the environment")
parser.add_argument("--recreate", action="store_true", help="Recreate virtual environment")
args = parser.parse_args()
venvManager = VenvManager("venv")
CreateEnvrionment(venvManager, args.recreate)
if args.reinstall:
ReInstall(venvManager)
CreateEnvironmentForRealESRGAN(venvManager.osName)
CreateDirectories()
venvManager.RunFile("main.py")