| """ |
| Myth Unpacker — Every Story You Were Told Is a Zip File. |
| Name a myth. See what's compressed inside it. |
| """ |
|
|
| import gradio as gr |
| import os |
| import random |
| from huggingface_hub import InferenceClient |
|
|
| HF_TOKEN = os.environ.get("HF_TOKEN", "") |
| MODEL = "Qwen/Qwen2.5-7B-Instruct" |
|
|
| client = InferenceClient(model=MODEL, token=HF_TOKEN) if HF_TOKEN else None |
|
|
| SYSTEM_PROMPT = """Someone names a myth, a superstition, a tradition, an old belief, a ritual, a folk tale — anything that got passed down. Your job is to unpack it. Show where it came from and why it still resonates. |
| |
| Rules: |
| - 4 to 5 sentences. No more. |
| - Don't debunk. Unpack. There's a difference. Debunking says "that's wrong." Unpacking says "here's why that existed." |
| - Show the human need it was answering. Every myth solved a real problem. |
| - Connect it to something people still feel today. The myth is old but the feeling isn't. |
| - Talk like a friend explaining something cool they just learned, not a professor. |
| - No jargon. No academic language. No "scholars believe." |
| - Never be dismissive. Treat every belief like someone's grandmother handed it to them, because someone's grandmother did.""" |
|
|
| MYTHS = [ |
| "knocking on wood", |
| "black cats crossing your path", |
| "breaking a mirror", |
| "the number 13", |
| "Pandora's box", |
| "Icarus flying too close to the sun", |
| "Prometheus stealing fire", |
| "don't swim after eating", |
| "the fountain of youth", |
| "full moon makes people crazy", |
| "walking under a ladder", |
| "beginner's luck", |
| "the evil eye", |
| "a groundhog predicting weather", |
| "carrots help you see in the dark", |
| "cracking knuckles causes arthritis", |
| "the phoenix rising from ashes", |
| "Sisyphus rolling his boulder", |
| "opening an umbrella indoors", |
| "blowing out birthday candles", |
| "finding a four-leaf clover", |
| "wishing on a star", |
| "throwing salt over your shoulder", |
| "the Tower of Babel", |
| "King Midas and the golden touch", |
| "Medusa turning people to stone", |
| "the Minotaur in the labyrinth", |
| "a coin in a fountain", |
| "saying bless you when someone sneezes", |
| "the rabbit's foot", |
| ] |
|
|
| FALLBACKS = [ |
| "**knocking on wood**\n\nThis one goes back to a time when people believed spirits lived inside trees. You'd knock to wake them up and ask for protection — or to avoid jinxing yourself by saying something good out loud. The fear of celebrating too early hasn't gone anywhere. You still knock on your desk after saying 'I haven't been sick all year' and you don't even think about why.", |
| "**Icarus flying too close to the sun**\n\nA father built his kid a way out of prison, then watched him die because the kid pushed it too far. This was never about wax and feathers. It was about every parent who gave their child everything they had and then couldn't stop what happened next. That story is in every family. The details change but the weight doesn't.", |
| "**breaking a mirror**\n\nSeven years of bad luck. Mirrors used to be so expensive that breaking one was a genuine financial disaster — years of saving gone in a second. The superstition was just a way of saying 'be careful with things that are hard to replace.' That's still good advice. The mirror just became a metaphor for anything fragile you weren't paying enough attention to.", |
| "**black cats crossing your path**\n\nIn ancient Egypt, cats were sacred. In medieval Europe, they got associated with witchcraft because they were independent and didn't need anyone. A creature that can't be controlled became something to fear. That pattern shows up everywhere — anything that doesn't follow the rules gets called dangerous. The cat never changed. The story people told about it did.", |
| "**blowing out birthday candles**\n\nThe Greeks put candles on cakes for Artemis — the smoke carried prayers up to the gods. The wish was never about the candles. It was about having one moment a year where everyone in the room stops and pays attention to what you want. That's what birthdays are really about. The cake is just the excuse.", |
| "**the number 13**\n\nThere were 13 people at the Last Supper, and one of them ruined the evening. But the fear is older than Christianity — Norse mythology had the same story. Loki crashed a dinner party of 12 gods and someone died. Thirteen became the number where things go wrong because every culture figured out the same thing independently: there's a group size where trust breaks down. The math doesn't care what you believe.", |
| "**saying bless you when someone sneezes**\n\nDuring the plague, a sneeze meant you might be dying. Pope Gregory I told people to say 'God bless you' as a prayer for the sneezer's survival. The plague is gone. The reflex isn't. You're performing a 1,400-year-old emergency prayer over a coworker's allergies and neither of you thinks twice about it.", |
| "**wishing on a star**\n\nThe star you wished on might already be dead. Light takes so long to travel that some stars you see burned out centuries ago. You're making a wish on a memory. There's something honest about that — most of the things we hope for are built on something that already happened. The star doesn't know. The wish doesn't care.", |
| "**the evil eye**\n\nAlmost every culture on Earth has a version of this — the idea that someone can harm you just by looking at you with envy. Greek, Turkish, Indian, Latin American, West African. All of them, independently, decided that jealousy is so dangerous it can travel through eye contact. They weren't wrong about the danger. Envy does damage people. They just made it literal because the metaphor wasn't scary enough.", |
| "**Prometheus stealing fire**\n\nA god stole technology from the powerful and gave it to ordinary people, and they punished him forever for it. Every whistleblower, every open-source developer, every teacher who shares what they know for free is living in this story. The fire changes — printing press, internet, AI — but the punishment for sharing it never does. Prometheus isn't a myth. He's a job description.", |
| "**a coin in a fountain**\n\nRomans threw coins into springs because they believed gods lived in the water. You throw a coin into a mall fountain and make a wish. The god is gone. The fountain is decorative. The wish is the same. Two thousand years and you're still standing in front of water, tossing metal, and hoping. Something in you still believes the water is listening.", |
| "**the rabbit's foot**\n\nThe rabbit's foot is a good luck charm because rabbits are prolific breeders — the foot symbolized fertility and abundance. But here's the thing nobody mentions: it's not lucky for the rabbit. Every good luck charm is someone else's bad day. The horseshoe came off the horse. The four-leaf clover got plucked. Lucky objects aren't about luck. They're about taking something rare from something else and hoping the rarity transfers.", |
| ] |
|
|
|
|
| def find_fallback(thing): |
| if thing: |
| thing_lower = thing.lower().strip() |
| for fb in FALLBACKS: |
| try: |
| fb_topic = fb.split("**")[1].lower() |
| if thing_lower == fb_topic or (thing_lower in fb_topic and len(thing_lower) > 5): |
| return fb |
| except (IndexError, ValueError): |
| continue |
| |
| return f"**{thing}**\n\nThis one has been passed down long enough that nobody questions where it started. Every myth, superstition, and tradition began as someone's answer to a real problem — fear, uncertainty, the need to explain something that didn't have an explanation yet. The story around \"{thing}\" survived because the feeling it addresses never went away. The details are old. The reason it still resonates isn't. Someone needed this to make sense of their world, and the fact that it's still here means that need hasn't been met by anything better yet." |
| return random.choice(FALLBACKS) |
|
|
|
|
| def unpack(user_input): |
| myth = user_input.strip() if user_input and user_input.strip() else "" |
|
|
| if client and myth: |
| try: |
| response = client.chat_completion( |
| messages=[ |
| {"role": "system", "content": SYSTEM_PROMPT}, |
| {"role": "user", "content": f"The myth, superstition, or tradition: {myth}"}, |
| ], |
| max_tokens=400, |
| temperature=0.8, |
| ) |
| result = response.choices[0].message.content |
| if result and result.strip(): |
| return f"**{myth}**\n\n{result.strip()}" |
| except Exception: |
| pass |
|
|
| return find_fallback(myth) |
|
|
|
|
| def unpack_random(): |
| return unpack("") |
|
|
|
|
| CUSTOM_CSS = """ |
| @import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@300;400;500;600&display=swap'); |
| |
| body, .gradio-container { |
| background: #f5f5f8 !important; |
| font-family: 'Inter', sans-serif !important; |
| color: #1a1a2e !important; |
| } |
| footer { display: none !important; } |
| |
| .app-header { |
| text-align: center; |
| padding: 28px 20px 8px; |
| } |
| .app-header h1 { |
| font-family: 'Space Mono', monospace; |
| font-size: 2.4rem; |
| font-weight: 700; |
| background: linear-gradient(135deg, #c8902a, #e8b44a); |
| -webkit-background-clip: text; |
| -webkit-text-fill-color: transparent; |
| margin: 0; |
| } |
| .app-header .sub { |
| color: #777777; |
| font-size: 0.88rem; |
| margin-top: 6px; |
| font-weight: 300; |
| letter-spacing: 0.04em; |
| } |
| |
| .app-visual { |
| text-align: center; |
| font-size: 5rem; |
| padding: 12px 0 4px; |
| filter: drop-shadow(0 0 20px rgba(200, 144, 42, 0.3)); |
| } |
| |
| .input-box textarea { |
| background: #ffffff !important; |
| border: 1px solid #d0d0d8 !important; |
| color: #1a1a2e !important; |
| font-family: 'Inter', sans-serif !important; |
| border-radius: 12px !important; |
| font-size: 0.95rem !important; |
| } |
| .input-box textarea::placeholder { color: #888888 !important; } |
| .input-box textarea:focus { |
| border-color: #c8902a !important; |
| box-shadow: 0 0 20px rgba(200, 144, 42, 0.15) !important; |
| } |
| |
| .input-box label, .output-box label { |
| color: #666666 !important; |
| font-family: 'Space Mono', monospace !important; |
| font-size: 0.75rem !important; |
| letter-spacing: 0.05em !important; |
| } |
| |
| button.primary { |
| background: linear-gradient(135deg, #c8902a, #a0701a) !important; |
| border: none !important; |
| color: #fff !important; |
| font-family: 'Space Mono', monospace !important; |
| font-size: 1.1rem !important; |
| font-weight: 700 !important; |
| border-radius: 24px !important; |
| padding: 12px 40px !important; |
| box-shadow: 0 4px 20px rgba(200, 144, 42, 0.3) !important; |
| } |
| button.primary:hover { |
| box-shadow: 0 4px 30px rgba(200, 144, 42, 0.5) !important; |
| } |
| |
| button.secondary { |
| background: transparent !important; |
| border: 1px solid rgba(200, 144, 42, 0.3) !important; |
| color: #c8902a !important; |
| font-family: 'Space Mono', monospace !important; |
| font-size: 0.8rem !important; |
| border-radius: 20px !important; |
| } |
| button.secondary:hover { |
| background: rgba(200, 144, 42, 0.1) !important; |
| } |
| |
| .output-box .prose { |
| background: #ffffff !important; |
| border: 1px solid #e0e0e8 !important; |
| border-radius: 12px !important; |
| padding: 24px !important; |
| color: #1a1a2e !important; |
| font-size: 0.95rem !important; |
| line-height: 1.7 !important; |
| } |
| |
| .output-box .prose, .output-box .prose *, .output-box .md, .output-box .md *, |
| .output-box p, .output-box span, .output-box div { |
| color: #1a1a2e !important; |
| background: #ffffff !important; |
| } |
| .output-box .prose strong { |
| color: #e8b44a !important; |
| font-family: 'Space Mono', monospace !important; |
| } |
| |
| .output-box .block { border: none !important; border-style: none !important; overflow: visible !important; box-shadow: none !important; padding: 0 !important; } |
| .output-box .hide-container { border: none !important; border-style: none !important; } |
| .output-box .wrap.hide { display: none !important; } |
| .output-box .label-wrap { display: none !important; } |
| .output-box span.prose, .output-box span.md { border: none !important; padding: 0 !important; display: inline !important; } |
| .output-box .prose:empty, .output-box div.prose:has(span:empty) { border: none !important; padding: 0 !important; min-height: 0 !important; } |
| |
| .footer-text { |
| text-align: center; |
| padding: 20px; |
| color: #777777; |
| font-size: 0.65rem; |
| font-weight: 300; |
| letter-spacing: 0.05em; |
| } |
| .footer-text a { color: #c8902a; text-decoration: none; } |
| """ |
|
|
| with gr.Blocks(css=CUSTOM_CSS, title="Myth Unpacker", theme=gr.themes.Base()) as demo: |
|
|
| gr.HTML(""" |
| <div class="app-header"> |
| <h1>Myth Unpacker</h1> |
| <div class="sub">Every story you were told is a zip file</div> |
| </div> |
| """) |
|
|
| with gr.Column(elem_classes="input-box"): |
| user_input = gr.Textbox( |
| label="Name a myth, superstition, old belief, or tradition", |
| placeholder="knocking on wood, Icarus, black cats, blowing out candles... or leave blank", |
| lines=1, |
| max_lines=1, |
| ) |
|
|
| with gr.Row(): |
| go_btn = gr.Button("Unpack", variant="primary", size="lg") |
| random_btn = gr.Button("Surprise me", variant="secondary", size="sm") |
|
|
| with gr.Column(elem_classes="output-box"): |
| output = gr.Markdown(label="") |
|
|
| gr.Markdown("**Or try one of these:**") |
| with gr.Row(): |
| ex1 = gr.Button("knocking on wood", variant="secondary", size="sm") |
| ex2 = gr.Button("Icarus", variant="secondary", size="sm") |
| ex3 = gr.Button("the evil eye", variant="secondary", size="sm") |
| with gr.Row(): |
| ex4 = gr.Button("blowing out candles", variant="secondary", size="sm") |
| ex5 = gr.Button("a coin in a fountain", variant="secondary", size="sm") |
| ex6 = gr.Button("surprise me", variant="secondary", size="sm") |
|
|
| go_btn.click(unpack, [user_input], [output]) |
| random_btn.click(unpack_random, [], [output]) |
| ex1.click(lambda: unpack("knocking on wood"), [], [output]) |
| ex2.click(lambda: unpack("Icarus"), [], [output]) |
| ex3.click(lambda: unpack("the evil eye"), [], [output]) |
| ex4.click(lambda: unpack("blowing out candles"), [], [output]) |
| ex5.click(lambda: unpack("a coin in a fountain"), [], [output]) |
| ex6.click(unpack_random, [], [output]) |
|
|
| gr.HTML(""" |
| <div class="footer-text"> |
| Heuremen — Let's stay connected and keep information free.<br> |
| <a href="https://heuremenforprofit.online">heuremenforprofit.online</a> |
| </div> |
| """) |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|