-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
199 lines (163 loc) · 6.93 KB
/
GUI.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import tkinter as tk
from tkinter import messagebox
from tkinter import filedialog
from subprocess import call, DEVNULL
import customtkinter as ctk
import threading
import subprocess
import os
from RunManager import RunManager
from VenvManager import VenvManager
class GUI:
startUpInformationlabel = None
startUpFrame = None
initializeFrame = None
inputDirectoryLabel = None
outputDirectoryLabel = None
initializeInfoLabel = None
inputDirectory = None
outputDirectory = None
modelCombobox = None
scaleSlider = None
scaleLabel = None
faceCheckbox = None
fp32Checkbox = None
window = None
runManager = RunManager()
venv_manager = VenvManager()
def __init__(self):
self.inputDirectory = os.getcwd()
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("green")
self.window = ctk.CTk()
self.window.title("Upscale with Real ESRGAN")
self.window.geometry("700x500")
"""
StartUp Frame Widgets
"""
self.startUpFrame = ctk.CTkFrame(master=self.window)
self.startUpInformationlabel = ctk.CTkLabel(master=self.startUpFrame, text='')
startupButton = ctk.CTkButton(
master=self.startUpFrame,
text="Startup",
command=self.StartTheStartup
)
self.startUpInformationlabel.pack(side="top")
startupButton.pack()
self.startUpFrame.pack(pady=25)
"""
Initialize Frame Widgets
"""
self.initializeFrame = ctk.CTkFrame(master=self.window)
self.inputDirectoryLabel = ctk.CTkLabel(master=self.initializeFrame, text=f'{os.getcwd()}\input')
self.outputDirectoryLabel = ctk.CTkLabel(master=self.initializeFrame, text=f'{os.getcwd()}\output')
inputSelectButton = ctk.CTkButton(
master = self.initializeFrame,
text="Choose Directory",
command=self.ChangeInputDirectory
)
outputSelectButton = ctk.CTkButton(
master = self.initializeFrame,
text="Choose Directory",
command=self.ChangeOutputDirectory
)
modelString = tk.StringVar()
self.modelCombobox = ctk.CTkComboBox(
self.initializeFrame,
width=300,
variable= modelString,
state='readonly',
values=['RealESRGAN_x4plus',
'RealESRNet_x4plus',
'RealESRGAN_x4plus_anime_6B',
'RealESRGAN_x2plus',
'realesr-general-x4v3']
)
modelNameLabel = ctk.CTkLabel(self.initializeFrame, text="Model Name")
self.scaleLabel = ctk.CTkLabel(self.initializeFrame, text="Scale : 3")
self.scaleSlider = ctk.CTkSlider(
master=self.initializeFrame,
width=200,
from_=2,
to=4,
number_of_steps=2,
command=self.SliderEvent
)
faceLabel = ctk.CTkLabel(self.initializeFrame, text="Face Enhancement")
self.faceCheckbox = ctk.CTkCheckBox(
master=self.initializeFrame,
text="",
onvalue=1,
offvalue=0
)
fp32Label = ctk.CTkLabel(self.initializeFrame, text="FP32")
self.fp32Checkbox = ctk.CTkCheckBox(
master=self.initializeFrame,
text="",
onvalue=1,
offvalue=0
)
self.inputDirectoryLabel.grid(column=0, row=0, padx=(0, 50), ipady=5)
inputSelectButton.grid(column=1, row=0)
self.outputDirectoryLabel.grid(column=0, row=1, padx=(0, 50), ipady=5)
outputSelectButton.grid(column=1, row=1)
modelNameLabel.grid(column=0, row=2, padx=(0, 50), ipady=5)
self.modelCombobox.grid(column=1, row=2)
self.scaleLabel.grid(column=0, row=3, padx=(0, 50), ipady=5)
self.scaleSlider.grid(column=1, row=3)
faceLabel.grid(column=0, row=4, padx=(0, 50), ipady=5)
self.faceCheckbox.grid(column=1, row=4)
fp32Label.grid(column=0, row=5, padx=(0, 50), ipady=5)
self.fp32Checkbox.grid(column=1, row=5)
self.initializeFrame.pack()
initializeButton = ctk.CTkButton(
master=self.window,
text="Initialize",
command=self.StartInitialize
)
initializeButton.pack(pady=30)
self.initializeInfoLabel = ctk.CTkLabel(master=self.window, text="")
self.initializeInfoLabel.pack()
def SliderEvent(self, value):
self.scaleLabel.configure(text=f"Scale : {int(self.scaleSlider.get())}")
def ChangeInputDirectory(self):
self.initializeInfoLabel.configure(text="")
self.inputDirectory = filedialog.askdirectory(initialdir=self.inputDirectory)
self.inputDirectoryLabel.configure(text=f"{self.inputDirectory}")
self.runManager.inputFolder = self.inputDirectory
def ChangeOutputDirectory(self):
self.outputDirectory = filedialog.askdirectory(mustexist=True, initialdir=os.getcwd())
self.outputDirectoryLabel.configure(text=self.outputDirectory)
self.runManager.outputFolder = self.outputDirectory
def Initialize(self):
self.runManager.venv_manager = self.venv_manager
self.runManager.modelName = self.modelCombobox.get()
self.runManager.scale = f"{int(self.scaleSlider.get())}"
self.runManager.faceEnhance = self.faceCheckbox.get()
self.runManager.fp32 = self.fp32Checkbox.get()
self.initializeInfoLabel.configure(text="Upscaling ...")
self.runManager.Run()
self.initializeInfoLabel.configure(text="DONE!!!")
print("DONE!!!")
def StartUp(self):
if os.path.exists(os.path.join("third-party", "Real-ESRGAN")):
self.startUpInformationlabel.configure(text="Real-ESRGAN repo is already installed")
return
realesrgan_repokey = "realesrgan"
if os.path.exists(os.path.join("third-party", "Real-ESRGAN")) is False:
self.venv_manager.CloneRepository("https://github.com/xinntao/Real-ESRGAN.git", realesrgan_repokey, "third-party")
self.venv_manager.InstallRequirementsFromRepository(realesrgan_repokey)
self.venv_manager.RunScriptInsideRepository(realesrgan_repokey, "setup.py develop")
self.startUpInformationlabel.configure(text="Installation is completed!!! You can continue")
print("Installation is completed!!! You can continue")
def Loop(self):
self.window.mainloop()
def Refresh(self):
self.window.update()
self.window.after(1000, self.Refresh)
def StartTheStartup(self):
self.Refresh()
threading.Thread(target=self.StartUp).start()
def StartInitialize(self):
self.Refresh()
threading.Thread(target=self.Initialize).start()