-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
152 lines (119 loc) · 5.13 KB
/
app.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import streamlit as st
import random as rd
import datetime as dt
import os
from dotenv import load_dotenv
load_dotenv()
st.set_page_config(layout="wide")
# =========== Functions ====================================
@st.cache # don't re-import data every time the app re-runs
def import_data(data_file_name):
with open(data_file_name, "r") as file:
data = file.readlines()
data = [word for line in data for word in line.split()]
return data
def generate_NPC():
sex = rd.sample(['male','female'],1)[0]
if sex == 'male':
names = rd.sample(male_names_list,2)
elif sex == 'female':
names = rd.sample(female_names_list,2)
alias = rd.sample(aliases_list,1)[0]
physical_appearance = rd.sample(physical_traits_list,2)
clothing = rd.sample(clothing_list,1)[0]
race = rd.sample(races_list,1)[0]
personality = rd.sample(personality_traits_list,2)
flavour = rd.sample(flavours_list,1)[0]
description = f"""
\n
NAME OPTIONS: {names}.\n
ALIAS: {alias}.\n
PHYSICAL APPEARANCE: {[physical_appearance,sex, race]}.\n
CLOTHING: {clothing}.\n
PERSONALITY: {personality}.\n
FLAVOUR: {flavour}.\n
OCCUPATION: .\n
GOALS: .\n
RESOURCES: .\n
NOTES FROM PLAYER INTERACTIONS: .\n
CREATED DATE: {dt.datetime.now().strftime("%Y-%m-%d %H:%M")}.\n
"""
return description
def select_faction():
faction = rd.sample(factions_list,1)
return faction
def generate_extra_flavour():
new_flavour = rd.sample(flavours_list,1)
return new_flavour
def generate_colour():
colour = rd.sample(colours_list,1)
return colour
def select_location():
location = rd.sample(locations_list,1)
return location
# Import the data
personality_traits_list = import_data('data_files/personalities.txt')
physical_traits_list = import_data('data_files/physical_traits.txt')
clothing_list = import_data('data_files/clothing.txt')
flavours_list = import_data('data_files/flavours.txt')
male_names_list = import_data('data_files/male_names.txt')
female_names_list = import_data('data_files/female_names.txt')
aliases_list = import_data('data_files/aliases.txt')
races_list = import_data('data_files/races.txt')
factions_list = import_data('data_files/factions.txt')
colours_list = import_data('data_files/colours.txt')
locations_list = import_data('data_files/locations.txt')
# ========== APP =============================
"# Scum and Villainy NPC creator"
create_character_button = st.button("Create NPC")
if create_character_button:
description = generate_NPC()
st.session_state['character_description'] = description
# This is so the description you generate doesn't disappear if you click other buttons
if 'character_description' in st.session_state:
st.write(st.session_state['character_description']) # basically, if you generated an NPC, print that NPC
col1a, col2a = st.columns(2)
col1b, col2b = st.columns(2)
# Button for giving you a random extra flavour
generate_flavour_button = col1a.checkbox("Give me an extra flavour")
if generate_flavour_button:
new_flavour = generate_extra_flavour()
st.session_state['generated_flavour'] = new_flavour[0]
col1a.write(st.session_state['generated_flavour'])
st.session_state['character_description'] += f'''EXTRA FLAVOUR: {st.session_state['generated_flavour']}. \n'''
# Button for giving you a random faction
generate_faction_button = col2a.checkbox("Give me a random faction")
if generate_faction_button:
faction = select_faction()
st.session_state['generated_faction'] = faction[0]
col2a.write(st.session_state['generated_faction'])
st.session_state['character_description'] += f'''FACTION: {st.session_state['generated_faction']}. \n'''
# Button for giving you a random colour
generate_colour_button = col1b.checkbox("Need a random colour for clothes skin, hair etc?")
if generate_colour_button:
colour = generate_colour()
st.session_state['generated_colour'] = colour[0]
col1b.write(st.session_state['generated_colour'])
st.session_state['character_description'] += f'''GENERATED COLOUR: {st.session_state['generated_colour']}. \n'''
# Button for giving you a random location
generate_location_button = col2b.checkbox("Sample random sub-system")
if generate_location_button:
location = select_location()
st.session_state['generated_location'] = location[0]
col2b.write(st.session_state['generated_location'])
st.session_state['character_description'] += f'''LOCATION: {st.session_state['generated_location']}. \n'''
# Exporting
export_character_button = st.button('Export')
if export_character_button:
export_location = os.getenv("EXPORT_LOCATION")
if export_location is not None: #if
filepath = export_location
else:
filepath = ''
filename = "S&V_generated_NPCs.md"
f"Saving NPC to {filepath+filename}"
NPC_to_export = st.session_state['character_description']
NPC_to_export = NPC_to_export.replace('.\n','.')
with open((filepath+filename),'a') as f: # Append the NPC to the file
f.write("## <NAME> ") # Add a markdown header
f.write(NPC_to_export) # add the character