-
Notifications
You must be signed in to change notification settings - Fork 1
/
playDND.py
124 lines (100 loc) · 3.64 KB
/
playDND.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
from chatgpt_wrapper import ChatGPT
from animate import load_animation, stream_text_horizontal
from campaign import cleanup, save
from runflask import runFlask
from imageGen import prepare_prompts
import os
import sys
import importlib
bot = ChatGPT()
class Story:
# Return the story to the summarizer.
def __init__(self, content) -> None:
self.campaign = content
def __str__(self):
return ' '.join(self.campaign)
def saveGame(self):
formatted_campaign = cleanup(self.__str__())
filename = save(formatted_campaign)
summaryFile = self.summarizeCampaign(filename)
return summaryFile
def summarizeCampaign(self, storyFile):
summarizer = importlib.import_module("bert-cnn")
return summarizer.bert_model(storyFile)
def generateImages(self, summaryFile):
prepare_prompts(summaryFile)
class Player:
_idx = 0
players = []
def __init__(self, playerName, charClass, charName, charRace) -> None:
Player._idx += 1
self.idx = self._idx
self.playerName = playerName
self.charClass = charClass
self.charName = charName
self.charRace = charRace
def __str__(self) -> str:
return "Player {} -> Name:{}, Character Class:{}, Character Name:{}, Character Race:{}".format(self.idx, self.playerName, self.charClass, self.charName, self.charRace)
def __repr__(self) -> str:
return self.charName + " the " + self.charClass + " of " + self.charRace + " race"
def get_info():
welcome_prompt = "Greetings, adventurers! Are you ready to embark on a journey into the realm of DnD?"
stream_text_horizontal(welcome_prompt)
etc = "Press Enter to continue..."
stream_text_horizontal(etc)
input()
player_prompt = "How many players are in for today's adventure?"
stream_text_horizontal(player_prompt)
n_players = int(input(">> "))
print("\n")
for i in range(n_players):
curr_player = "Player " + str(i+1)
stream_text_horizontal("Enter Name for "+curr_player)
pName = input(">> ")
stream_text_horizontal("Enter Character Class for "+curr_player)
pCClass = input(">> ")
stream_text_horizontal("Enter Character Name for "+curr_player)
pCName = input(">> ")
stream_text_horizontal("Enter Character Race for "+curr_player)
pCRace = input(">> ")
Player.players.append(Player(pName, pCClass, pCName, pCRace))
print("\n")
os.system("clear")
def playDND():
campaign = []
prem = []
filename = "identity1.txt"
with open(filename, 'r') as f:
content = f.read()
premise_prompt = content.format([i for i in Player.players])
for chunk in bot.ask_stream(premise_prompt):
prem.append(chunk)
sys.stdout.write(chunk)
sys.stdout.flush()
campaign.append("".join(prem))
print("\n")
while (True):
chunks = []
query = input(">> ")
if (query == "quit"):
os.system('clear')
story = Story(campaign)
stream_text_horizontal("Summarizing the campaign ...")
summaryFile = story.saveGame()
stream_text_horizontal("Generating images from campaign ...")
story.generateImages(summaryFile)
runFlask()
break
for chunk in bot.ask_stream(query):
chunks.append(chunk)
sys.stdout.write(chunk)
sys.stdout.flush()
campaign.append("".join(chunks))
print("\n")
if __name__ == '__main__':
# Play initial animation
load_animation()
# Gather data about players
get_info()
# Start the game
playDND()