-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pages.py
331 lines (322 loc) · 11.4 KB
/
pages.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
from shiny import App, render, ui, reactive
import shinyswatch
from classes import Npc, Game
from utils import add_tooltip, img_to_base64str
PAGE_HOME = ui.TagList(
ui.div(
{"id": "page-0-content"},
# ui.h1("Try it for free"),
add_tooltip(
ui.input_password(
"API_key",
"OpenAI key",
placeholder="Provide your OpenAI key. Now it's GPT4 + Dall-e 3 so the free version is limited to N requests per month",
value="",
width="100%",
),
"Your OpenAI API key. Optional",
),
ui.output_ui(id="missing_api_key"),
ui.row(
ui.column(
6,
ui.output_ui(id="new_world_button"),
style_="margin-top: 40px;",
),
ui.column(
6,
ui.output_ui(id="upload_existing_world"),
style_="margin-top: 40px;",
),
),
class_="main-page-container col-lg-7 col-md-8 col-sm-10 col-12 mx-auto",
),
)
PAGE_WORLD_CREATE = ui.TagList(
ui.div(
{"id": "create-world-content"},
ui.h1("Try it for free"),
add_tooltip(
ui.input_text(
"new_world_name",
"World name",
placeholder="World name",
value="My world",
width="100%",
),
"The name of your world",
),
add_tooltip(
ui.input_text_area(
"new_world_description",
"Input your world description",
value="A mid-sized village situated by the river in medieval Moldova. \
It has a self-sufficient community surrounded by a wooden palisade. There is a market \
square, a church, and fields for growing crops and grazing livestock. The villagers \
are engaged in crafts, and in times of war or danger, they rely on a small militia \
from nearby castle.",
placeholder="World description",
width="100%",
rows=6,
resize="none",
),
"The prompt for ChatGPT to generate the world",
),
ui.h4("General settings", style_="text-align: center; width: 100%;"),
ui.row(
{"id": "create-world-settings"},
ui.column(
3,
add_tooltip(
ui.input_select(
"new_world_npc_num",
"# NPCs",
[*range(1, 16)],
selected=2,
width="80%",
),
"The number of NPCs in the world",
),
),
ui.column(
3,
add_tooltip(
ui.input_numeric(
"new_world_temperature",
"t (°C)",
value=0,
width="80%",
),
"The initial temperature of the world",
),
),
ui.column(
6,
add_tooltip(
ui.input_checkbox_group(
"images_to_generate",
"Choose type of images to generate:",
{
"text_to_image_generate_world": ui.span("World"),
"text_to_image_generate_npcs": ui.span("Npcs"),
},
selected=[
"text_to_image_generate_world",
"text_to_image_generate_npcs",
],
# width="33.3%"
),
"Choose type of images to generate. It will take more time to generate the result",
),
),
class_="text-panel",
style_="border-radius: 5px 5px 5px 5px/25px 25px 25px 5px;"
),
ui.h4("Time settings", style_="text-align: center; width: 100%; margin-top: 1rem;"),
ui.div(
ui.row(
{"id": "create-world-datetime"},
add_tooltip(
ui.input_numeric("new_world_year", "Year", value=1000, width="25%"),
"The initial year of the world",
),
add_tooltip(
ui.input_select(
"new_world_era",
"Era",
["AD", "BC"],
width="25%",
),
"The initial era of the world",
),
add_tooltip(
ui.input_select(
"new_world_day",
"Day",
[*range(1, 32)],
width="25%",
),
"The initial day of the world",
),
add_tooltip(
ui.input_select(
"new_world_month",
"Month",
{
"1": "January",
"2": "February",
"3": "March",
"4": "April",
"5": "May",
"6": "June",
"7": "July",
"8": "August",
"9": "September",
"10": "October",
"11": "November",
"12": "December",
},
width="25%",
),
"The initial month of the world",
),
),
ui.row(
add_tooltip(
ui.input_select(
"new_world_hour",
"Hour",
[*range(0, 24)],
selected=12,
width="33.3%",
),
"The initial hour of the world",
),
add_tooltip(
ui.input_select(
"new_world_minute",
"Minute",
[*range(0, 60)],
selected=0,
width="33.3%",
),
"The initial minute of the world",
),
add_tooltip(
ui.input_select(
"new_world_second",
"Second",
[*range(0, 60)],
selected=0,
width="33.3%",
),
"The initial second of the world",
),
),
class_="text-panel",
style_="border-radius: 5px 5px 5px 5px/25px 25px 25px 5px;"
),
ui.div(
ui.input_action_button(
"to_page_world_loading",
"Create new world",
width="100%",
style_="margin-top: 1rem;"
),
),
ui.tags.script(
"""
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
"""
),
class_="main-page-container main-page-container col-lg-9 col-md-10 col-sm-12 col-12 mx-auto",
)
)
PAGE_WORLD_LOADING = ui.TagList(
ui.div(
{"id": "loading-world-content"},
ui.row(
ui.h1(
ui.output_text("loading_world_header_text"),
class_="loading_world_header",
),
ui.img(
id="loading_world_image",
src="img/loading.svg",
class_="loading_world_image",
),
ui.div(
ui.span(
"The process of generating the world relies on ChatGPT. It typically takes between 1 to 3 minutes to complete, and the time it takes depends on the number of NPCs",
),
style_="margin-top: 40px;",
),
),
class_="main-page-container col-lg-7 col-md-8 col-sm-10 col-12 mx-auto",
)
)
PAGE_WORLD_UPDATING = ui.TagList(
ui.div(
{"id": "updating-world-content"},
ui.row(
ui.h1(
ui.output_text("updating_world_header_text"),
class_="updating_world_header",
),
ui.img(
id="loading_world_image",
src="img/loading.svg",
class_="loading_world_image",
),
ui.div(
ui.span(
"The process of updating the world relies on ChatGPT. It typically takes between 1 to 2 minutes to complete, and the time it takes depends on the number of NPCs",
),
style_="margin-top: 40px;",
),
),
class_="main-page-container col-lg-7 col-md-8 col-sm-10 col-12 mx-auto",
)
)
PAGE_WORLD_INTERACT = ui.TagList(
ui.div(
{"id": "interact-world-content"},
ui.h1(ui.output_text("world_interact_header")),
ui.navset_tab_card(
ui.nav_menu(
"NPCs",
ui.nav(
f"NPC placeholder",
"NPC placeholder",
value=f"npc_placeholder",
),
value="npcs_nav_menu",
),
id="world_interact_tabs",
footer=ui.download_button("download_world", "Save the world", style_="margin-top: 1rem;")
),
ui.row(
ui.column(
3,
ui.output_ui(id="world_tick_rate_input", style_="margin-top: 12px; width: 90%;"),
),
ui.column(
3,
ui.output_ui(id="world_tick_type_input", style_="margin-top: 12px; width: 90%;"),
),
ui.column(
6,
ui.input_action_button(
"to_page_world_updating",
ui.output_text("world_progress_button_text"),
width="100%",
style_="height: 80%;",
),
),
),
class_="main-page-container col-lg-9 col-md-12 col-sm-12 col-12 mx-auto",
)
)
def create_page_missing_api_key(header="API key is missing!", message='OpenAI API key is missing. Please provide it to be able to generate the world.'):
# return PAGE_MISSING_API_KEY
page_missing_api_key = ui.TagList(
ui.div(
{"id": "page-0-content"},
ui.h1(header),
ui.div(
ui.div(
ui.p(message),
ui.a(
"Get your OpenAI API key here",
href="https://help.openai.com/en/articles/4936850-where-do-i-find-my-api-key",
style_="color: #fff;",
target="_blank",
),
class_="text-panel well",
),
class_="main-page-container col-lg-12 col-md-12 col-sm-12 col-12 mx-auto",
),
),
)
return page_missing_api_key