awacke1 commited on
Commit
c76ba6b
·
verified ·
1 Parent(s): 0285ca1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -1
app.py CHANGED
@@ -426,4 +426,86 @@ if st.button("Generate Story"):
426
  story_paragraphs.append(" ".join(paragraph))
427
 
428
  st.subheader("Generated Story")
429
- st.write("\n\n".join(story_paragraphs))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  story_paragraphs.append(" ".join(paragraph))
427
 
428
  st.subheader("Generated Story")
429
+ st.write("\n\n".join(story_paragraphs))
430
+
431
+
432
+
433
+ import streamlit as st
434
+ import random
435
+ import string
436
+
437
+ st.title("Baby Gecko's Continual Story Generator")
438
+
439
+ # Story Parts
440
+ story_parts = {
441
+ "beginning": [
442
+ "In the realm of [noun], where [idiom], a [adjective] [noun] embarks on an epic journey.",
443
+ "Amidst the [adjective] [noun], a [noun] of unparalleled [noun] emerges, seeking to [rhyme].",
444
+ "In a world fraught with [noun], a [adjective] [noun] arises, determined to [idiom]."
445
+ ],
446
+ "middle": [
447
+ "Endowed with [adjective] [noun], the [noun] [verb_past] through the [adjective] [noun], [rhyme].",
448
+ "With [noun] as their guide, the [noun] [verb_past] the [adjective] [noun], unraveling the secrets of [noun].",
449
+ "Confronted by the [adjective] [noun], the [noun] must [idiom] and [rhyme]."
450
+ ],
451
+ "end": [
452
+ "In a climactic battle of [noun] and [noun], the [noun] [verb_past] the [adjective] [noun], emerging [adjective] and [adjective].",
453
+ "With the power of [noun] and [noun], the [noun] [verb_past] the [adjective] [noun], [rhyme].",
454
+ "Forever changed by their [adjective] journey, the [noun] [verb_past] home, their [noun] forever etched in the annals of [noun]."
455
+ ]
456
+ }
457
+
458
+ # Vocabulary
459
+ vocabulary = {
460
+ "noun": ["quintessence", "paradigm", "phenomenon", "cognizance", "providence", "iniquity", "juxtaposition", "obfuscation", "rescission", "volition"],
461
+ "adjective": ["abstruse", "Byzantine", "chimerical", "draconian", "ephemeral", "inexorable", "labyrinthine", "mercurial", "quixotic", "turgid"],
462
+ "verb_past": ["amalgamated", "bifurcated", "coalesced", "deconstructed", "extrapolated", "juxtaposed", "metamorphosed", "obfuscated", "reified", "transmogrified"],
463
+ "idiom": ["the cat's out of the bag", "a penny for your thoughts", "the elephant in the room", "a leopard can't change its spots", "the writing is on the wall", "a blessing in disguise", "a fish out of water", "a wild goose chase", "a square peg in a round hole", "a needle in a haystack"]
464
+ }
465
+
466
+ # Rhyme Generation (L-System Grammar)
467
+ def generate_rhyme(axiom, rules, iterations):
468
+ rhyme = axiom
469
+ for _ in range(iterations):
470
+ new_rhyme = ""
471
+ for char in rhyme:
472
+ new_rhyme += rules.get(char, char)
473
+ rhyme = new_rhyme
474
+ return rhyme
475
+
476
+ rhyme_axioms = ["A", "B", "C", "D", "E"]
477
+ rhyme_rules = {
478
+ "A": "[adjective] [noun]",
479
+ "B": "[verb_past] with [noun]",
480
+ "C": "in the [adjective] [noun]",
481
+ "D": "where [noun] [verb_past]",
482
+ "E": "and [adjective] [noun] [verb_past]"
483
+ }
484
+
485
+ # Story Generation
486
+ def generate_story():
487
+ story_paragraphs = []
488
+ for part in story_parts:
489
+ paragraph = []
490
+ for sentence_template in story_parts[part]:
491
+ sentence = sentence_template
492
+ for word_type in vocabulary:
493
+ if f"[{word_type}]" in sentence:
494
+ word = random.choice(vocabulary[word_type])
495
+ sentence = sentence.replace(f"[{word_type}]", word, 1)
496
+ if "[rhyme]" in sentence:
497
+ axiom = random.choice(rhyme_axioms)
498
+ rhyme = generate_rhyme(axiom, rhyme_rules, random.randint(1, 3))
499
+ sentence = sentence.replace("[rhyme]", rhyme, 1)
500
+ paragraph.append(sentence)
501
+ story_paragraphs.append(" ".join(paragraph))
502
+ return "\n\n".join(story_paragraphs)
503
+
504
+ # Streamlit App
505
+ if st.button("Generate Story"):
506
+ story = generate_story()
507
+ st.subheader("Generated Story")
508
+ st.write(story)
509
+
510
+
511
+