-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_pygui.py
82 lines (68 loc) · 2.4 KB
/
main_pygui.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
import PySimpleGUI as sg
import openai
import pyperclip
# Set up OpenAI API credentials
openai.api_key = "YOUR_API_KEY"
# Define the ChatGPT function that sends a prompt to OpenAI and returns the response
def chat_gpt(prompt):
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)
message = response.choices[0].text
return message.strip()
# Define the PySimpleGUI layout
sg.theme('LightGrey1')
layout = [
[sg.Text('ChatGPT', font=('Helvetica', 20), pad=(5, 5))],
[sg.Multiline('', key='conversation', font=('Helvetica', 14), size=(60, 10), pad=(5, 5))],
[
sg.Input('', key='input_message', font=('Helvetica', 14), size=(50, 1), pad=(5, 5)),
sg.Button('Send', font=('Helvetica', 14), pad=(5, 5))
],
[sg.Button('Toggle Theme', font=('Helvetica', 14), pad=(5, 5))],
[
sg.TabGroup([
[
sg.Tab('Jailbreaking', [
[sg.Button('Button 1'), sg.Button('Button 2'), sg.Button('Button 3'), sg.Button('Button 4'), sg.Button('Button 5')]
])
]
])
]
]
# Create the PySimpleGUI window
window = sg.Window('ChatGPT', layout)
# Start the PySimpleGUI event loop
while True:
event, values = window.read()
# Exit the event loop when the window is closed
if event == sg.WINDOW_CLOSED:
break
# Toggle between light and dark theme
if event == 'Toggle Theme':
if sg.theme() == 'LightGrey1':
sg.theme('DarkGrey1')
else:
sg.theme('LightGrey1')
# Send the user's message and get a response from ChatGPT
if event == 'Send':
# Get the user's input message
message = values['input_message']
# Clear the input field
window['input_message'].update('')
# Add the user's message to the conversation area
window['conversation'].print('You: ' + message)
# Call ChatGPT to get a response
response = chat_gpt(message)
# Add the response to the conversation area
window['conversation'].print('ChatGPT: ' + response)
# Copy the text to the clipboard when the button is clicked
if event.startswith('Button'):
pyperclip.copy('Button ' + event[-1] + ' text copied to clipboard!')
# Close the PySimpleGUI window when the event loop is exited
window.close()