-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.py
157 lines (131 loc) · 6.45 KB
/
main.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
#!/usr/bin/python3
# tooltips
# Please read this tutorial on how to prepare your images for use with DeepCreamPy.
# The greater the number of variations, the longer decensoring process will be.
import sys
from PySide6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QGridLayout, QGroupBox, QApplication
from PySide6.QtGui import QGuiApplication, QFont, QTextCursor, QScreen
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QRadioButton, QPushButton, QTextEdit, QLabel, QSizePolicy, QMainWindow, QStatusBar, QProgressBar
from decensor import Decensor
from signals import Signals
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.signals = Signals()
self.initUI()
self.setSignals()
self.decensor = None
self.current_is_mosaic = None
def initUI(self):
grid_layout = QGridLayout()
grid_layout.setSpacing(10)
self.setLayout(grid_layout)
self.tutorialLabel = QLabel()
self.tutorialLabel.setText("Welcome to DeepCreamPy!\n\nIf you're new to DCP, please read the README.\nThis program does nothing without the proper setup of your images.\n\nReport any bugs you encounter to me on Github or Twitter @deeppomf.")
self.tutorialLabel.setAlignment(Qt.AlignCenter)
self.tutorialLabel.setFont(QFont('Sans Serif', 13))
self.censorTypeGroupBox = QGroupBox('Censor Type')
barButton = QRadioButton('Bar censor')
mosaicButton = QRadioButton('Mosaic censor')
barButton.setChecked(True)
censorLayout = QVBoxLayout()
censorLayout.addWidget(barButton)
censorLayout.addWidget(mosaicButton)
self.censorTypeGroupBox.setLayout(censorLayout)
self.variationsGroupBox = QGroupBox('Number of Decensor Variations')
var1Button = QRadioButton('1')
var2Button = QRadioButton('2')
var3Button = QRadioButton('4')
var1Button.setChecked(True)
varLayout = QVBoxLayout()
varLayout.addWidget(var1Button)
varLayout.addWidget(var2Button)
varLayout.addWidget(var3Button)
self.variationsGroupBox.setLayout(varLayout)
self.loadModelButton = QPushButton('Load Model')
self.loadModelButton.clicked.connect(self.load_model)
self.loadModelButton.setSizePolicy(
QSizePolicy.Preferred,
QSizePolicy.Preferred)
self.decensorButton = QPushButton('Decensor Your Images')
self.decensorButton.clicked.connect(self.decensorClicked)
self.decensorButton.setSizePolicy(
QSizePolicy.Preferred,
QSizePolicy.Preferred)
self.decensorButton.setEnabled(False)
self.progressMessage = QTextEdit()
self.progressCursor = QTextCursor(self.progressMessage.document())
self.progressMessage.setTextCursor(self.progressCursor)
self.progressMessage.setReadOnly(True)
self.progressCursor.insertText("After you prepared your images, click on the decensor button once to begin decensoring.\nPlease be patient.\nDecensoring will take time.\n")
self.statusBar = QStatusBar(self)
self.progressBar = QProgressBar()
self.progressBar.setMinimum(0)
self.progressBar.setMaximum(100)
self.progressBar.setValue(0)
self.statusLabel = QLabel("Showing Progress")
self.statusBar.addWidget(self.statusLabel, 1)
self.statusBar.addWidget(self.progressBar, 2)
grid_layout.addWidget(self.tutorialLabel, 0, 0, 1, 2)
grid_layout.addWidget(self.censorTypeGroupBox, 1, 0, 1, 1)
grid_layout.addWidget(self.variationsGroupBox, 1, 1, 1, 1)
grid_layout.addWidget(self.loadModelButton, 2, 0, 1, 1)
grid_layout.addWidget(self.decensorButton, 2, 1, 1, 1)
grid_layout.addWidget(self.progressMessage, 3, 0, 1, 2)
grid_layout.addWidget(self.statusBar, 4, 0, 1, 2)
self.resize(900, 600)
self.center()
self.setWindowTitle('DeepCreamPy v2.2.0-beta')
self.show()
def load_model(self):
censorTypeElements = self.censorTypeGroupBox.children()
censorButtons = [elem for elem in censorTypeElements if isinstance(elem, QRadioButton)]
for cb in censorButtons:
if cb.isChecked():
censorType = cb.text()
is_mosaic = censorType == 'Bar censor'
if self.current_is_mosaic != is_mosaic:
self.decensor = Decensor(self)
self.current_is_mosaic = is_mosaic
self.loadModelButton.setEnabled(True)
if is_mosaic:
self.decensor.is_mosaic = False
else:
self.decensor.is_mosaic = True
self.decensor.start()
self.decensor.signals = self.signals
def setSignals(self):
self.signals.update_decensorButton_Text.connect(self.decensorButton.setText)
self.signals.update_decensorButton_Enabled.connect(self.decensorButton.setEnabled)
self.signals.update_statusLabel_Text.connect(self.statusLabel.setText)
self.signals.update_ProgressBar_SET_VALUE.connect(self.progressBar.setValue)
self.signals.update_ProgressBar_MAX_VALUE.connect(self.progressBar.setMaximum)
self.signals.update_ProgressBar_MIN_VALUE.connect(self.progressBar.setMinimum)
self.signals.insertText_progressCursor.connect(self.progressMessage.append)
self.signals.clear_progressMessage.connect(self.progressMessage.clear)
self.signals.appendText_progressMessage.connect(self.progressMessage.append)
def decensorClicked(self):
self.decensorButton.setEnabled(False)
self.progressMessage.clear()
self.progressCursor.insertText("Decensoring has begun!\n")
variationsElements = self.variationsGroupBox.children()
variationsButtons = [elem for elem in variationsElements if isinstance(elem, QRadioButton)]
for vb in variationsButtons:
if vb.isChecked():
variations = int(vb.text())
self.decensor.variations = variations
self.decensorButton.setEnabled(False)
self.decensor.start()
def center(self):
available_geometry = QGuiApplication.primaryScreen().availableGeometry()
self.move(available_geometry.center() - self.rect().center())
if __name__ == '__main__':
import os
if os.name == 'nt':
import PySide6
pyqt = os.path.dirname(PySide6.__file__)
QApplication.addLibraryPath(os.path.join(pyqt, "plugins"))
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec())