Skip to content

Instantly share code, notes, and snippets.

@mcburton
Created August 26, 2025 16:42
Show Gist options
  • Save mcburton/7c9b5099ceda96647804754f78eb1273 to your computer and use it in GitHub Desktop.
Save mcburton/7c9b5099ceda96647804754f78eb1273 to your computer and use it in GitHub Desktop.
Dr. Burton's really bad mad libs story.
import marimo
__generated_with = "0.14.17"
app = marimo.App(width="medium", auto_download=["html"])
@app.cell
def _(initial_story, mo):
# "Once upon a time in {place} there lived a boy named {name}. He liked to {verb} and {verb} all day long."
story_template = mo.ui.text_area(value=initial_story, )
mo.md(f"""
# Python Mad Libs - Dr. Burton's boring story.
Fill out the mad libs below to create a boring story.
""")
return (story_template,)
@app.cell
def _(generate_widgets, mo, story_template):
# Example usage
#story_template = "Once upon a time in {place} there lived a boy named {name}. He liked to {verb} and {verb} all day long."
widgets = generate_widgets(story_template.value)
#runny = mo.ui.run_button()
# Display the generated widgets
mo.vstack(widgets.values())
return (widgets,)
@app.cell
def _(mo):
runny = mo.ui.run_button(label="Click to generate story.")
runny
return (runny,)
@app.cell
def _(initial_story, mo, runny, widgets):
mo.stop(not runny.value)
barf = {k: v.value for k,v in widgets.items()}
mo.md(initial_story.format(**barf))
return
@app.cell
def _():
# initial story
initial_story="""Once upon a time in the University of {place1}, Professor {noun1} {verb1}
tirelessly in the realm of {academic_discipline1}. With a brilliant mind and
a penchant for {adjective1} theories, {noun1} had become renowned for
pushing the boundaries of {academic_discipline1} during the {time_period1}
era.
One day, while pondering the intricacies of
{theoretical_framework1}, {noun1} stumbled upon a {noun2} that seemed to
{verb2} with the laws of nature itself. Excitement bubbled up in {noun1},
and they couldn't resist delving deeper into this mysterious
{noun2}.
Late into the night, surrounded by stacks of {plural_noun1} and
scribbled equations, {noun1} made a groundbreaking discovery that would
forever change the field of {academic_discipline1}. Their {adjective2}
research had unlocked the secrets of {theoretical_framework1}, ushering in a
new era of {academic_discipline1} exploration.
And so, Professor
{noun1}'s name echoed through the hallowed halls of academia, leaving a
legacy of {adjective3} innovation for generations to come."""
return (initial_story,)
@app.cell
def _():
import marimo as mo
import re
return mo, re
@app.cell
def _(mo, re):
def generate_widgets(story: str):
# Find all placeholders in the story
placeholders = re.findall(r'\{(.*?)\}', story)
return {placeholder: mo.ui.text(value='', label=f"Enter a {placeholder}") for placeholder in placeholders}
return (generate_widgets,)
@app.cell
def _():
return
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment