-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
172 lines (131 loc) · 5 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
import sys
from PySide6.QtCore import Qt, QThread, Signal
from PySide6.QtWidgets import (
QApplication,
QDialog,
QHBoxLayout,
QLabel,
QLineEdit,
QMainWindow,
QMessageBox,
QProgressDialog,
QPushButton,
QVBoxLayout,
QWidget,
)
from main import main
class WorkerThread(QThread):
finished = Signal()
error = Signal(str)
def __init__(self, word_count, prompt):
super().__init__()
self.word_count = word_count
self.prompt = prompt
def run(self):
try:
main(self.word_count, self.prompt)
except Exception as e:
self.error.emit(str(e))
finally:
self.finished.emit()
class CustomPopup(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Video Complete!")
self.setModal(True)
self.layout = QVBoxLayout()
self.setLayout(self.layout)
message_label = QLabel("Video generation complete!")
message_label.setStyleSheet("font-size: 18px; font-weight: bold;")
message_label.setAlignment(Qt.AlignCenter)
self.layout.addWidget(message_label)
button_layout = QHBoxLayout()
self.quit_button = QPushButton("Quit")
self.quit_button.clicked.connect(self.close_application)
button_layout.addWidget(self.quit_button)
self.regenerate_button = QPushButton("Regenerate")
self.regenerate_button.clicked.connect(self.reset_form)
button_layout.addWidget(self.regenerate_button)
self.layout.addLayout(button_layout)
def close_application(self):
QApplication.instance().quit()
def reset_form(self):
self.done(1)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("AI Content Generation System")
central_widget = QWidget()
self.setCentralWidget(central_widget)
self.layout = QVBoxLayout()
self.layout.setAlignment(Qt.AlignCenter)
title_label = QLabel("AI Content Generation System")
title_label.setStyleSheet("font-size: 24px; font-weight: bold;")
title_label.setAlignment(Qt.AlignCenter)
self.layout.addWidget(title_label)
self.word_count_label = QLabel("Word Count (30-200):")
self.word_count_label.setStyleSheet("font-size: 18px;")
self.layout.addWidget(self.word_count_label)
self.word_count_input = QLineEdit()
self.word_count_input.setPlaceholderText("Enter word count (e.g., 50)")
self.layout.addWidget(self.word_count_input)
self.prompt_label = QLabel("Prompt:")
self.prompt_label.setStyleSheet("font-size: 18px;")
self.layout.addWidget(self.prompt_label)
self.prompt_input = QLineEdit()
self.prompt_input.setPlaceholderText("Enter your prompt")
self.layout.addWidget(self.prompt_input)
self.submit_button = QPushButton("Submit")
self.submit_button.clicked.connect(self.start_generation)
self.layout.addWidget(self.submit_button)
central_widget.setLayout(self.layout)
self.progress_dialog = None
self.worker_thread = None
def start_generation(self):
word_count = self.word_count_input.text()
prompt = self.prompt_input.text()
if not word_count.isdigit() or not 30 <= int(word_count) <= 200:
QMessageBox.warning(
self, "Invalid Input", "Word count must be between 30 and 200."
)
return
if not prompt.strip():
QMessageBox.warning(
self, "Invalid Input", "Prompt cannot be empty."
)
return
self.submit_button.setEnabled(False)
self.progress_dialog = QProgressDialog(
"Generating video, please wait...", None, 0, 0, self
)
self.progress_dialog.setWindowTitle("Processing")
self.progress_dialog.setWindowModality(Qt.WindowModal)
self.progress_dialog.show()
self.worker_thread = WorkerThread(word_count, prompt)
self.worker_thread.finished.connect(self.complete_generation)
self.worker_thread.error.connect(self.show_error)
self.worker_thread.start()
def complete_generation(self):
if self.progress_dialog:
self.progress_dialog.close()
self.progress_dialog = None
popup = CustomPopup(self)
if popup.exec() == 1:
self.reset_form()
def reset_form(self):
self.word_count_input.clear()
self.prompt_input.clear()
self.submit_button.setEnabled(True)
def show_error(self, error_message):
if self.progress_dialog:
self.progress_dialog.close()
self.progress_dialog = None
self.submit_button.setEnabled(True)
QMessageBox.critical(
self, "Error", f"An error occurred:\n{error_message}"
)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())