File size: 4,644 Bytes
acccd91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import Constants
import sys
import openai
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (
    QApplication,
    QWidget,
    QLabel,
    QLineEdit,
    QPushButton,
    QVBoxLayout,
    QHBoxLayout,
    QGroupBox,
    QTextEdit
)

openai.api_key = Constants.API_KEY


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        self.logo_label = QLabel()
        self.logo_pixmap = QPixmap('michaelajayi.jpg').scaled(
            500, 500, Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.logo_label.setPixmap(self.logo_pixmap)

        self.input_label = QLabel('Ask Something')
        self.input_field = QLineEdit()
        self.input_field.setPlaceholderText('Type here...')
        self.answer_label = QLabel('Answer:')
        self.answer_field = QTextEdit()
        self.answer_field.setReadOnly(True)
        self.sumbit_button = QPushButton('Sumbit')
        self.sumbit_button.setStyleSheet(
            """
            QPushButton {
                background-color: #2F3540;
                border: none;
                color: white;
                padding: 15px 32px;
                font-size: 18px;
                font-weight: bold;
                border-radius: 25px;
                }
            QpushButton:hover {
                background-color: #3e8e41;
                }
                """

        )
        self.recommended_questions_group = QGroupBox('Recommended Questions')
        self.recommended_questions_layout = QVBoxLayout()
        self.recommended_questions = ["What is the four corner opposition?",
                                      "How do I become a better storyteller?", "What are some popular ways to get better at writting?"]
        self.question_buttons = []

        # Create a layout
        layout = QVBoxLayout()
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(50)
        layout.setAlignment(Qt.AlignCenter)

        # Add Logo
        layout.addWidget(self.logo_label, alignment=Qt.AlignCenter)

        # Add Input Field and Sumbit Button
        input_layout = QHBoxLayout()
        input_layout.addWidget(self.input_label)
        input_layout.addWidget(self.input_field)
        input_layout.addWidget(self.sumbit_button)
        layout.addLayout(input_layout)

        # Add Answer Field
        layout.addWidget(self.answer_label)
        layout.addWidget(self.answer_field)

        # add the recommended questions buttons
        for question in self.recommended_questions:
            button = QPushButton(question)
            button.setStyleSheet(
                """
                QPushButton {
                    background-color: #FFFFFF:
                    border: 2px solid #00AEFF;
                    colour: #00AEFF;
                    padding: 10px 20px;
                    font-size: 30px;
                    font-weight: bold;
                    border-radius: 5px;
                    }
                    QPushButton:hover {
                        background-color: #00AEFF;
                        color: #FFFFFF;
                        }"""
            )
            button.clicked.connect(
                lambda _, q=question: self.input_field.setText(q))
            self.recommended_questions_layout.addWidget(button)
            self.question_buttons.append(button)
        self.recommended_questions_group.setLayout(
            self.recommended_questions_layout)
        layout.addWidget(self.recommended_questions_group)

        # Set the layout
        self.setLayout(layout)

        # Set the window properties
        self.setWindowTitle('Storyteller Writer Advisor Bot')
        self.setGeometry(200, 200, 600, 600)

        # Connect the submit button to the function which queries OpenAI's API
        self.sumbit_button.clicked.connect(self.get_answer)

    def get_answer(self):
        question = self.input_field.text()

        completion = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[
                {"role": "system", "content": "You are a Storyteller expert. Answer the follwing questions in a concise way or with bullet points."},
                {"role": "user", "content": "What is the four corner opposition?"},
                {"role": "assistant", "content": "A story structure writing technique that draws the lines between four leading charcters conflicts."},
                {"role": "user", "content": f'{question}'}],
            max_tokens=1024,
            n=1,
            stop=None,
            temperature=1
        )