Spaces:
Sleeping
Sleeping
Commit ·
b730ea2
0
Parent(s):
initial commit
Browse files- README.md +28 -0
- app.py +232 -0
- requirements.txt +2 -0
README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: History Contextualizer
|
| 3 |
+
emoji: 📰
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
+
license: mit
|
| 9 |
+
short_description: Every "unprecedented" thing has a receipt.
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# History Contextualizer — Every "Unprecedented" Thing Has a Receipt
|
| 13 |
+
|
| 14 |
+
Name something happening right now. See when it happened before.
|
| 15 |
+
|
| 16 |
+
## What this is
|
| 17 |
+
|
| 18 |
+
AI taking jobs. Housing nobody can afford. Book banning. Political polarization. Everyone addicted to screens. Feels new, right?
|
| 19 |
+
|
| 20 |
+
It's not. This finds the specific year, place, and people where the same thing played out. Not "throughout history" — a specific moment. The parallel. The receipt.
|
| 21 |
+
|
| 22 |
+
## How it works
|
| 23 |
+
|
| 24 |
+
Type something happening right now that feels unprecedented. Or leave it blank and it'll pick one. The model pulls the historical receipt — the specific moment this exact thing happened before. No moralizing. No lessons. Just the fact that you're not the first person standing here.
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
Heuremen — Let's stay connected and keep information free.
|
app.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
History Contextualizer — Every "Unprecedented" Thing Has a Receipt.
|
| 3 |
+
Name something happening now. See when it happened before.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import os
|
| 8 |
+
import random
|
| 9 |
+
from huggingface_hub import InferenceClient
|
| 10 |
+
|
| 11 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 12 |
+
MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 13 |
+
|
| 14 |
+
client = InferenceClient(model=MODEL, token=HF_TOKEN) if HF_TOKEN else None
|
| 15 |
+
|
| 16 |
+
SYSTEM_PROMPT = """Someone describes something happening in the world right now — politically, socially, culturally, economically, technologically. Your job is to show them when this exact thing happened before. The parallel. The receipt.
|
| 17 |
+
|
| 18 |
+
Rules:
|
| 19 |
+
- 4 to 5 sentences. No more.
|
| 20 |
+
- Be specific. Name the year, the place, the people. Not "throughout history" — give a specific moment.
|
| 21 |
+
- Show the parallel clearly. What rhymes between then and now.
|
| 22 |
+
- Don't moralize. Don't say what should happen. Just show what did happen last time.
|
| 23 |
+
- The point isn't "history repeats itself." The point is "you're not the first person standing here."
|
| 24 |
+
- Talk like a friend who stayed up reading Wikipedia until 3am, not a history teacher.
|
| 25 |
+
- No "many scholars argue." No hedging. Just show the receipt."""
|
| 26 |
+
|
| 27 |
+
EVENTS = [
|
| 28 |
+
"AI taking people's jobs",
|
| 29 |
+
"billionaires going to space",
|
| 30 |
+
"book banning",
|
| 31 |
+
"culture war over what kids learn in school",
|
| 32 |
+
"distrust in the media",
|
| 33 |
+
"everyone addicted to their phones",
|
| 34 |
+
"housing prices nobody can afford",
|
| 35 |
+
"inflation making groceries expensive",
|
| 36 |
+
"misinformation spreading faster than truth",
|
| 37 |
+
"political polarization",
|
| 38 |
+
"people leaving cities for small towns",
|
| 39 |
+
"a pandemic changing everything",
|
| 40 |
+
"student debt crisis",
|
| 41 |
+
"social media making people depressed",
|
| 42 |
+
"wealth gap growing",
|
| 43 |
+
"people not trusting elections",
|
| 44 |
+
"new technology scaring everyone",
|
| 45 |
+
"a generation that can't afford to have kids",
|
| 46 |
+
"empire in decline",
|
| 47 |
+
"workers demanding better conditions",
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
FALLBACKS = [
|
| 51 |
+
"**AI taking people's jobs**\n\nIn 1830, a group of English textile workers called the Luddites smashed weaving machines with hammers because the machines were replacing them. They weren't wrong — the machines did replace them. But their grandchildren worked jobs that didn't exist yet when the hammers came out. The fear was real. The future was just unrecognizable from where they were standing. Same spot you're in right now.",
|
| 52 |
+
"**billionaires going to space**\n\nIn the 1490s, the richest families in Europe funded ships to cross the Atlantic. They said it was about discovery. It was about getting their name on something bigger than money could buy on land. Bezos and Musk aren't astronauts. They're the Medicis with better rockets. The pitch hasn't changed in 500 years — it's still 'exploration' that happens to come with a flag and a tax break.",
|
| 53 |
+
"**everyone addicted to their phones**\n\nWhen novels became cheap enough for regular people to buy in the 1800s, doctors warned that reading fiction was destroying young minds — especially women's. They called it a public health crisis. The concern was real: people were ignoring their families, staying up all night, living in fantasy worlds. Sound familiar? The screen changed. The worry about it didn't.",
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def contextualize(user_input):
|
| 58 |
+
event = user_input.strip() if user_input and user_input.strip() else random.choice(EVENTS)
|
| 59 |
+
prompt = f"Something happening right now: {event}"
|
| 60 |
+
|
| 61 |
+
if client:
|
| 62 |
+
try:
|
| 63 |
+
response = client.chat_completion(
|
| 64 |
+
messages=[
|
| 65 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 66 |
+
{"role": "user", "content": prompt},
|
| 67 |
+
],
|
| 68 |
+
max_tokens=400,
|
| 69 |
+
temperature=0.8,
|
| 70 |
+
)
|
| 71 |
+
result = response.choices[0].message.content
|
| 72 |
+
if not result or not result.strip():
|
| 73 |
+
return random.choice(FALLBACKS)
|
| 74 |
+
return f"**{event}**\n\n{result.strip()}"
|
| 75 |
+
except Exception:
|
| 76 |
+
return random.choice(FALLBACKS)
|
| 77 |
+
else:
|
| 78 |
+
return random.choice(FALLBACKS)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def clear():
|
| 82 |
+
return "", ""
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
CUSTOM_CSS = """
|
| 86 |
+
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@300;400;500;600&display=swap');
|
| 87 |
+
|
| 88 |
+
body, .gradio-container {
|
| 89 |
+
background: #0a0806 !important;
|
| 90 |
+
font-family: 'Inter', sans-serif !important;
|
| 91 |
+
color: #d8d0c0 !important;
|
| 92 |
+
}
|
| 93 |
+
footer { display: none !important; }
|
| 94 |
+
|
| 95 |
+
.app-header {
|
| 96 |
+
text-align: center;
|
| 97 |
+
padding: 28px 20px 8px;
|
| 98 |
+
}
|
| 99 |
+
.app-header h1 {
|
| 100 |
+
font-family: 'Space Mono', monospace;
|
| 101 |
+
font-size: 2.2rem;
|
| 102 |
+
font-weight: 700;
|
| 103 |
+
background: linear-gradient(135deg, #a08060, #d0b080);
|
| 104 |
+
-webkit-background-clip: text;
|
| 105 |
+
-webkit-text-fill-color: transparent;
|
| 106 |
+
margin: 0;
|
| 107 |
+
}
|
| 108 |
+
.app-header .sub {
|
| 109 |
+
color: #7a7060;
|
| 110 |
+
font-size: 0.88rem;
|
| 111 |
+
margin-top: 6px;
|
| 112 |
+
font-weight: 300;
|
| 113 |
+
letter-spacing: 0.04em;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
.app-visual {
|
| 117 |
+
text-align: center;
|
| 118 |
+
font-size: 5rem;
|
| 119 |
+
padding: 12px 0 4px;
|
| 120 |
+
filter: drop-shadow(0 0 20px rgba(160, 128, 96, 0.3));
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.input-box textarea {
|
| 124 |
+
background: #141008 !important;
|
| 125 |
+
border: 1px solid rgba(160, 128, 96, 0.25) !important;
|
| 126 |
+
color: #d8d0c0 !important;
|
| 127 |
+
font-family: 'Inter', sans-serif !important;
|
| 128 |
+
border-radius: 12px !important;
|
| 129 |
+
font-size: 0.95rem !important;
|
| 130 |
+
}
|
| 131 |
+
.input-box textarea::placeholder { color: #7a7060 !important; }
|
| 132 |
+
.input-box textarea:focus {
|
| 133 |
+
border-color: #a08060 !important;
|
| 134 |
+
box-shadow: 0 0 20px rgba(160, 128, 96, 0.15) !important;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.input-box label, .output-box label {
|
| 138 |
+
color: #7a7060 !important;
|
| 139 |
+
font-family: 'Space Mono', monospace !important;
|
| 140 |
+
font-size: 0.75rem !important;
|
| 141 |
+
letter-spacing: 0.05em !important;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
button.primary {
|
| 145 |
+
background: linear-gradient(135deg, #a08060, #806040) !important;
|
| 146 |
+
border: none !important;
|
| 147 |
+
color: #fff !important;
|
| 148 |
+
font-family: 'Space Mono', monospace !important;
|
| 149 |
+
font-size: 1.1rem !important;
|
| 150 |
+
font-weight: 700 !important;
|
| 151 |
+
border-radius: 24px !important;
|
| 152 |
+
padding: 12px 40px !important;
|
| 153 |
+
box-shadow: 0 4px 20px rgba(160, 128, 96, 0.3) !important;
|
| 154 |
+
}
|
| 155 |
+
button.primary:hover {
|
| 156 |
+
box-shadow: 0 4px 30px rgba(160, 128, 96, 0.5) !important;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
button.secondary {
|
| 160 |
+
background: transparent !important;
|
| 161 |
+
border: 1px solid rgba(160, 128, 96, 0.3) !important;
|
| 162 |
+
color: #a08060 !important;
|
| 163 |
+
font-family: 'Space Mono', monospace !important;
|
| 164 |
+
font-size: 0.8rem !important;
|
| 165 |
+
border-radius: 20px !important;
|
| 166 |
+
}
|
| 167 |
+
button.secondary:hover {
|
| 168 |
+
background: rgba(160, 128, 96, 0.1) !important;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
.output-box .prose {
|
| 172 |
+
background: #141008 !important;
|
| 173 |
+
border: 1px solid rgba(160, 128, 96, 0.15) !important;
|
| 174 |
+
border-radius: 12px !important;
|
| 175 |
+
padding: 24px !important;
|
| 176 |
+
color: #d8d0c0 !important;
|
| 177 |
+
font-size: 0.95rem !important;
|
| 178 |
+
line-height: 1.7 !important;
|
| 179 |
+
}
|
| 180 |
+
.output-box .prose strong {
|
| 181 |
+
color: #d0b080 !important;
|
| 182 |
+
font-family: 'Space Mono', monospace !important;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
.footer-text {
|
| 186 |
+
text-align: center;
|
| 187 |
+
padding: 20px;
|
| 188 |
+
color: #7a7060;
|
| 189 |
+
font-size: 0.65rem;
|
| 190 |
+
font-weight: 300;
|
| 191 |
+
letter-spacing: 0.05em;
|
| 192 |
+
}
|
| 193 |
+
.footer-text a { color: #a08060; text-decoration: none; }
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
with gr.Blocks(css=CUSTOM_CSS, title="History Contextualizer", theme=gr.themes.Base()) as demo:
|
| 197 |
+
|
| 198 |
+
gr.HTML("""
|
| 199 |
+
<div class="app-header">
|
| 200 |
+
<h1>History Contextualizer</h1>
|
| 201 |
+
<div class="sub">Every "unprecedented" thing has a receipt</div>
|
| 202 |
+
</div>
|
| 203 |
+
<div class="app-visual">📰</div>
|
| 204 |
+
""")
|
| 205 |
+
|
| 206 |
+
with gr.Column(elem_classes="input-box"):
|
| 207 |
+
user_input = gr.Textbox(
|
| 208 |
+
label="What's happening right now that feels new?",
|
| 209 |
+
placeholder="AI taking jobs, housing crisis, book banning, political polarization...",
|
| 210 |
+
lines=1,
|
| 211 |
+
max_lines=2,
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
with gr.Row():
|
| 215 |
+
go_btn = gr.Button("Pull the receipt", variant="primary", size="lg")
|
| 216 |
+
clear_btn = gr.Button("Another one", variant="secondary", size="sm")
|
| 217 |
+
|
| 218 |
+
with gr.Column(elem_classes="output-box"):
|
| 219 |
+
output = gr.Markdown(label="")
|
| 220 |
+
|
| 221 |
+
go_btn.click(contextualize, [user_input], [output])
|
| 222 |
+
clear_btn.click(clear, [], [user_input, output])
|
| 223 |
+
|
| 224 |
+
gr.HTML("""
|
| 225 |
+
<div class="footer-text">
|
| 226 |
+
Heuremen — Let's stay connected and keep information free.<br>
|
| 227 |
+
<a href="https://heuremenforprofit.online">heuremenforprofit.online</a>
|
| 228 |
+
</div>
|
| 229 |
+
""")
|
| 230 |
+
|
| 231 |
+
if __name__ == "__main__":
|
| 232 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=5.0.0
|
| 2 |
+
huggingface_hub>=0.20.0
|