Spaces:
Running
Running
Upload 2 files
Browse files- app (34).py +83 -0
- cycle_events.json +192 -0
app (34).py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import json, math, numpy as np, plotly.graph_objects as go
|
| 3 |
+
import gradio as gr, os, openai, pathlib
|
| 4 |
+
|
| 5 |
+
# ----- config ----------
|
| 6 |
+
CENTER = 2025
|
| 7 |
+
CYCLES = {
|
| 8 |
+
"K-Wave (50 yr)": 50,
|
| 9 |
+
"Business Cycle (Juglar 9 yr)": 9,
|
| 10 |
+
"Finance Cycle (80 yr)": 80,
|
| 11 |
+
"Hegemony Cycle (250 yr)": 250
|
| 12 |
+
}
|
| 13 |
+
COLOR = {50:"#ff3333",9:"#66ff66",80:"#ffcc00",250:"#66ccff"}
|
| 14 |
+
AMPL = {50:1.0,9:0.6,80:1.6,250:4.0}
|
| 15 |
+
|
| 16 |
+
# ----- load events -----
|
| 17 |
+
events_path = pathlib.Path(__file__).with_name("cycle_events.json")
|
| 18 |
+
with open(events_path, encoding="utf-8") as f:
|
| 19 |
+
EVENTS = {int(e['year']): e['events'] for e in json.load(f)}
|
| 20 |
+
|
| 21 |
+
def half_sine(xs, period, amp):
|
| 22 |
+
phase = np.mod(xs - CENTER, period)
|
| 23 |
+
y = amp * np.sin(np.pi * phase / period)
|
| 24 |
+
y[y < 0] = 0
|
| 25 |
+
return y
|
| 26 |
+
|
| 27 |
+
def build_fig(start, end):
|
| 28 |
+
xs = np.linspace(start, end, (end-start)*4)
|
| 29 |
+
fig = go.Figure()
|
| 30 |
+
# draw towers as lines
|
| 31 |
+
for period in sorted(set(CYCLES.values())):
|
| 32 |
+
y = half_sine(xs, period, AMPL[period])
|
| 33 |
+
fig.add_trace(go.Scatter(x=xs, y=y,
|
| 34 |
+
mode="lines",
|
| 35 |
+
line=dict(color=COLOR[period], width=1),
|
| 36 |
+
hoverinfo="skip",
|
| 37 |
+
showlegend=False))
|
| 38 |
+
# points with hover
|
| 39 |
+
for year, evs in EVENTS.items():
|
| 40 |
+
if start <= year <= end:
|
| 41 |
+
for ev in evs:
|
| 42 |
+
period = CYCLES[ev['cycle']+' Cycle'] if ev['cycle']!='K-Wave' else 50
|
| 43 |
+
# assume first event determines period amplitude
|
| 44 |
+
per = CYCLES.get(ev['cycle'] if ev['cycle']!='K-Wave' else "K-Wave (50 yr)",50)
|
| 45 |
+
y = half_sine(np.array([year]), per, AMPL[per])[0]
|
| 46 |
+
txt_en = "<br>".join(e['event_en'] for e in evs)
|
| 47 |
+
txt_ko = "<br>".join(e['event_ko'] for e in evs)
|
| 48 |
+
fig.add_trace(go.Scatter(
|
| 49 |
+
x=[year], y=[y],
|
| 50 |
+
mode="markers",
|
| 51 |
+
marker=dict(color="white", size=6),
|
| 52 |
+
customdata=[[txt_en, txt_ko]],
|
| 53 |
+
hovertemplate="Year %{x}<br>%{customdata[0]}<br>%{customdata[1]}<extra></extra>",
|
| 54 |
+
showlegend=False
|
| 55 |
+
))
|
| 56 |
+
|
| 57 |
+
fig.update_layout(
|
| 58 |
+
template="plotly_dark",
|
| 59 |
+
height=400,
|
| 60 |
+
margin=dict(t=30, l=40, r=40, b=40)
|
| 61 |
+
)
|
| 62 |
+
fig.update_xaxes(title="Year", range=[start, end])
|
| 63 |
+
fig.update_yaxes(title="Relative amplitude", showticklabels=False)
|
| 64 |
+
return fig
|
| 65 |
+
|
| 66 |
+
# ----- gradio -----
|
| 67 |
+
def make_app():
|
| 68 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 69 |
+
gr.Markdown("## ๐ญ **CycleNavigator (Interactive)**")
|
| 70 |
+
gr.Markdown("<sub>K-Wave 50y โข Business 9y โข Finance 80y โข Hegemony 250y</sub>")
|
| 71 |
+
with gr.Row():
|
| 72 |
+
start = gr.Number(value=1775, label="Start Year")
|
| 73 |
+
end = gr.Number(value=2025, label="End Year")
|
| 74 |
+
plot = gr.Plot(value=build_fig(1775,2025))
|
| 75 |
+
def update(s,e):
|
| 76 |
+
return build_fig(int(s), int(e))
|
| 77 |
+
start.change(update, [start,end], plot)
|
| 78 |
+
end.change(update, [start,end], plot)
|
| 79 |
+
gr.File(value=events_path, label="Download cycle_events.json")
|
| 80 |
+
return demo
|
| 81 |
+
|
| 82 |
+
if __name__ == "__main__":
|
| 83 |
+
make_app().launch()
|
cycle_events.json
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"cycle": "Hegemony",
|
| 12 |
+
"event_en": "US declares independence, emerging power.",
|
| 13 |
+
"event_ko": "๋ฏธ๊ตญ ๋
๋ฆฝ์ ์ธ, ์๋ก์ด ๊ฐ๋๊ตญ ๋ถ์."
|
| 14 |
+
}
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"year": 1815,
|
| 19 |
+
"events": [
|
| 20 |
+
{
|
| 21 |
+
"cycle": "Hegemony",
|
| 22 |
+
"event_en": "Congress of Vienna; British naval supremacy.",
|
| 23 |
+
"event_ko": "๋น ํ์; ์๊ตญ ํด์ ํจ๊ถ ํ๋ฆฝ."
|
| 24 |
+
}
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"year": 1873,
|
| 29 |
+
"events": [
|
| 30 |
+
{
|
| 31 |
+
"cycle": "Finance",
|
| 32 |
+
"event_en": "Panic of 1873 triggers Long Depression.",
|
| 33 |
+
"event_ko": "1873๋
๊ณตํฉ์ผ๋ก ์ฅ๊ธฐ ๋ถํฉ ์์."
|
| 34 |
+
}
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"year": 1879,
|
| 39 |
+
"events": [
|
| 40 |
+
{
|
| 41 |
+
"cycle": "K-Wave",
|
| 42 |
+
"event_en": "Edison practical incandescent bulb ushers Electric Age.",
|
| 43 |
+
"event_ko": "์๋์จ ๋ฐฑ์ด์ ๊ตฌ๋ก ์ ๊ธฐ ์๋ ๊ฐ๋ง."
|
| 44 |
+
}
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"year": 1893,
|
| 49 |
+
"events": [
|
| 50 |
+
{
|
| 51 |
+
"cycle": "Business",
|
| 52 |
+
"event_en": "Panic of 1893 rail & bank failures.",
|
| 53 |
+
"event_ko": "1893๋
์ฒ ๋ยท์ํ ํ์ฐ ๊ณตํฉ."
|
| 54 |
+
}
|
| 55 |
+
]
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"year": 1914,
|
| 59 |
+
"events": [
|
| 60 |
+
{
|
| 61 |
+
"cycle": "Hegemony",
|
| 62 |
+
"event_en": "World War I begins, upends balance of power.",
|
| 63 |
+
"event_ko": "์ 1์ฐจ ์ธ๊ณ๋์ ๋ฐ๋ฐ, ์ธ๋ ฅ ๊ท ํ ๋ถ๊ดด."
|
| 64 |
+
}
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"year": 1929,
|
| 69 |
+
"events": [
|
| 70 |
+
{
|
| 71 |
+
"cycle": "Finance",
|
| 72 |
+
"event_en": "Wall Street crash, Great Depression.",
|
| 73 |
+
"event_ko": "์๊ฐ ๋ถ๊ดด, ๋๊ณตํฉ ์์."
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"cycle": "Business",
|
| 77 |
+
"event_en": "Juglar bust within Great Depression.",
|
| 78 |
+
"event_ko": "๋๊ณตํฉ ๋ด ์ฅฌ๊ธ๋ผ ํ๊ฐ."
|
| 79 |
+
}
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"year": 1945,
|
| 84 |
+
"events": [
|
| 85 |
+
{
|
| 86 |
+
"cycle": "Hegemony",
|
| 87 |
+
"event_en": "WWII ends; US global hegemony.",
|
| 88 |
+
"event_ko": "2์ฐจ๋์ ์ข
์ ; ๋ฏธ๊ตญ ํจ๊ถ ํ๋ฆฝ."
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"cycle": "K-Wave",
|
| 92 |
+
"event_en": "Postwar mass production boom starts.",
|
| 93 |
+
"event_ko": "์ ํ ๋๋์์ฐ ํธํฉ ์์."
|
| 94 |
+
}
|
| 95 |
+
]
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"year": 1973,
|
| 99 |
+
"events": [
|
| 100 |
+
{
|
| 101 |
+
"cycle": "K-Wave",
|
| 102 |
+
"event_en": "Oil shock peaks 4th K-wave.",
|
| 103 |
+
"event_ko": "์ค์ผ์ผํฌ๋ก 4์ฐจ Kํ๋ ์ ์ ."
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
"cycle": "Business",
|
| 107 |
+
"event_en": "1973-75 recession stagflation.",
|
| 108 |
+
"event_ko": "1973-75 ๋ถํฉ ๋ฐ ์คํ๊ทธํ๋ ์ด์
."
|
| 109 |
+
}
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"year": 1982,
|
| 114 |
+
"events": [
|
| 115 |
+
{
|
| 116 |
+
"cycle": "Business",
|
| 117 |
+
"event_en": "Early 80s recession ends inflation.",
|
| 118 |
+
"event_ko": "80๋
๋ ์ด ๋ถํฉ, ์ธํ๋ ์ด์
์ข
์."
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"cycle": "Finance",
|
| 122 |
+
"event_en": "Latin American debt crisis.",
|
| 123 |
+
"event_ko": "์ค๋จ๋ฏธ ์ธ์ฑ ์๊ธฐ."
|
| 124 |
+
}
|
| 125 |
+
]
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"year": 1991,
|
| 129 |
+
"events": [
|
| 130 |
+
{
|
| 131 |
+
"cycle": "Hegemony",
|
| 132 |
+
"event_en": "Dissolution of Soviet Union.",
|
| 133 |
+
"event_ko": "์๋ จ ํด์ฒด."
|
| 134 |
+
}
|
| 135 |
+
]
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"year": 2000,
|
| 139 |
+
"events": [
|
| 140 |
+
{
|
| 141 |
+
"cycle": "K-Wave",
|
| 142 |
+
"event_en": "Dotโcom bubble bursts.",
|
| 143 |
+
"event_ko": "๋ท์ปด ๋ฒ๋ธ ๋ถ๊ดด."
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"cycle": "Business",
|
| 147 |
+
"event_en": "2001 recession.",
|
| 148 |
+
"event_ko": "2001๋
๊ฒฝ๊ธฐ์นจ์ฒด."
|
| 149 |
+
}
|
| 150 |
+
]
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"year": 2008,
|
| 154 |
+
"events": [
|
| 155 |
+
{
|
| 156 |
+
"cycle": "Finance",
|
| 157 |
+
"event_en": "Global Financial Crisis.",
|
| 158 |
+
"event_ko": "์ธ๊ณ ๊ธ์ต ์๊ธฐ."
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"cycle": "Business",
|
| 162 |
+
"event_en": "Great Recession.",
|
| 163 |
+
"event_ko": "๋๋ถํฉ."
|
| 164 |
+
}
|
| 165 |
+
]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"year": 2014,
|
| 169 |
+
"events": [
|
| 170 |
+
{
|
| 171 |
+
"cycle": "Hegemony",
|
| 172 |
+
"event_en": "China tops US in PPP GDP.",
|
| 173 |
+
"event_ko": "์ค๊ตญ PPP GDP 1์."
|
| 174 |
+
}
|
| 175 |
+
]
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"year": 2020,
|
| 179 |
+
"events": [
|
| 180 |
+
{
|
| 181 |
+
"cycle": "Business",
|
| 182 |
+
"event_en": "COVIDโ19 recession.",
|
| 183 |
+
"event_ko": "์ฝ๋ก๋19 ๋ถํฉ."
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
"cycle": "Hegemony",
|
| 187 |
+
"event_en": "Multipolar shift intensifies.",
|
| 188 |
+
"event_ko": "๋ค๊ทน ์ฒด์ ์ ํ ๊ฐ์."
|
| 189 |
+
}
|
| 190 |
+
]
|
| 191 |
+
}
|
| 192 |
+
]
|