-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameAssist.py
More file actions
140 lines (107 loc) · 4.39 KB
/
GameAssist.py
File metadata and controls
140 lines (107 loc) · 4.39 KB
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
"""import wx
import openai
# Set up the OpenAI API credentials
openai.api_key = "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"
# Define the emotions and their corresponding characters
emotion_to_character = {
"happy": "Character A",
"angry": "Character B",
"sad": "Character C",
"frustrated": "Character D",
"anxious": "Character E",
"calm": "Character F"
}
class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Bionic Owls AI Game Assist", size=(600, 400))
panel = wx.Panel(self)
# Create the UI elements
text_label = wx.StaticText(panel, label="How do you feel?")
self.text_ctrl = wx.TextCtrl(panel)
button = wx.Button(panel, label="Get Character")
# Bind the button to the click event handler
self.Bind(wx.EVT_BUTTON, self.on_button_click, button)
# Create the layout
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(text_label, 0, wx.ALL, 5)
vbox.Add(self.text_ctrl, 0, wx.ALL|wx.EXPAND, 5)
vbox.Add(button, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(vbox)
def on_button_click(self, event):
description = self.text_ctrl.GetValue()
character = get_character_from_emotion(description)
wx.MessageBox(f"The character corresponding to the emotion is {character}", "Result", wx.OK | wx.ICON_INFORMATION)
def get_character_from_emotion(description):
# Use the GPT-3 model to analyze the description and identify the emotion
response = openai.Completion.create(
engine="text-davinci-002",
prompt="classify the following text as happy, angry, sad, frustrated, anxious or calm:\n" + description + "\nemotion:",
max_tokens=1,
n=1,
stop=None,
temperature=0.7,
)
# Extract the emotion from the OpenAI API response
emotion = response.choices[0].text.strip().lower()
# Return the character corresponding to the identified emotion
return emotion_to_character.get(emotion, "Unknown character")
if __name__ == "__main__":
app = wx.App()
frame = MainWindow()
frame.Show()
app.MainLoop()
"""
import wx
import openai
# Set up the OpenAI API credentials
openai.api_key = "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"
# Define the emotions and their corresponding characters
emotion_to_character = {
"happy": "RBO",
"angry": "EnemyRobot",
"sad": "NBO",
"frustrated": "Character D",
"anxious": "Character E",
"calm": "Character F"
}
class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Bionic Owls AI Game Assist", size=(600, 400))
panel = wx.Panel(self)
# Create the UI elements
text_label = wx.StaticText(panel, label="How do you feel?")
self.text_ctrl = wx.TextCtrl(panel)
self.character_label = wx.StaticText(panel, label="")
button = wx.Button(panel, label="Get Character")
# Bind the button to the click event handler
self.Bind(wx.EVT_BUTTON, self.on_button_click, button)
# Create the layout
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(text_label, 0, wx.ALL, 5)
vbox.Add(self.text_ctrl, 0, wx.ALL|wx.EXPAND, 5)
vbox.Add(button, 0, wx.ALL|wx.CENTER, 5)
vbox.Add(self.character_label, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(vbox)
def on_button_click(self, event):
description = self.text_ctrl.GetValue()
character = get_character_from_emotion(description)
self.character_label.SetLabel(f"The character corresponding to the emotion is {character}")
def get_character_from_emotion(description):
# Use the GPT-3 model to analyze the description and identify the emotion
response = openai.Completion.create(
engine="text-davinci-002",
prompt="classify the following text as happy, angry, sad, frustrated, anxious or calm:\n" + description + "\nemotion:",
max_tokens=1,
n=1,
stop=None,
temperature=0.7,
)
# Extract the emotion from the OpenAI API response
emotion = response.choices[0].text.strip().lower()
# Return the character corresponding to the identified emotion
return emotion_to_character.get(emotion, "Unknown character")
if __name__ == "__main__":
app = wx.App()
frame = MainWindow()
frame.Show()
app.MainLoop()