-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.py
435 lines (385 loc) · 15.1 KB
/
routes.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
"""The navigation routes for the application."""
import os
from quart import Blueprint, render_template, Markup
routes = Blueprint("routes", __name__, static_url_path="", static_folder="assets",)
# Generic routes
@routes.route("/")
def index() -> str:
"""
The home page route.
Returns:
str: The home page template.
"""
return render_template("index.html")
@routes.route("/sidebar")
def sidebar() -> str:
"""
Returns the sidebar. Used to keep one version of the sidebar globally.
Returns:
str: The sidebar template.
"""
return render_template("sidebar.html")
@routes.route("/header")
def header() -> str:
"""
Returns the header. Used to keep one version of the header globally.
Returns:
str: The header template.
"""
return render_template("header.html")
@routes.route("/games")
def games_index() -> str:
"""
The home page for the game project.
Returns:
str: The home page template for games.
"""
return render_template("/games/index.html")
@routes.route("/games/<name>")
def games(name: str) -> str:
"""
The games route. Return the correct game page based on the route.
Args:
name (str): The name of the game to load.
Returns:
str: The template for the corresponding game or the index template if the game
does not exist.
"""
name_map = {
"madgab": "games/madgab.html",
}
if name not in name_map:
return render_template("/games/index.html")
else:
return render_template(name_map[name])
@routes.route("/mixmash")
def mixmash_index() -> str:
"""
Return the mix and mash homepage.
Returns:
str: The mix and mash homepage template.
"""
return render_template("/mixmash/index.html")
@routes.route("/mixmash/<name>")
def mixmash(name: str) -> str:
"""
The mix and mash route. Returns the correct mix and mash project based on the
provided name.
Args:
name (str): The name of the mix and mash project to load.
Returns:
str: The corresponding mix and mash template or the index template if
the project is not found.
"""
if name == "biblicaltrump":
data = {
"project_name": "biblical_trump",
"title": "Biblical Trump",
"description": Markup("""
<p>What would Trump sounds like if he tweeted
during Biblical times?
This is not meant to be political, just having some fun.
Read more about the project
<a href="https://bgreenawald.github.io/blog/2018/markov-text-gen.html">
here.</a></p>
"""),
"gallery_description": Markup("""
<p>See a gallery of some of my favorite biblical Trumpisms.
Capitalization done manually.</p>
"""),
"gallery": [
"Though shalt not go use Twitter Trump",
"I am the Ephraimites best which was great",
"The midst of seventy years agothis is mad sometimes referred to be long massive tax just named Eutychus being stubborn can call it", # noqa: E501
"The original costume was Susan Berry",
"Who was a son of them thou shalt thou art not the word again despite Obamas terrible", # noqa: E501
"Hillary she is a great commercial with retired workers of judah",
"Spectacular panoramic views of the ground",
],
"data": Markup("""
<p>The data for this project was the Gutenburg Bible and an archive of
<a href="https://github.com/mkearney/trumptweets">Trump's tweets</a></p>
""")
}
return render_template("/mixmash/mixmash.html", **data)
else:
return render_template("/mixmash/index.html")
@routes.route("/nntextgen")
def nntextgen_index() -> str:
"""
The home page for the nn text gen project.
Returns:
str: The home page template for nn text gen.
"""
return render_template("/nntextgen/index.html")
@routes.route("/nntextgen/<name>")
def textgen(name: str) -> str:
"""
The NN text gen route. Returns the correct nn text gen project based on the
name.
Args:
name (str): The name of the project to load.
Returns:
str: The corresponding nn text gen template or the index template if the project
does not exist.
"""
data = {
"boy_names": {
"project_name": "boy_names",
"title": "Boy Names",
"description": Markup("""
<p>Generates new boy names from a dataset of 1000 boy names.
Enter some starting characters in the box below (2 characters max) to get the
algorithm started, or leave blank for a random start. Tweak
the options to your liking and click "Generate" when you're ready!</p>
"""),
"iters": list(range(1, 11)),
"selected": 5,
"max_seed_length": 2,
"gallery_description": Markup("""
<p>Some of my favorite generated names.</p>
"""),
"gallery": [
"AngeldeJesus",
"Babatunde",
"Curvin",
"Deforest",
"Gobel",
"Moishy",
"Purvis",
"Riggins",
"Ugo",
"Yer",
],
"gallery_full": Markup("""
<a href="/nntextgen/gallery/boy_names">See the full gallery.</a>
"""),
"data_description": Markup("""
<p>This model was trained on 1000 boy names from
<a href="https://www.babble.com/pregnancy/1000-most-popular-boy-names/">
here.</a></p>
"""),
"data_full": Markup("""
<a href="/nntextgen/data/boy_names">See the full data.</a>
""")
},
"girl_names": {
"project_name": "girl_names",
"title": "Girl Names",
"description": Markup("""
<p>Generates new girls names from a dataset of 1000 girl names.
Enter some starting characters in the box below (2 characters max) to get the
algorithm started, or leave blank for a random start. Tweak
the options to your liking and click "Generate" when you're ready!</p>
"""),
"iters": list(range(1, 11)),
"selected": 5,
"max_seed_length": 2,
"gallery_description": Markup("""
<p>Some of my favorite generated names.</p>
"""),
"gallery": [
"Blonnie",
"Borghild",
"Jamiracle",
"Pasqualina",
"Pearly",
"Rut",
"Sharde",
"Shaquasia",
"Unnamed",
"Vanellope",
],
"gallery_full": Markup("""
<a href="/nntextgen/gallery/girl_names">See the full gallery.</a>
"""),
"data_description": Markup("""
<p>This model was trained on 1000 girl names from
<a href="https://www.babble.com/pregnancy/1000-most-popular-girl-names/">
here.</a></p>
"""),
"data_full": Markup("""
<a href="/nntextgen/data/girl_names">See the full data.</a>
""")
},
"stripper_names": {
"project_name": "stripper_names",
"title": "Stripper Names",
"description": Markup("""
<p>Generates new stripper names from a dataset of over
8000 adult film actresses.
Enter some starting characters in the box below (3 characters max) to get the
algorithm started, or leave blank for a random start. Tweak
the options to your liking and click "Generate" when you're ready!</p>
"""),
"iters": list(range(1, 6)),
"selected": 3,
"max_seed_length": 3,
"gallery_description": Markup("""
<p>Some of my favorite generated names.</p>
"""),
"gallery": [
"Casolyn Fart",
"Soxy Black",
],
"gallery_full": Markup("""
<a href="/nntextgen/gallery/stripper_names">See the full gallery.</a>
"""),
"data_description": Markup("""
<p>This model was trained over 8000 adult film actress names scraped
from various sources.</p>
"""),
"data_full": Markup("""
<a href="/nntextgen/data/stripper_names">See the full data.</a>
""")
},
"pokemon_names": {
"project_name": "pokemon_names",
"title": "Pokemon Names",
"description": Markup("""
<p>Over 800 Pokemon not enough? Generate some new ones!
Enter some starting characters in the box below (2 characters max) to get the
algorithm started, or leave blank for a random start. Tweak
the options to your liking and click "Generate" when you're ready!</p>
"""),
"iters": list(range(1, 11)),
"selected": 5,
"max_seed_length": 2,
"gallery_description": Markup("""
<p>Some of my favorite generated names.</p>
"""),
"gallery": [
"Eoaoeo",
"Gooohu",
"Vesaggy",
],
"gallery_full": Markup("""
<a href="/nntextgen/gallery/pokemon_names">See the full gallery.</a>
"""),
"data_description": Markup("""
<p>This model was train on all Pokemon names (pre Sword and Shield) from
<a href="https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_name">
here.</a></p>
"""),
"data_full": Markup("""
<a href="/nntextgen/data/pokemon_names">See the full data.</a>
""")
},
"dinosaur_names": {
"project_name": "dinosaur_names",
"title": "Dinosaur Names",
"description": Markup("""
<p>Need some inspiration for you latest prehistoric archaeological
discover? Generate yourself some new dinosaurs names!
Enter some starting characters in the box below (2 characters max) to get the
algorithm started, or leave blank for a random start. Tweak
the options to your liking and click "Generate" when you're ready!</p>
"""),
"iters": list(range(1, 6)),
"selected": 3,
"max_seed_length": 2,
"gallery_description": Markup("""
<p>Some of my favorite generated names.</p>
"""),
"gallery": [
"Dampylodon",
"Lemopus",
"Shamag",
],
"gallery_full": Markup("""
<a href="/nntextgen/gallery/dinosaur_names">See the full gallery.</a>
"""),
"data_description": Markup("""
<p>This model was trained on over 1500 dinosaur names from
<a href="https://en.wikipedia.org/wiki/List_of_dinosaur_genera">here.
</a></p>
"""),
"data_full": Markup("""
<a href="/nntextgen/data/dinosaur_names">See the full data.</a>
""")
},
}
if name in data:
return render_template("/nntextgen/nntextgen.html", **data[name])
else:
return render_template("/nntextgen/index.html")
@routes.route("/nntextgen/data/<name>")
def data(name: str) -> str:
"""
Data endpoint for nn text gen projects.
Args:
name (str): The name of the nn text project to get data for.
Returns:
str: The populated data template for the given nn text gen project, or
an error template if the given project is not found.
"""
project_info = {
"boy_names": ("Boy Names", Markup("""
<p>This model was trained on 1000 boy names from
<a href="https://www.babble.com/pregnancy/1000-most-popular-boy-names/">here.</a></p>
""")),
"girl_names": ("Girl Names", Markup("""
<p>This model was trained on 1000 girl names from
<a href="https://www.babble.com/pregnancy/1000-most-popular-girl-names/">here.</a></p>
""")),
"stripper_names": ("Stripper Names", Markup("""
<p>This model was trained on 8000 adult film actress names from a
variety of sources.</p>
""")),
"pokemon_names": ("Pokemon Names", Markup("""
<p>This model was train on all Pokemon names (pre Sword and Shield) from
<a href="https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_name">
here.</a></p>
""")),
"dinosaur_names": ("Dinosaur Names", Markup("""
<p>This model was trained on over 1500 dinosaur names from
<a href="https://en.wikipedia.org/wiki/List_of_dinosaur_genera">here.</a></p>
""")),
}
filename = f"data/nntextgen/{name}/data.txt"
if os.path.exists(filename) and name in project_info:
with open(filename, "r") as file:
data = file.read().split("\n")
ret = {
"title": project_info[name][0],
"data_description": project_info[name][1],
"data": data
}
else:
ret = {
"title": "Error",
"data_description": "A dataset for the given project does not exist",
"data": []
}
return render_template("/nntextgen/data.html", **ret)
@routes.route("/nntextgen/gallery/<name>")
def gallery(name: str) -> str:
"""The gallery endpoint for the nn text gen project.
Args:
name (str): The name of the project to load the gallery for.
Returns:
str: The populated gallery template for the given project, or an error template
if the project is not found.
"""
project_info = {
"boy_names": ("Boy Names", "9000 boy names generated from the model."),
"girl_names": ("Girl Names", "9000 girl names generated from the model."),
"stripper_names": ("Stripper Names", "Over 1000 stripper names generated from the model."),
"pokemon_names": ("Pokemon Names", "Over 500 Pokemon names generated from the model."),
}
filename = f"data/nntextgen/{name}/gallery.txt"
if os.path.exists(filename) and name in project_info:
with open(filename, "r") as file:
data = file.read().split("\n")
ret = {
"title": project_info[name][0],
"gallery_description": project_info[name][1],
"gallery": data,
}
else:
ret = {
"title": "Error",
"data_description": "A gallery for the given project does not exist",
"data": [],
}
return render_template("/nntextgen/gallery.html", **ret)