justmichaelaj commited on
Commit
acccd91
1 Parent(s): d216c73

Create main project

Browse files
Files changed (1) hide show
  1. main project +134 -0
main project ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import Constants
3
+ import sys
4
+ import openai
5
+ from PyQt5.QtCore import Qt
6
+ from PyQt5.QtGui import QPixmap
7
+ from PyQt5.QtWidgets import (
8
+ QApplication,
9
+ QWidget,
10
+ QLabel,
11
+ QLineEdit,
12
+ QPushButton,
13
+ QVBoxLayout,
14
+ QHBoxLayout,
15
+ QGroupBox,
16
+ QTextEdit
17
+ )
18
+
19
+ openai.api_key = Constants.API_KEY
20
+
21
+
22
+ class MainWindow(QWidget):
23
+ def __init__(self):
24
+ super().__init__()
25
+ self.init_ui()
26
+
27
+ def init_ui(self):
28
+ self.logo_label = QLabel()
29
+ self.logo_pixmap = QPixmap('michaelajayi.jpg').scaled(
30
+ 500, 500, Qt.KeepAspectRatio, Qt.SmoothTransformation)
31
+ self.logo_label.setPixmap(self.logo_pixmap)
32
+
33
+ self.input_label = QLabel('Ask Something')
34
+ self.input_field = QLineEdit()
35
+ self.input_field.setPlaceholderText('Type here...')
36
+ self.answer_label = QLabel('Answer:')
37
+ self.answer_field = QTextEdit()
38
+ self.answer_field.setReadOnly(True)
39
+ self.sumbit_button = QPushButton('Sumbit')
40
+ self.sumbit_button.setStyleSheet(
41
+ """
42
+ QPushButton {
43
+ background-color: #2F3540;
44
+ border: none;
45
+ color: white;
46
+ padding: 15px 32px;
47
+ font-size: 18px;
48
+ font-weight: bold;
49
+ border-radius: 25px;
50
+ }
51
+ QpushButton:hover {
52
+ background-color: #3e8e41;
53
+ }
54
+ """
55
+
56
+ )
57
+ self.recommended_questions_group = QGroupBox('Recommended Questions')
58
+ self.recommended_questions_layout = QVBoxLayout()
59
+ self.recommended_questions = ["What is the four corner opposition?",
60
+ "How do I become a better storyteller?", "What are some popular ways to get better at writting?"]
61
+ self.question_buttons = []
62
+
63
+ # Create a layout
64
+ layout = QVBoxLayout()
65
+ layout.setContentsMargins(20, 20, 20, 20)
66
+ layout.setSpacing(50)
67
+ layout.setAlignment(Qt.AlignCenter)
68
+
69
+ # Add Logo
70
+ layout.addWidget(self.logo_label, alignment=Qt.AlignCenter)
71
+
72
+ # Add Input Field and Sumbit Button
73
+ input_layout = QHBoxLayout()
74
+ input_layout.addWidget(self.input_label)
75
+ input_layout.addWidget(self.input_field)
76
+ input_layout.addWidget(self.sumbit_button)
77
+ layout.addLayout(input_layout)
78
+
79
+ # Add Answer Field
80
+ layout.addWidget(self.answer_label)
81
+ layout.addWidget(self.answer_field)
82
+
83
+ # add the recommended questions buttons
84
+ for question in self.recommended_questions:
85
+ button = QPushButton(question)
86
+ button.setStyleSheet(
87
+ """
88
+ QPushButton {
89
+ background-color: #FFFFFF:
90
+ border: 2px solid #00AEFF;
91
+ colour: #00AEFF;
92
+ padding: 10px 20px;
93
+ font-size: 30px;
94
+ font-weight: bold;
95
+ border-radius: 5px;
96
+ }
97
+ QPushButton:hover {
98
+ background-color: #00AEFF;
99
+ color: #FFFFFF;
100
+ }"""
101
+ )
102
+ button.clicked.connect(
103
+ lambda _, q=question: self.input_field.setText(q))
104
+ self.recommended_questions_layout.addWidget(button)
105
+ self.question_buttons.append(button)
106
+ self.recommended_questions_group.setLayout(
107
+ self.recommended_questions_layout)
108
+ layout.addWidget(self.recommended_questions_group)
109
+
110
+ # Set the layout
111
+ self.setLayout(layout)
112
+
113
+ # Set the window properties
114
+ self.setWindowTitle('Storyteller Writer Advisor Bot')
115
+ self.setGeometry(200, 200, 600, 600)
116
+
117
+ # Connect the submit button to the function which queries OpenAI's API
118
+ self.sumbit_button.clicked.connect(self.get_answer)
119
+
120
+ def get_answer(self):
121
+ question = self.input_field.text()
122
+
123
+ completion = openai.ChatCompletion.create(
124
+ model="gpt-4",
125
+ messages=[
126
+ {"role": "system", "content": "You are a Storyteller expert. Answer the follwing questions in a concise way or with bullet points."},
127
+ {"role": "user", "content": "What is the four corner opposition?"},
128
+ {"role": "assistant", "content": "A story structure writing technique that draws the lines between four leading charcters conflicts."},
129
+ {"role": "user", "content": f'{question}'}],
130
+ max_tokens=1024,
131
+ n=1,
132
+ stop=None,
133
+ temperature=1
134
+ )