benjamin5607 commited on
Commit
2f889a4
ยท
verified ยท
1 Parent(s): 4a0a703

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +127 -207
app.py CHANGED
@@ -24,13 +24,10 @@ st.markdown("""
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
- # 2. ๋ฐ์ดํ„ฐ ๋กœ๋“œ ๋ฐ ๊ฐ•๋ ฅํ•œ ์ •์ œ (Sanitization)
28
  # ==========================================
29
  PLACE_DB = {}
30
 
31
- if not GROQ_API_KEY:
32
- st.error("๐Ÿšจ 'GROQ_API_KEY'๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค! Settings > Secrets ์„ค์ •์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.")
33
-
34
  try:
35
  if SHEET_URL:
36
  response = requests.get(SHEET_URL)
@@ -41,9 +38,9 @@ try:
41
  except:
42
  df = pd.read_csv(io.StringIO(response.text), engine='python', on_bad_lines='skip')
43
 
44
- # [ํ•ต์‹ฌ] ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊นจ๋œจ๋ฆด ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ํŠน์ˆ˜๋ฌธ์ž ์ œ๊ฑฐ
45
- # ๋”ฐ์˜ดํ‘œ, ์ค„๋ฐ”๊ฟˆ, ํƒญ์„ ๊ณต๋ฐฑ์ด๋‚˜ ๋นˆ ๋ฌธ์ž๋กœ ์น˜ํ™˜
46
- df = df.replace({r'\r': ' ', r'\n': ' ', r'"': '', r"'": ''}, regex=True)
47
 
48
  df.columns = df.columns.str.strip()
49
  col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
@@ -51,10 +48,9 @@ try:
51
 
52
  if 'Country' in df.columns:
53
  for country, group in df.groupby('Country'):
54
- cleaned_group = group.fillna("").to_dict(orient='records')
55
- PLACE_DB[country] = cleaned_group
56
  else:
57
- st.error("๐Ÿšจ CSV ํŒŒ์ผ์—์„œ 'Country' ์ปฌ๋Ÿผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
58
  else:
59
  if os.path.exists('places.json'):
60
  with open('places.json', 'r', encoding='utf-8-sig') as f:
@@ -74,11 +70,12 @@ if os.path.exists('emily.jpg'):
74
  emily_base64 = base64.b64encode(f.read()).decode()
75
  except: pass
76
 
 
77
  db_json_raw = json.dumps(PLACE_DB, ensure_ascii=False)
78
  db_base64 = base64.b64encode(db_json_raw.encode('utf-8')).decode('utf-8')
79
 
80
  # ==========================================
81
- # 4. ํ”„๋ก ํŠธ์—”๋“œ (HTML/JS/CSS) - Integer ID System ์ ์šฉ
82
  # ==========================================
83
  html_code = f"""
84
  <!DOCTYPE html>
@@ -87,11 +84,9 @@ html_code = f"""
87
  <meta charset="utf-8">
88
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
89
  <title>Drunken Plane</title>
90
-
91
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
92
  <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
93
  <link href="https://fonts.googleapis.com/css2?family=Special+Elite&display=swap" rel="stylesheet">
94
-
95
  <style>
96
  :root {{ --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }}
97
  body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }}
@@ -159,13 +154,12 @@ html_code = f"""
159
  </style>
160
  </head>
161
  <body>
162
-
163
  <div id="main-page" class="page">
164
  <div class="lang-switcher">
165
- <div class="lang-btn active" onclick="setLanguage('KO', this)">๐Ÿ‡ฐ๐Ÿ‡ท</div>
166
- <div class="lang-btn" onclick="setLanguage('EN', this)">๐Ÿ‡บ๐Ÿ‡ธ</div>
167
- <div class="lang-btn" onclick="setLanguage('JP', this)">๐Ÿ‡ฏ๐Ÿ‡ต</div>
168
- <div class="lang-btn" onclick="setLanguage('CN', this)">๐Ÿ‡จ๐Ÿ‡ณ</div>
169
  </div>
170
  <div style="text-align:center; padding:10px 0;">
171
  <div class="brand-title">DRUNKEN PLANE</div>
@@ -189,7 +183,7 @@ html_code = f"""
189
  <div id="chat-page" class="page">
190
  <div class="nav-bar"><button onclick="closeChat()" style="background:none; border:none; color:var(--gold); font-size:24px;">โ†</button><div id="emily-name" style="color:var(--gold); font-weight:bold;">์—๋ฐ€๋ฆฌ (Emily)</div><div></div></div>
191
  <div id="chat-messages"></div>
192
- <div class="chat-input-area"><input type="text" id="chat-input" class="chat-input" placeholder="์—๋ฐ€๋ฆฌ์—๊ฒŒ ๋งํ•ด๋ด, ์ž๊ธฐ์•ผ..." onkeydown="if(event.key === 'Enter') askBartender()"><button id="chat-send-btn" onclick="askBartender()" style="background:var(--gold); border:none; padding:10px 20px; border-radius:8px; font-weight:bold;">SEND</button></div>
193
  </div>
194
 
195
  <div id="detail-page" class="page">
@@ -203,73 +197,46 @@ html_code = f"""
203
  </div>
204
 
205
  <div id="passport-page" class="page">
206
- <div class="passport-cover">
207
- <button onclick="closePassportPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">โ†</button>
208
- <div style="color:var(--gold); font-weight:bold; font-size: 18px;">DRUNKARD'S PASSPORT</div>
209
- <div></div>
210
- </div>
211
  <div id="passport-grid" class="passport-grid"></div>
212
- <div class="data-controls">
213
- <button class="data-btn" onclick="exportData()">๐Ÿ’พ Save Game</button>
214
- <button class="data-btn" onclick="document.getElementById('import-file').click()">๐Ÿ“‚ Load Game</button>
215
- <input type="file" id="import-file" style="display:none" onchange="importData(this)">
216
- </div>
217
  </div>
218
 
219
- <div id="world-map-page" class="page">
220
- <div class="nav-bar"><button id="nav-home-btn" onclick="closeWorldMapPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">๐Ÿ  HOME</button></div>
221
- <div class="map-search-bar">
222
- <input type="text" id="map-search-input" class="search-input" placeholder="Search (e.g. Gangnam)" onkeydown="if(event.key === 'Enter') searchLocation()">
223
- <button class="search-btn" onclick="searchLocation()">๐Ÿ”</button>
224
- </div>
225
- <button class="map-gps-btn" onclick="flyToUserLocation()">๐ŸŽฏ</button>
226
- <div id="full-map"></div>
227
- </div>
228
-
229
  <div id="loader" class="loading-screen"><div class="loader-ring"></div><div id="loader-msg" style="color:var(--gold); font-family:monospace; margin-top:15px;"></div></div>
230
 
231
  <script>
 
232
  function b64DecodeUnicode(str) {{
233
- return decodeURIComponent(atob(str).split('').map(function(c) {{
234
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
235
- }}).join(''));
 
 
236
  }}
237
 
 
238
  const PLACE_DB = JSON.parse(b64DecodeUnicode("{db_base64}"));
239
  let userLat = null, userLon = null, selectedCountry = "", selectedType = "All", currentLang = "KO", chatInitialized = false;
240
- let miniMap = null, worldMap = null, worldMarkers = L.layerGroup();
241
- let chatHistory = [];
242
- let currentDetailPlace = null;
243
- let currentFilteredList = [];
244
-
245
- // [ํ•ต์‹ฌ ๋ณ€๊ฒฝ: ์ง€๋„ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ (Key๋ฅผ ์ˆซ์ž๋กœ ๊ด€๋ฆฌ)]
246
- let MAP_CACHE = {{}};
247
- let mapKeyCounter = 0; // ์œ ๋‹ˆํฌํ•œ ์ˆซ์ž ID ์ƒ์„ฑ์šฉ
248
 
249
  const TRANSLATIONS = {{
250
- "KO": {{ "sub": "๊ธ€๋กœ๋ฒŒ ์ฃผ๋ฅ˜ ํ—ค๋ฆฌํ‹ฐ์ง€ ํˆฌ์–ด", "ai": "Korean", "mapBtn": "๐Ÿ—บ๏ธ ์›”๋“œ๋งต ํƒํ—˜", "passBtn": "๐Ÿ“˜ ๋‚ด ์—ฌ๊ถŒ", "filters": ["๐ŸŒ ์ „์ฒด", "๐Ÿบ ์ „ํ†ต์ฃผ", "๐Ÿฅƒ ์œ„์Šคํ‚ค", "๐Ÿบ ๋งฅ์ฃผ", "๐Ÿท ์™€์ธ", "๐Ÿน ๋ฐ”"], "chatPlace": "์—๋ฐ€๋ฆฌ์—๊ฒŒ ๋งํ•ด๋ด, ์ž๊ธฐ์•ผ...", "send": "์ „์†ก", "home": "๐Ÿ  ํ™ˆ", "searchPlace": "์žฅ์†Œ ๊ฒ€์ƒ‰ (์˜ˆ: ๊ฐ•๋‚จ)", "emilyName": "์—๋ฐ€๋ฆฌ (Emily)", "reportHeader": "๋ฆฌํฌํŠธ", "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapLinkBtn": "์ง€๋„" }},
251
- "EN": {{ "sub": "GLOBAL ALCOHOL HERITAGE TOUR", "ai": "English", "mapBtn": "๐Ÿ—บ๏ธ WORLD MAP EXPLORER", "passBtn": "๐Ÿ“˜ MY PASSPORT", "filters": ["๐ŸŒ All", "๐Ÿบ Trad.", "๐Ÿฅƒ Whiskey", "๐Ÿบ Beer", "๐Ÿท Wine", "๐Ÿน Bar"], "chatPlace": "Talk to Emily...", "send": "SEND", "home": "๐Ÿ  HOME", "searchPlace": "Search (e.g. Gangnam)", "emilyName": "Emily", "reportHeader": "REPORT", "aiBtn": "AI REVIEW", "mapLinkBtn": "MAP" }},
252
- "JP": {{ "sub": "ไธ–็•ŒใฎใŠ้…’ใƒ˜ใƒชใƒ†ใƒผใ‚ธใƒ„ใ‚ขใƒผ", "ai": "Japanese", "mapBtn": "๐Ÿ—บ๏ธ ไธ–็•Œๅœฐๅ›ณๆŽข็ดข", "passBtn": "๐Ÿ“˜ ใƒžใ‚คใƒ‘ใ‚นใƒใƒผใƒˆ", "filters": ["๐ŸŒ ๅ…จใฆ", "๐Ÿบ ไผ็ตฑ้…’", "๐Ÿฅƒ ใ‚ฆใ‚คใ‚นใ‚ญใƒผ", "๐Ÿบ ใƒ“ใƒผใƒซ", "๐Ÿท ใƒฏใ‚คใƒณ", "๐Ÿน ใƒใƒผ"], "chatPlace": "ใ‚จใƒŸใƒชใƒผใซ่ฉฑใ—ใ‹ใ‘ใฆ...", "send": "้€ไฟก", "home": "๐Ÿ  ใƒ›ใƒผใƒ ", "searchPlace": "ๅ ดๆ‰€ๆคœ็ดข (ไพ‹: ๆ–ฐๅฎฟ)", "emilyName": "ใ‚จใƒŸใƒชใƒผ (Emily)", "reportHeader": "ใƒฌใƒใƒผใƒˆ", "aiBtn": "AI ใƒฌใƒ“ใƒฅใƒผ", "mapLinkBtn": "ๅœฐๅ›ณ" }},
253
- "CN": {{ "sub": "ๅ…จ็ƒ้…’็ฑป้—ไบงไน‹ๆ—…", "ai": "Chinese", "mapBtn": "๐Ÿ—บ๏ธ ไธ–็•Œๅœฐๅ›พๆŽข็ดข", "passBtn": "๐Ÿ“˜ ๆˆ‘็š„ๆŠค็…ง", "filters": ["๐ŸŒ ๅ…จ้ƒจ", "๐Ÿบ ไผ ็ปŸ้…’", "๐Ÿฅƒ ๅจๅฃซๅฟŒ", "๐Ÿบ ๅ•ค้…’", "๐Ÿท ่‘ก่„้…’", "๐Ÿน ้…’ๅง"], "chatPlace": "่ทŸ่‰พ็ฑณไธฝ่Šๅคฉ...", "send": "ๅ‘้€", "home": "๐Ÿ  ไธป้กต", "searchPlace": "ๆœ็ดขๅœฐ็‚น (ไพ‹ๅฆ‚: ๆฑŸๅ—)", "emilyName": "่‰พ็ฑณไธฝ (Emily)", "reportHeader": "ๆŠฅๅ‘Š", "aiBtn": "AI ็‚น่ฏ„", "mapLinkBtn": "ๅœฐๅ›พ" }}
254
  }};
255
 
256
- const GREETINGS = {{ "KO": "์•ˆ๋…•, ์ž๊ธฐ? ์˜ค๋Š˜ ์ •๋ง ๊ณ ์ƒ ๋งŽ์•˜์–ด. ์—๋ฐ€๋ฆฌํ•œํ…Œ ๋ญ๋“  ๋ฌผ์–ด๋ด~", "EN": "Hey darling, rough day? Let Emily pour you a drink.", "JP": "ใ‚ใ‚‰ใ€ใƒใƒ‹ใƒผใ€‚ไปŠๆ—ฅใฏใŠ็–ฒใ‚Œๆง˜ใ€‚ใ‚จใƒŸใƒชใƒผใซใชใ‚“ใงใ‚‚่žใ„ใฆ๏ผŸ", "CN": "ไบฒ็ˆฑ็š„๏ผŒไปŠๅคฉ่พ›่‹ฆไบ†ใ€‚ๆœ‰ไป€ไนˆๆƒณๅ–็š„ๅ—๏ผŸ" }};
257
- const LOAD_MSGS = {{ "KO": ["์Œ~ ์ž๊ธฐ๋ฅผ ์œ„ํ•œ ์„ฑ์ง€๊ฐ€ ์–ด๋”” ์žˆ๋”๋ผ?", "๊ธˆ๋ฐœ ๋จธ๋ฆฌ ์ข€ ์ •๋ฆฌํ•˜๊ณ  ์•Œ๋ ค์ค„๊ฒŒ!"], "EN": ["Searching for your perfect spot...", "Fixing my hair, one sec!"], "JP": ["้›†ไธญใ—ใฆใ‚‹ใ‚...", "้ซชใ‚’ๆ•ดใˆใฆใ™ใใซๆ•™ใˆใ‚‹ใ‚ใญ"], "CN": ["ๆญฃๅœจๅ€พๅฌ...", "ๆญฃๅœจๆ•ด็†้‡‘ๅ‘..."] }};
258
- const CAT_MAP = {{ "Traditional": 1, "Whiskey": 2, "Beer": 3, "Wine": 4, "Bar": 5 }};
259
- const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
260
-
261
  window.onload = function() {{
262
- initCountryDropdown();
263
  const keys = Object.keys(PLACE_DB).sort();
 
 
264
  if(keys.length > 0) selectCountry(keys[0]);
265
- navigator.geolocation.getCurrentPosition(p => {{ userLat = p.coords.latitude; userLon = p.coords.longitude; }}, err => console.log("GPS Not Available"));
266
  }};
267
 
268
- function initCountryDropdown() {{
269
- const select = document.getElementById('country-select');
270
- Object.keys(PLACE_DB).sort().forEach(c => {{ const opt = document.createElement('option'); opt.value = c; opt.text = c; select.appendChild(opt); }});
271
- }}
272
-
273
  function setLanguage(lang, el) {{
274
  currentLang = lang;
275
  document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
@@ -291,202 +258,155 @@ html_code = f"""
291
  function selectCountry(c) {{ selectedCountry = c; renderList(); }}
292
  function filterType(t, el) {{ selectedType = t; document.querySelectorAll('.type-btn').forEach(b => b.classList.remove('selected')); el.classList.add('selected'); renderList(); }}
293
 
294
- function getMapUrl(name, country, lat, lon, address) {{
295
- if (country && (country.includes("Korea") || country.includes("ํ•œ๊ตญ") || country === "๋Œ€ํ•œ๋ฏผ๊ตญ")) {{ return "https://map.naver.com/p/search/" + encodeURIComponent(address ? address : name); }}
296
- else {{ return "https://www.google.com/maps/search/" + encodeURIComponent(name) + "/@" + lat + "," + lon + ",18z"; }}
297
- }}
298
-
299
- function openMapLink(url) {{ window.open(url, '_blank'); }}
300
-
301
  function renderList() {{
302
  const list = document.getElementById('place-list'); list.innerHTML = "";
303
  const stamps = getStamps();
304
  const visitedSet = new Set(stamps.map(s => s ? s.name + '|' + s.country : ''));
305
  const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
306
- currentFilteredList = filtered; // ๋ฆฌ์ŠคํŠธ ์ธ๋ฑ์Šค์šฉ
307
  const t = TRANSLATIONS[currentLang];
308
 
309
  filtered.forEach((p, idx) => {{
310
  const card = document.createElement('div');
311
  const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
312
  card.className = isVisited ? 'place-card visited' : 'place-card';
313
- let desc = (currentLang === 'KO' ? p.desc_ko : (currentLang === 'EN' ? p.desc_en : (currentLang === 'JP' ? p.desc_jp : p.desc_cn))) || p.desc_en || "No description.";
314
 
315
- // HTML ํ‘œ์‹œ์šฉ (๋”ฐ์˜ดํ‘œ ์ œ๊ฑฐ)
316
- const safeName = String(p.name).replace(/['"]/g, "");
317
- const safeDesc = String(desc).replace(/['"]/g, "");
318
- const safeMapLink = getMapUrl(p.name, selectedCountry, p.lat, p.lon, p.address || "").replace(/['"]/g, "");
319
-
320
- let catIdx = CAT_MAP[p.category] || 0;
321
- let translatedCat = t.filters[catIdx] || p.category;
322
-
323
- // [์ค‘์š”] onclick์—๋Š” ์˜ค์ง ์ˆซ์ž(idx)๋งŒ ๋“ค์–ด๊ฐ
324
- card.innerHTML = "<div class='visited-badge'>VISITED ๐Ÿ’ฎ</div><b>" + safeName + "</b><div class='pc-cat'>" + translatedCat + "</div><div class='pc-desc'>" + safeDesc + "</div>" +
325
- "<div class='card-actions'><button class='btn-action btn-ai' onclick='openDetailByIndex(" + idx + ")'>" + t.aiBtn + "</button>" +
326
- "<button class='btn-action btn-map' onclick='openMapLink(\"" + safeMapLink + "\")'>" + t.mapLinkBtn + "</button></div>";
327
  list.appendChild(card);
328
  }});
329
  }}
330
 
331
- function getStamps() {{
332
- try {{ return JSON.parse(localStorage.getItem('drunk_passport') || '[]'); }}
333
- catch(e) {{ localStorage.setItem('drunk_passport', '[]'); return []; }}
 
 
 
 
 
 
 
 
334
  }}
335
 
 
 
 
 
 
 
 
 
 
336
  function stampCurrentPlace() {{
337
- if(!currentDetailPlace) {{ alert("No place selected."); return; }}
338
  const stamps = getStamps();
339
- const exists = stamps.find(s => s.name === currentDetailPlace.name && s.country === currentDetailPlace.country);
340
- if(exists) {{ alert("Already Stamped! ๐Ÿ’ฎ"); return; }}
341
  stamps.push({{ name: currentDetailPlace.name, country: currentDetailPlace.country, date: new Date().toLocaleDateString() }});
342
  localStorage.setItem('drunk_passport', JSON.stringify(stamps));
343
- renderList();
344
- alert("Stamped! ๐Ÿ’ฎ");
345
  }}
346
 
347
  function openPassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(0%)'; renderPassport(); }}
348
  function renderPassport() {{
349
  const grid = document.getElementById('passport-grid'); grid.innerHTML = "";
350
- const stamps = getStamps();
351
- stamps.forEach(s => {{
352
- if(!s || !s.name) return;
353
  const el = document.createElement('div'); el.className = 'stamp-card';
354
- const rot = Math.floor(Math.random() * 30) - 15;
355
- el.innerHTML = "<div class='stamp-mark' style='transform: rotate(" + rot + "deg)'><div class='stamp-country'>" + s.country + "</div><div class='stamp-name'>" + s.name + "</div><div class='stamp-date'>" + s.date + "</div></div>";
 
 
 
356
  grid.appendChild(el);
357
  }});
358
- if(stamps.length === 0) grid.innerHTML = "<div style='color:#666; text-align:center; width:100%; margin-top:50px; grid-column: 1/-1;'>No Stamps Yet.</div>";
359
- }}
360
-
361
- function exportData() {{
362
- const data = localStorage.getItem('drunk_passport');
363
- const blob = new Blob([data], {{type: 'application/json'}});
364
- const url = URL.createObjectURL(blob);
365
- const a = document.createElement('a'); a.href = url; a.download = 'drunk_passport_save.json'; a.click();
366
- }}
367
-
368
- function importData(input) {{
369
- const file = input.files[0]; if(!file) return;
370
- const reader = new FileReader();
371
- reader.onload = function(e) {{
372
- try {{
373
- const data = JSON.parse(e.target.result);
374
- if(Array.isArray(data)) {{ localStorage.setItem('drunk_passport', JSON.stringify(data)); renderPassport(); renderList(); alert("Data Loaded!"); }}
375
- else {{ alert("Invalid File"); }}
376
- }} catch(err) {{ alert("File Error"); }}
377
- }};
378
- reader.readAsText(file);
379
- }}
380
-
381
- async function callGroq(messages) {{
382
- const apiKey = "{GROQ_API_KEY}"; if(!apiKey || apiKey.length < 10) return "Error: API Key Missing";
383
- const url = "https://api.groq.com/openai/v1/chat/completions";
384
- const models = ["llama-3.3-70b-versatile", "llama-3.1-70b-versatile", "mixtral-8x7b-32768"];
385
- for (const model of models) {{
386
- try {{
387
- const response = await fetch(url, {{ method: 'POST', headers: {{ 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + apiKey }}, body: JSON.stringify({{ model: model, messages: messages, temperature: 0.7, max_tokens: 2048 }}) }});
388
- if (!response.ok) throw new Error(response.statusText);
389
- const data = await response.json(); return data.choices[0].message.content;
390
- }} catch (error) {{ console.log(error); }}
391
- }}
392
- return "Connection Failed.";
393
  }}
394
 
395
- function openChat() {{ document.getElementById('chat-page').style.transform = 'translateY(0%)'; if(!chatInitialized) {{ addChatMessage(GREETINGS[currentLang], 'bot'); chatInitialized = true; }} }}
396
- async function askBartender() {{
397
- const input = document.getElementById('chat-input'); const msg = input.value.trim(); if(!msg) return;
398
- addChatMessage(msg, 'user'); input.value = ""; chatHistory.push({{ role: "user", content: msg }});
399
- const loadingMsg = addChatMessage(getRandom(LOAD_MSGS[currentLang]), 'bot');
400
-
401
- let nearbyPlaces = [];
402
- if(userLat && userLon) {{ Object.keys(PLACE_DB).forEach(c => {{ PLACE_DB[c].forEach(p => {{ if(p.lat && p.lon) nearbyPlaces.push({{ ...p, country: c }}); }}); }}); }}
403
- if(nearbyPlaces.length === 0) nearbyPlaces = (PLACE_DB[selectedCountry] || []).map(p => ({{...p, country: selectedCountry}}));
404
- const pool = nearbyPlaces.slice(0, 10).map(p => p.name).join(', ');
405
-
406
- const res = await callGroq([...chatHistory, {{ role: "system", content: "You are Emily. Recommend from: [" + pool + "]. Lang: " + TRANSLATIONS[currentLang].ai }}]);
407
- if(loadingMsg) loadingMsg.remove();
408
-
409
- let finalMsg = res;
410
- const match = res.match(/\[(.*?)\]/);
411
- if(match) {{
412
- const pName = match[1]; const found = nearbyPlaces.find(p => p.name.includes(pName));
413
- if(found) {{
414
- const mapUrl = getMapUrl(pName, found.country, found.lat, found.lon, "");
415
- finalMsg += "<br><a href='" + mapUrl + "' target='_blank' class='reco-btn'>๐Ÿ“ MAP</a>";
416
- }}
417
- }}
418
- addChatMessage(finalMsg, 'bot', true); chatHistory.push({{ role: "assistant", content: res }});
419
- }}
420
 
421
- function addChatMessage(t, s, html=false) {{ const box = document.getElementById('chat-messages'); const div = document.createElement('div'); div.className = "msg " + s; if(html) div.innerHTML = t.replace(/\\n/g, '<br>'); else div.innerText = t; box.appendChild(div); box.scrollTop = box.scrollHeight; return div; }}
422
-
423
- // [ํ•ต์‹ฌ ๋ณ€๊ฒฝ 4] ์›”๋“œ๋งต ํŒ์—… - ์ˆซ์ž ID ์‚ฌ์šฉ (๋”ฐ์˜ดํ‘œ ์ง€์˜ฅ ํƒˆ์ถœ)
424
  function openWorldMapPage() {{
425
  document.getElementById('world-map-page').style.transform = 'translateY(0%)';
426
  if(!worldMap) {{
427
- worldMap = L.map('full-map').setView([20, 0], 2); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
428
- MAP_CACHE = {{}};
429
- mapKeyCounter = 0; // ์ดˆ๊ธฐํ™”
430
-
431
  Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
432
  if(p.lat && p.lon) {{
433
- // ๋ฐ์ดํ„ฐ๋ฅผ ์บ์‹œ์— ์ €์žฅํ•˜๊ณ  ์ˆซ์ž(ID)๋ฅผ ๋ฐœ๊ธ‰
434
- const currentId = mapKeyCounter++;
435
- MAP_CACHE[currentId] = {{ name: p.name, country: c, url: getMapUrl(p.name, c, p.lat, p.lon, "") }};
436
-
437
- const safeName = String(p.name).replace(/['"]/g, "");
438
 
439
- // onclick์—๋Š” ์˜ค์ง ์ˆซ์ž(currentId)๋งŒ ์ „๋‹ฌ -> ์ ˆ๋Œ€ ์—๋Ÿฌ ์•ˆ๋‚จ
440
- const popupContent = "<div style='text-align:center'><b>" + safeName + "</b><br>" +
441
- "<div style='display:flex; gap:5px; margin-top:5px; justify-content:center;'>" +
442
- "<button onclick='clickMapDetail(" + currentId + ")' style='background:#d4af37; border:none; border-radius:4px; padding:4px 8px; font-size:11px; cursor:pointer;'>๐Ÿค– REVIEW</button>" +
443
- "<button onclick='clickMapLink(" + currentId + ")' style='background:#333; color:white; border:1px solid #555; border-radius:4px; padding:4px 8px; font-size:11px; cursor:pointer;'>๐Ÿ—บ๏ธ MAP</button>" +
444
- "</div></div>";
445
- L.marker([p.lat, p.lon]).bindPopup(popupContent).addTo(worldMap);
446
  }}
447
  }}));
448
  }}
449
  setTimeout(() => worldMap.invalidateSize(), 400);
450
  }}
451
-
452
- // ๋งต ํด๋ฆญ ํ•ธ๋“ค๋Ÿฌ (์ˆซ์ž๋กœ ๋ฐ์ดํ„ฐ ์ฐพ๊ธฐ)
453
- function clickMapDetail(id) {{
454
- const data = MAP_CACHE[id];
455
- if(data) {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
456
- }}
457
-
458
- function clickMapLink(id) {{
459
- const data = MAP_CACHE[id];
460
- if(data) window.open(data.url, '_blank');
461
- }}
462
 
463
- async function searchLocation() {{
464
- const query = document.getElementById('map-search-input').value; if(!query) return;
465
- try {{ const res = await fetch('https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(query)); const data = await res.json();
466
- if(data.length > 0) {{ worldMap.flyTo([data[0].lat, data[0].lon], 12); L.popup().setLatLng([data[0].lat, data[0].lon]).setContent("๐Ÿ”Ž " + query).openOn(worldMap); }} else alert("Not Found");
467
- }} catch(e) {{}}
 
 
 
 
 
468
  }}
469
 
470
- function flyToUserLocation() {{ if(userLat && userLon) {{ worldMap.flyTo([userLat, userLon], 13); L.marker([userLat, userLon]).addTo(worldMap).bindPopup("๐Ÿ“ You").openPopup(); }} else alert("GPS..."); }}
471
- function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
 
 
 
 
 
 
472
 
473
- function openDetailFromMap(n, c) {{ closeWorldMapPage(); openDetail(n, c); }}
474
- function openDetailByIndex(idx) {{ const p = currentFilteredList[idx]; if(p) openDetail(p.name, selectedCountry); }}
475
  async function openDetail(n, c) {{
476
- const p = (PLACE_DB[c] || []).find(x => x.name === n); if(!p) return;
477
  currentDetailPlace = {{ name: n, country: c }};
478
- document.getElementById('detail-page').style.transform = 'translateX(0%)'; document.getElementById('repo-title').innerText = n;
479
- document.getElementById('loader-msg').innerText = TRANSLATIONS[currentLang].aiBtn + "..."; document.getElementById('loader').style.display='flex';
 
480
  if(!miniMap) {{ miniMap = L.map('mini-map'); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(miniMap); }}
481
- setTimeout(() => {{ miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap).bindPopup(p.name).openPopup(); }}, 400);
482
- const res = await callGroq([{{ role: "system", content: "Act as Emily. Write DETAILED report." }}, {{ role: "user", content: "Report for '" + n + "' in '" + c + "'. In " + TRANSLATIONS[currentLang].ai + "." }}]);
483
- document.getElementById('loader').style.display='none'; document.getElementById('repo-content').innerHTML = res.replace(/\\n/g, '<br>').replace(/###/g, 'โญ');
 
484
  }}
485
 
486
- function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
487
- function closeDetail() {{ document.getElementById('detail-page').style.transform = 'translateX(100%)'; }}
488
  function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
489
  function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
 
 
 
 
 
 
 
490
  </script>
491
  </body>
492
  </html>
 
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
+ # 2. ๋ฐ์ดํ„ฐ ๋กœ๋“œ ๋ฐ "๊ฐ•๋ ฅํ•œ" ์ •์ œ (Anti-SyntaxError)
28
  # ==========================================
29
  PLACE_DB = {}
30
 
 
 
 
31
  try:
32
  if SHEET_URL:
33
  response = requests.get(SHEET_URL)
 
38
  except:
39
  df = pd.read_csv(io.StringIO(response.text), engine='python', on_bad_lines='skip')
40
 
41
+ # [ํ•ต์‹ฌ ์ˆ˜์ •] ๋ชจ๋“  ๋ฌธ์ž์—ด ์ปฌ๋Ÿผ์—์„œ JS ์—๋Ÿฌ๋ฅผ ์œ ๋ฐœํ•˜๋Š” ๋ฌธ์ž๋“ค(์—”ํ„ฐ, ํƒญ, ๋”ฐ์˜ดํ‘œ) ์ œ๊ฑฐ
42
+ for col in df.select_dtypes(include=['object']).columns:
43
+ df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '').str.replace("'", "")
44
 
45
  df.columns = df.columns.str.strip()
46
  col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
 
48
 
49
  if 'Country' in df.columns:
50
  for country, group in df.groupby('Country'):
51
+ PLACE_DB[country] = group.fillna("").to_dict(orient='records')
 
52
  else:
53
+ st.error("๐Ÿšจ CSV์— 'Country' ์ปฌ๋Ÿผ์ด ์—†์Šต๋‹ˆ๋‹ค.")
54
  else:
55
  if os.path.exists('places.json'):
56
  with open('places.json', 'r', encoding='utf-8-sig') as f:
 
70
  emily_base64 = base64.b64encode(f.read()).decode()
71
  except: pass
72
 
73
+ # Base64๋กœ ์ธ์ฝ”๋”ฉํ•˜์—ฌ JS ์ „๋‹ฌ (๋”ฐ์˜ดํ‘œ ์ถฉ๋Œ ์›์ฒœ ๋ฐฉ์ง€)
74
  db_json_raw = json.dumps(PLACE_DB, ensure_ascii=False)
75
  db_base64 = base64.b64encode(db_json_raw.encode('utf-8')).decode('utf-8')
76
 
77
  # ==========================================
78
+ # 4. ํ”„๋ก ํŠธ์—”๋“œ (HTML/JS/CSS) - 100% ๊ฒ€์ฆ ๋ฒ„์ „
79
  # ==========================================
80
  html_code = f"""
81
  <!DOCTYPE html>
 
84
  <meta charset="utf-8">
85
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
86
  <title>Drunken Plane</title>
 
87
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
88
  <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
89
  <link href="https://fonts.googleapis.com/css2?family=Special+Elite&display=swap" rel="stylesheet">
 
90
  <style>
91
  :root {{ --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }}
92
  body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }}
 
154
  </style>
155
  </head>
156
  <body>
 
157
  <div id="main-page" class="page">
158
  <div class="lang-switcher">
159
+ <div class="lang-btn active" id="l-KO" onclick="setLanguage('KO', this)">๐Ÿ‡ฐ๐Ÿ‡ท</div>
160
+ <div class="lang-btn" id="l-EN" onclick="setLanguage('EN', this)">๐Ÿ‡บ๐Ÿ‡ธ</div>
161
+ <div class="lang-btn" id="l-JP" onclick="setLanguage('JP', this)">๐Ÿ‡ฏ๐Ÿ‡ต</div>
162
+ <div class="lang-btn" id="l-CN" onclick="setLanguage('CN', this)">๐Ÿ‡จ๐Ÿ‡ณ</div>
163
  </div>
164
  <div style="text-align:center; padding:10px 0;">
165
  <div class="brand-title">DRUNKEN PLANE</div>
 
183
  <div id="chat-page" class="page">
184
  <div class="nav-bar"><button onclick="closeChat()" style="background:none; border:none; color:var(--gold); font-size:24px;">โ†</button><div id="emily-name" style="color:var(--gold); font-weight:bold;">์—๋ฐ€๋ฆฌ (Emily)</div><div></div></div>
185
  <div id="chat-messages"></div>
186
+ <div class="chat-input-area"><input type="text" id="chat-input" class="chat-input" placeholder="..." onkeydown="if(event.key === 'Enter') askBartender()"><button id="chat-send-btn" onclick="askBartender()" style="background:var(--gold); border:none; padding:10px 20px; border-radius:8px; font-weight:bold;">SEND</button></div>
187
  </div>
188
 
189
  <div id="detail-page" class="page">
 
197
  </div>
198
 
199
  <div id="passport-page" class="page">
200
+ <div class="passport-cover"><button onclick="closePassportPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">โ†</button><div style="color:var(--gold); font-weight:bold; font-size: 18px;">DRUNKARD'S PASSPORT</div><div></div></div>
 
 
 
 
201
  <div id="passport-grid" class="passport-grid"></div>
202
+ <div class="data-controls"><button class="data-btn" onclick="exportData()">๐Ÿ’พ Save Game</button><button class="data-btn" onclick="document.getElementById('import-file').click()">๐Ÿ“‚ Load Game</button><input type="file" id="import-file" style="display:none" onchange="importData(this)"></div>
 
 
 
 
203
  </div>
204
 
205
+ <div id="world-map-page" class="page"><div class="nav-bar"><button id="nav-home-btn" onclick="closeWorldMapPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">๐Ÿ  HOME</button></div><div class="map-search-bar"><input type="text" id="map-search-input" class="search-input" placeholder="..." onkeydown="if(event.key === 'Enter') searchLocation()"><button class="search-btn" onclick="searchLocation()">๐Ÿ”</button></div><button class="map-gps-btn" onclick="flyToUserLocation()">๐ŸŽฏ</button><div id="full-map"></div></div>
 
 
 
 
 
 
 
 
 
206
  <div id="loader" class="loading-screen"><div class="loader-ring"></div><div id="loader-msg" style="color:var(--gold); font-family:monospace; margin-top:15px;"></div></div>
207
 
208
  <script>
209
+ // ์•ˆ์ „ํ•œ ๋ฐ์ดํ„ฐ ๋””์ฝ”๋”ฉ
210
  function b64DecodeUnicode(str) {{
211
+ try {{
212
+ return decodeURIComponent(atob(str).split('').map(function(c) {{
213
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
214
+ }}).join(''));
215
+ }} catch(e) {{ return "{{}}"; }}
216
  }}
217
 
218
+ // ์ „์—ญ ๋ฐ์ดํ„ฐ (์—ด์‡  ์—ญํ• ์„ ํ•˜๋Š” ์ˆซ์ž ID ํ™œ์šฉ)
219
  const PLACE_DB = JSON.parse(b64DecodeUnicode("{db_base64}"));
220
  let userLat = null, userLon = null, selectedCountry = "", selectedType = "All", currentLang = "KO", chatInitialized = false;
221
+ let miniMap = null, worldMap = null, currentFilteredList = [];
222
+ let MAP_CACHE = {{}}; // ์ง€๋„์—์„œ ํด๋ฆญ ์‹œ ๋ฐ์ดํ„ฐ ์กฐํšŒ๋ฅผ ์œ„ํ•œ ์บ์‹œ
223
+ let mapIdCounter = 0;
 
 
 
 
 
224
 
225
  const TRANSLATIONS = {{
226
+ "KO": {{ "sub": "๊ธ€๋กœ๋ฒŒ ์ฃผ๋ฅ˜ ํ—ค๋ฆฌํ‹ฐ์ง€ ํˆฌ์–ด", "ai": "Korean", "mapBtn": "๐Ÿ—บ๏ธ ์›”๋“œ๋งต ํƒํ—˜", "passBtn": "๐Ÿ“˜ ๋‚ด ์—ฌ๊ถŒ", "filters": ["๐ŸŒ ์ „์ฒด", "๐Ÿบ ์ „ํ†ต์ฃผ", "๐Ÿฅƒ ์œ„์Šคํ‚ค", "๐Ÿบ ๋งฅ์ฃผ", "๐Ÿท ์™€์ธ", "๐Ÿน ๋ฐ”"], "chatPlace": "์—๋ฐ€๋ฆฌ์—๊ฒŒ ๋งํ•ด๋ด...", "send": "์ „์†ก", "home": "๐Ÿ  ํ™ˆ", "searchPlace": "์žฅ์†Œ ๊ฒ€์ƒ‰", "emilyName": "์—๋ฐ€๋ฆฌ", "reportHeader": "๋ฆฌํฌํŠธ", "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapLinkBtn": "์ง€๋„" }},
227
+ "EN": {{ "sub": "GLOBAL ALCOHOL HERITAGE TOUR", "ai": "English", "mapBtn": "๐Ÿ—บ๏ธ EXPLORER", "passBtn": "๐Ÿ“˜ PASSPORT", "filters": ["๐ŸŒ All", "๐Ÿบ Trad.", "๐Ÿฅƒ Whiskey", "๐Ÿบ Beer", "๐Ÿท Wine", "๐Ÿน Bar"], "chatPlace": "Talk to Emily...", "send": "SEND", "home": "๐Ÿ  HOME", "searchPlace": "Search", "emilyName": "Emily", "reportHeader": "REPORT", "aiBtn": "AI REVIEW", "mapLinkBtn": "MAP" }},
228
+ "JP": {{ "sub": "ไธ–็•ŒใฎใŠ้…’ใƒ˜ใƒชใƒ†ใƒผใ‚ธใƒ„ใ‚ขใƒผ", "ai": "Japanese", "mapBtn": "๐Ÿ—บ๏ธ ๅœฐๅ›ณๆŽข็ดข", "passBtn": "๐Ÿ“˜ ใƒ‘์ŠคํฌํŠธ", "filters": ["๐ŸŒ ๅ…จใฆ", "๐Ÿบ ไผ็ตฑ้…’", "๐Ÿฅƒ ใ‚ฆใ‚คใ‚นใ‚ญใƒผ", "๐Ÿบ ใƒ“ใƒผใƒซ", "๐Ÿท ใƒฏใ‚คใƒณ", "๐Ÿน ใƒใƒผ"], "chatPlace": "ใ‚จใƒŸใƒชใƒผใซ่ฉฑใ—ใฆ...", "send": "้€ไฟก", "home": "๐Ÿ  ใƒ›ใƒผใƒ ", "searchPlace": "ๅ ดๆ‰€ๆคœ็ดข", "emilyName": "ใ‚จใƒŸใƒชใƒผ", "reportHeader": "ใƒฌใƒใƒผใƒˆ", "aiBtn": "AI ใƒฌใƒ“ใƒฅใƒผ", "mapLinkBtn": "ๅœฐๅ›ณ" }},
229
+ "CN": {{ "sub": "ๅ…จ็ƒ้…’็ฑป้—ไบงไน‹ๆ—…", "ai": "Chinese", "mapBtn": "๐Ÿ—บ๏ธ ๆŽข็ดขๅœฐๅ›พ", "passBtn": "๐Ÿ“˜ ๆˆ‘็š„ๆŠค็…ง", "filters": ["๐ŸŒ ๅ…จ้ƒจ", "๐Ÿบ ไผ ็ปŸ้…’", "๐Ÿฅƒ ๅจๅฃซๅฟŒ", "๐Ÿบ ๅ•ค้…’", "๐Ÿท ่‘ก่„้…’", "๐Ÿน ้…’ๅง"], "chatPlace": "ๅ’Œ่‰พ็ฑณไธฝ่Š่Š...", "send": "ๅ‘้€", "home": "๐Ÿ  ไธป้กต", "searchPlace": "ๆœ็ดข", "emilyName": "่‰พ็ฑณไธฝ", "reportHeader": "ๆŠฅๅ‘Š", "aiBtn": "AI ็‚น่ฏ„", "mapLinkBtn": "ๅœฐๅ›พ" }}
230
  }};
231
 
 
 
 
 
 
232
  window.onload = function() {{
 
233
  const keys = Object.keys(PLACE_DB).sort();
234
+ const select = document.getElementById('country-select');
235
+ keys.forEach(k => {{ const opt = document.createElement('option'); opt.value = k; opt.text = k; select.appendChild(opt); }});
236
  if(keys.length > 0) selectCountry(keys[0]);
237
+ navigator.geolocation.getCurrentPosition(p => {{ userLat = p.coords.latitude; userLon = p.coords.longitude; }}, e => console.log("GPS Off"));
238
  }};
239
 
 
 
 
 
 
240
  function setLanguage(lang, el) {{
241
  currentLang = lang;
242
  document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
 
258
  function selectCountry(c) {{ selectedCountry = c; renderList(); }}
259
  function filterType(t, el) {{ selectedType = t; document.querySelectorAll('.type-btn').forEach(b => b.classList.remove('selected')); el.classList.add('selected'); renderList(); }}
260
 
261
+ // ๋ฆฌ์ŠคํŠธ ๋ Œ๋”๋ง (์ˆซ์ž ID ๊ธฐ๋ฐ˜ ํด๋ฆญ ์ด๋ฒคํŠธ)
 
 
 
 
 
 
262
  function renderList() {{
263
  const list = document.getElementById('place-list'); list.innerHTML = "";
264
  const stamps = getStamps();
265
  const visitedSet = new Set(stamps.map(s => s ? s.name + '|' + s.country : ''));
266
  const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
267
+ currentFilteredList = filtered;
268
  const t = TRANSLATIONS[currentLang];
269
 
270
  filtered.forEach((p, idx) => {{
271
  const card = document.createElement('div');
272
  const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
273
  card.className = isVisited ? 'place-card visited' : 'place-card';
274
+ let desc = (currentLang === 'KO' ? p.desc_ko : (currentLang === 'EN' ? p.desc_en : (currentLang === 'JP' ? p.desc_jp : p.desc_cn))) || p.desc_en || "...";
275
 
276
+ // [์•ˆ์ „] ํ…์ŠคํŠธ์— ์ง์ ‘ ์ ‘๊ทผํ•˜์ง€ ์•Š๊ณ  ์ˆซ์ž(idx)๋งŒ ๋„˜๊น€
277
+ card.innerHTML = `<div class='visited-badge'>VISITED ๐Ÿ’ฎ</div>
278
+ <b>${{p.name}}</b>
279
+ <div class='pc-cat'>${{p.category}}</div>
280
+ <div class='pc-desc'>${{desc}}</div>
281
+ <div class='card-actions'>
282
+ <button class='btn-action btn-ai' onclick='clickAction(${{idx}}, "ai")'>${{t.aiBtn}}</button>
283
+ <button class='btn-action btn-map' onclick='clickAction(${{idx}}, "map")'>${{t.mapLinkBtn}}</button>
284
+ </div>`;
 
 
 
285
  list.appendChild(card);
286
  }});
287
  }}
288
 
289
+ // ์ˆซ์ž ID๋กœ ๋ฐ์ดํ„ฐ ์ฐพ๊ธฐ (์—๋Ÿฌ ๋ฐฉ์ง€ 1์ˆœ์œ„)
290
+ function clickAction(idx, type) {{
291
+ const p = currentFilteredList[idx];
292
+ if(!p) return;
293
+ if(type === 'ai') openDetail(p.name, selectedCountry);
294
+ else {{
295
+ const url = (selectedCountry.includes("Korea") || selectedCountry.includes("ํ•œ๊ตญ"))
296
+ ? "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name)
297
+ : "http://google.com/maps/search/" + encodeURIComponent(p.name + " " + selectedCountry);
298
+ window.open(url, '_blank');
299
+ }}
300
  }}
301
 
302
+ // ์ง€๋„ ํŒ์—… ํด๏ฟฝ๏ฟฝ๏ฟฝ ํ•ธ๋“ค๋Ÿฌ (์ˆซ์ž Key ํ™œ์šฉ)
303
+ function clickMapAction(key, type) {{
304
+ const data = MAP_CACHE[key];
305
+ if(!data) return;
306
+ if(type === 'ai') {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
307
+ else window.open(data.url, '_blank');
308
+ }}
309
+
310
+ function getStamps() {{ try {{ return JSON.parse(localStorage.getItem('drunk_passport') || '[]'); }} catch(e) {{ return []; }} }}
311
  function stampCurrentPlace() {{
312
+ if(!currentDetailPlace) return;
313
  const stamps = getStamps();
314
+ if(stamps.find(s => s.name === currentDetailPlace.name)) return alert("Already Stamped!");
 
315
  stamps.push({{ name: currentDetailPlace.name, country: currentDetailPlace.country, date: new Date().toLocaleDateString() }});
316
  localStorage.setItem('drunk_passport', JSON.stringify(stamps));
317
+ renderList(); alert("Stamped! ๐Ÿ’ฎ");
 
318
  }}
319
 
320
  function openPassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(0%)'; renderPassport(); }}
321
  function renderPassport() {{
322
  const grid = document.getElementById('passport-grid'); grid.innerHTML = "";
323
+ getStamps().forEach(s => {{
324
+ if(!s.name) return;
 
325
  const el = document.createElement('div'); el.className = 'stamp-card';
326
+ el.innerHTML = `<div class='stamp-mark' style='transform: rotate(${{Math.random()*20-10}}deg)'>
327
+ <div class='stamp-country'>${{s.country}}</div>
328
+ <div class='stamp-name'>${{s.name}}</div>
329
+ <div class='stamp-date'>${{s.date}}</div>
330
+ </div>`;
331
  grid.appendChild(el);
332
  }});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  }}
334
 
335
+ function exportData() {{ const blob = new Blob([localStorage.getItem('drunk_passport')], {{type: 'application/json'}}); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'passport.json'; a.click(); }}
336
+ function importData(input) {{ const reader = new FileReader(); reader.onload = e => {{ localStorage.setItem('drunk_passport', e.target.result); renderList(); alert("Loaded!"); }}; reader.readAsText(input.files[0]); }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
 
 
 
 
338
  function openWorldMapPage() {{
339
  document.getElementById('world-map-page').style.transform = 'translateY(0%)';
340
  if(!worldMap) {{
341
+ worldMap = L.map('full-map').setView([20, 0], 2);
342
+ L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
343
+ MAP_CACHE = {{}}; mapIdCounter = 0;
 
344
  Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
345
  if(p.lat && p.lon) {{
346
+ const key = mapIdCounter++;
347
+ const mapUrl = (c.includes("Korea") || c.includes("ํ•œ๊ตญ"))
348
+ ? "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name)
349
+ : "http://google.com/maps/search/" + encodeURIComponent(p.name + " " + c);
350
+ MAP_CACHE[key] = {{ name: p.name, country: c, url: mapUrl }};
351
 
352
+ // [์ค‘์š”] ํŒ์—… ๋ฒ„ํŠผ์—๋„ ์ˆซ์ž ID(key)๋งŒ ๋„˜๊น€
353
+ const popupHtml = `<div style='text-align:center'><b>${{p.name}}</b><br>
354
+ <div style='display:flex; gap:5px; margin-top:5px;'>
355
+ <button onclick='clickMapAction(${{key}}, "ai")' style='background:#d4af37; border:none; padding:4px 8px; border-radius:4px; font-size:11px; cursor:pointer;'>๐Ÿค– AI</button>
356
+ <button onclick='clickMapAction(${{key}}, "map")' style='background:#333; color:white; border:none; padding:4px 8px; border-radius:4px; font-size:11px; cursor:pointer;'>๐Ÿ—บ๏ธ MAP</button>
357
+ </div></div>`;
358
+ L.marker([p.lat, p.lon]).bindPopup(popupHtml).addTo(worldMap);
359
  }}
360
  }}));
361
  }}
362
  setTimeout(() => worldMap.invalidateSize(), 400);
363
  }}
 
 
 
 
 
 
 
 
 
 
 
364
 
365
+ async function callGroq(messages) {{
366
+ const url = "https://api.groq.com/openai/v1/chat/completions";
367
+ try {{
368
+ const res = await fetch(url, {{
369
+ method: 'POST',
370
+ headers: {{ 'Content-Type': 'application/json', 'Authorization': 'Bearer {GROQ_API_KEY}' }},
371
+ body: JSON.stringify({{ model: "llama-3.3-70b-versatile", messages: messages, temperature: 0.7 }})
372
+ }});
373
+ const data = await res.json(); return data.choices[0].message.content;
374
+ }} catch(e) {{ return "Error..."; }}
375
  }}
376
 
377
+ function openChat() {{ document.getElementById('chat-page').style.transform = 'translateY(0%)'; }}
378
+ function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
379
+ async function askBartender() {{
380
+ const inp = document.getElementById('chat-input'); const msg = inp.value.trim(); if(!msg) return;
381
+ addChatMessage(msg, 'user'); inp.value = "";
382
+ const res = await callGroq([{{ role: "system", content: "You are Emily. Act flirtatious. In " + TRANSLATIONS[currentLang].ai }}, {{ role: "user", content: msg }}]);
383
+ addChatMessage(res, 'bot');
384
+ }}
385
 
386
+ function addChatMessage(t, s) {{ const box = document.getElementById('chat-messages'); const div = document.createElement('div'); div.className = "msg " + s; div.innerText = t; box.appendChild(div); box.scrollTop = box.scrollHeight; }}
387
+ function closeDetail() {{ document.getElementById('detail-page').style.transform = 'translateX(100%)'; }}
388
  async function openDetail(n, c) {{
389
+ const p = PLACE_DB[c].find(x => x.name === n); if(!p) return;
390
  currentDetailPlace = {{ name: n, country: c }};
391
+ document.getElementById('detail-page').style.transform = 'translateX(0%)';
392
+ document.getElementById('repo-title').innerText = n;
393
+ document.getElementById('loader').style.display='flex';
394
  if(!miniMap) {{ miniMap = L.map('mini-map'); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(miniMap); }}
395
+ setTimeout(() => {{ miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }}, 400);
396
+ const res = await callGroq([{{ role: "system", content: "Write a travel report in " + TRANSLATIONS[currentLang].ai }}, {{ role: "user", content: "Report for " + n }}]);
397
+ document.getElementById('loader').style.display='none';
398
+ document.getElementById('repo-content').innerText = res;
399
  }}
400
 
 
 
401
  function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
402
  function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
403
+ async function searchLocation() {{
404
+ const q = document.getElementById('map-search-input').value; if(!q) return;
405
+ const res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${{encodeURIComponent(q)}}`);
406
+ const data = await res.json();
407
+ if(data.length > 0) worldMap.flyTo([data[0].lat, data[0].lon], 12);
408
+ }}
409
+ function flyToUserLocation() {{ if(userLat) worldMap.flyTo([userLat, userLon], 14); }}
410
  </script>
411
  </body>
412
  </html>