benjamin5607 commited on
Commit
bbabc6c
Β·
verified Β·
1 Parent(s): a8b52b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -63
app.py CHANGED
@@ -8,13 +8,15 @@ import requests
8
  import io
9
 
10
  # ==========================================
11
- # πŸ” 1. μ‹œν¬λ¦Ώ 및 κΈ°λ³Έ μ„€μ •
12
  # ==========================================
13
- GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
 
14
  SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")
15
 
16
  st.set_page_config(page_title="Drunken Plane", page_icon="✈️", layout="wide")
17
 
 
18
  st.markdown("""
19
  <style>
20
  .block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
@@ -24,34 +26,54 @@ st.markdown("""
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
- # 2. 데이터 λ‘œλ“œ 및 μ •μ œ
28
  # ==========================================
29
  PLACE_DB = {}
 
 
 
 
 
 
 
30
  try:
31
  if SHEET_URL:
32
- response = requests.get(SHEET_URL)
33
  response.encoding = 'utf-8'
 
34
  df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
35
- df = df.fillna("")
36
  df.columns = df.columns.str.strip()
 
 
37
  for col in df.select_dtypes(include=['object']).columns:
38
  df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
 
39
  if 'Country' in df.columns:
40
  for country, group in df.groupby('Country'):
41
  PLACE_DB[country] = group.fillna("").to_dict(orient='records')
 
 
 
 
42
  except Exception as e:
43
- st.error(f"Data Load Error: {e}")
 
44
 
 
45
  emily_base64 = ""
46
  if os.path.exists('emily.jpg'):
47
- with open("emily.jpg", "rb") as f:
48
- emily_base64 = base64.b64encode(f.read()).decode()
 
 
49
 
 
50
  db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
51
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
52
 
53
  # ==========================================
54
- # 3. 톡합 ν”„λ‘ νŠΈμ—”λ“œ (λͺ¨λΈ λ³€κ²½ + 상세 μ—λŸ¬ 좜λ ₯)
55
  # ==========================================
56
  html_template = """
57
  <!DOCTYPE html>
@@ -66,25 +88,26 @@ html_template = """
66
  body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
67
  .page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
68
 
69
- .top-nav { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 500; }
 
70
  .passport-btn { font-size: 26px; cursor: pointer; background: rgba(255,215,0,0.1); padding: 8px; border-radius: 15px; border: 1px solid rgba(212,175,55,0.3); }
71
  .lang-switcher { display: flex; gap: 6px; }
72
  .lang-btn { background: rgba(0,0,0,0.6); border: 1px solid #444; color: #888; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 11px; }
73
  .lang-btn.active { background: var(--gold); color: black; font-weight: bold; border-color: var(--gold); }
74
 
75
- .type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; scrollbar-width: none; }
76
- .type-btn { padding: 8px 16px; border-radius: 20px; font-size: 11px; font-weight: bold; background: #1a1a1a; color: #777; border: 1px solid #333; white-space: nowrap; cursor: pointer; }
77
- .type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
78
-
79
  .place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
80
- .place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; }
81
  .pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
82
- .pc-name { font-size: 19px; font-weight: bold; color: var(--gold); line-height: 1.2; flex: 1; }
83
  .pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
84
- .pc-label { font-size: 11px; padding: 4px 10px; border-radius: 10px; background: rgba(212, 175, 55, 0.15); color: var(--gold); border: 1px solid var(--gold); font-weight: 900; white-space: nowrap; }
85
- .pc-desc { font-size: 13.5px; color: #aaa; line-height: 1.6; margin: 12px 0; }
86
  .btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
87
 
 
 
 
 
88
  .bartender-btn { position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('IMAGE_DATA'); background-size: cover; border: 3px solid var(--gold); z-index: 999; box-shadow: 0 0 20px rgba(212, 175, 55, 0.5); cursor: pointer; }
89
 
90
  #world-map-page, #passport-page, #chat-page { background: #000; z-index: 2000; transform: translateY(100%); }
@@ -92,12 +115,13 @@ html_template = """
92
  #detail-page { background: #0a0a0a; z-index: 4000; transform: translateX(100%); }
93
  .nav-bar { height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; background: #111; }
94
 
 
95
  .msg { max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; margin-bottom: 12px; }
96
  .msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }
97
  .msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }
98
  .reco-btn { display: block; margin-top: 8px; padding: 10px; background: var(--gold); color: black !important; border-radius: 10px; font-weight: bold; text-decoration: none; font-size: 12px; cursor: pointer; border:none; width: 100%; text-align: center; }
99
- .popup-btn { background: var(--gold); color: black; border: none; padding: 5px 10px; border-radius: 5px; font-weight: bold; font-size: 11px; cursor: pointer; margin-top: 5px; width: 100%; }
100
- .leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); }
101
  .stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
102
  .stamp { height: 90px; border-radius: 15px; border: 2px dashed #333; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #444; background: #161625; }
103
  .stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
@@ -110,13 +134,11 @@ html_template = """
110
  <div class="lang-switcher">
111
  <div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">πŸ‡°πŸ‡·</div>
112
  <div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">πŸ‡ΊπŸ‡Έ</div>
113
- <div class="lang-btn" id="btn-JP" onclick="setLanguage('JP', this)">πŸ‡―πŸ‡΅</div>
114
- <div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">πŸ‡¨πŸ‡³</div>
115
  </div>
116
  </div>
117
  <div style="text-align:center; padding: 5px 0 15px 0;">
118
  <div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
119
- <button onclick="openMap()" style="margin-top:10px; padding:10px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer;">πŸ—ΊοΈ EXPLORE WORLD MAP</button>
120
  </div>
121
  <center><select id="country-select" style="width:85%; max-width:400px; padding:12px; background:#111; border:1px solid var(--gold); color:white; border-radius:10px;" onchange="selectCountry(this.value)"></select></center>
122
  <div class="type-filter-container" id="filter-box"></div>
@@ -125,6 +147,7 @@ html_template = """
125
  </div>
126
 
127
  <div id="passport-page" class="page"><div class="nav-bar"><button onclick="closePassport()">←</button> MY PASSPORT</div><div id="stamp-grid" class="stamp-grid" style="overflow-y:auto;"></div></div>
 
128
  <div id="world-map-page" class="page"><div class="nav-bar"><button onclick="closeMap()">🏠 HOME</button></div><div id="full-map" style="width:100%; height:100%;"></div></div>
129
 
130
  <div id="chat-page" class="page">
@@ -139,42 +162,63 @@ html_template = """
139
  <div id="detail-page" class="page"><div class="nav-bar"><button onclick="closeDetail()">←</button> Review</div><div id="repo-content" style="padding:20px; white-space:pre-wrap; color:#ddd; line-height:1.7;"></div></div>
140
 
141
  <script>
142
- function b64DecodeUnicode(str) { return decodeURIComponent(atob(str).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }
 
 
 
 
 
 
143
  const PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));
144
  let currentLang = "KO", selectedCountry = "", selectedType = "All", chatHistory = [];
145
  let visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
146
  let userLat = null, userLon = null;
 
147
 
148
  const TRANSLATIONS = {
149
- "KO": { "ai": "Korean", "aiBtn": "AI 리뷰", "mapBtn": "지도", "filters": ["🌐 전체", "🏺 전톡주", "πŸ₯ƒ μœ„μŠ€ν‚€", "🍺 λ§₯μ£Ό", "🍷 와인", "🍹 λ°”"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
150
- "EN": { "ai": "English", "aiBtn": "AI REVIEW", "mapBtn": "MAP", "filters": ["🌐 All", "🏺 Trad.", "πŸ₯ƒ Whiskey", "🍺 Beer", "🍷 Wine", "🍹 Bar"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
151
- "JP": { "ai": "Japanese", "aiBtn": "AI レビγƒ₯γƒΌ", "mapBtn": "εœ°ε›³", "filters": ["🌐 全部", "🏺 伝硱酒", "πŸ₯ƒ ウむス킀", "🍺 ビール", "🍷 ワむン", "🍹 バー"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
152
- "CN": { "ai": "Chinese", "aiBtn": "AI η‚Ήθ―„", "mapBtn": "εœ°ε›Ύ", "filters": ["🌐 全部", "🏺 δΌ η»Ÿι…’", "πŸ₯ƒ 威士忌", "🍺 ε•€ι…’", "🍷 葑萄酒", "🍹 酒吧"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
153
  };
154
 
 
155
  function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
156
- var R = 6371; var dLat = deg2rad(lat2-lat1); var dLon = deg2rad(lon2-lon1);
157
- var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2);
158
- var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
159
- return (R * c).toFixed(1);
 
 
160
  }
161
  function deg2rad(deg) { return deg * (Math.PI/180); }
162
 
 
163
  function getMapUrl(p, country) {
164
  if (country.includes("Korea") || country.includes("ν•œκ΅­")) return "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name);
165
  return "https://www.google.com/maps/search/" + encodeURIComponent(p.name) + "/@" + p.lat + "," + p.lon + ",17z";
166
  }
167
 
 
168
  window.onload = function() {
169
- const keys = Object.keys(PLACE_DB).sort();
170
- const select = document.getElementById('country-select');
171
- keys.forEach(k => { const opt = document.createElement('option'); opt.value = k; opt.text = k; select.appendChild(opt); });
172
- if(keys.length > 0) selectCountry(keys[0]);
173
- renderFilters();
174
- navigator.geolocation.getCurrentPosition(function(p) { userLat = p.coords.latitude; userLon = p.coords.longitude; renderList(); });
 
 
 
 
 
 
 
 
 
 
175
  };
176
 
177
  function setLanguage(l, el) { currentLang = l; document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); el.classList.add('active'); renderFilters(); renderList(); }
 
178
  function renderFilters() {
179
  const box = document.getElementById('filter-box'); box.innerHTML = "";
180
  TRANSLATIONS[currentLang].filters.forEach((f, i) => {
@@ -183,6 +227,7 @@ html_template = """
183
  box.appendChild(btn);
184
  });
185
  }
 
186
  function selectCountry(c) { selectedCountry = c; renderList(); }
187
 
188
  function renderList() {
@@ -195,16 +240,15 @@ html_template = """
195
  const card = document.createElement('div'); card.className = 'place-card';
196
  const displayLabel = p.label || p.category || "";
197
  const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
 
198
  let distHtml = "";
199
  if(userLat && userLon && p.lat && p.lon) {
200
  const dist = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
201
  distHtml = `<span class="pc-dist">(πŸ“ ${dist}km)</span>`;
202
  }
 
203
  card.innerHTML = `
204
- <div class="pc-header">
205
- <div class="pc-name">${p.name} ${distHtml}</div>
206
- <div class="pc-label">${displayLabel}</div>
207
- </div>
208
  <div class="pc-desc">${desc}</div>
209
  <div style="display:flex; gap:10px; margin-top:15px;">
210
  <button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
@@ -214,28 +258,22 @@ html_template = """
214
  });
215
  }
216
 
217
- // [μ€‘μš”] Groq API 호좜 ν•¨μˆ˜ (μ•ˆμ •μ μΈ λͺ¨λΈλ‘œ ꡐ체 및 μ—λŸ¬ 상세화)
218
  async function callGroq(msgs) {
219
- const apiKey = "GROQ_KEY"; // νŒŒμ΄μ¬μ—μ„œ μΉ˜ν™˜λ¨
220
- if(!apiKey || apiKey.length < 5) return "Error: API Key is missing. Please check your settings.";
221
 
222
  try {
223
  const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
224
- method: "POST",
225
- headers: { "Content-Type": "application/json", "Authorization": "Bearer " + apiKey },
226
- // λͺ¨λΈμ„ κ°€μž₯ μ•ˆμ •μ μΈ llama-3.1-70b-versatile 둜 λ³€κ²½
227
  body: JSON.stringify({ model: "llama-3.1-70b-versatile", messages: msgs, temperature: 0.7 })
228
  });
229
 
230
- if (!r.ok) {
231
- const errData = await r.json();
232
- const errMsg = errData.error ? errData.error.message : r.statusText;
233
- return "Emily Error: " + r.status + " (" + errMsg + ")";
234
- }
235
 
236
  const d = await r.json();
237
  return d.choices[0].message.content;
238
- } catch(e) { return "Emily Network Error: " + e.message; }
239
  }
240
 
241
  async function sendChat() {
@@ -243,30 +281,37 @@ html_template = """
243
  addChatMessage(msg, 'user'); inp.value = "";
244
  chatHistory.push({ role: "user", content: msg });
245
 
 
246
  let nearbyContext = "";
 
 
247
  if(userLat && userLon) {
248
  let nearbyPlaces = [];
249
  for(let c in PLACE_DB) {
250
  PLACE_DB[c].forEach(p => {
251
  if(p.lat && p.lon) {
252
  const d = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
253
- if(parseFloat(d) <= 20) {
254
- nearbyPlaces.push(p.name + "(" + d + "km)");
255
- }
256
  }
257
  });
258
  }
259
- if(nearbyPlaces.length > 0) {
260
- nearbyContext = " [System: User GPS (" + userLat + "," + userLon + "). Places within 20km: " + nearbyPlaces.join(", ") + ". Prioritize these if user asks 'nearby'.]";
261
- }
262
  }
 
 
 
263
 
264
- const sysPrompt = "You are Emily, a bartender. Speak ONLY in " + TRANSLATIONS[currentLang].ai + ". IMPORTANT: If recommending a place, write the name in [Brackets]." + nearbyContext;
 
 
 
 
265
 
266
  const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
267
 
 
268
  let finalHtml = botMsg;
269
- const regex = /\\[(.*?)\\]/g;
270
  let match;
271
  while ((match = regex.exec(botMsg)) !== null) {
272
  const pName = match[1];
@@ -292,6 +337,7 @@ html_template = """
292
  }
293
 
294
  function markVisited(name) { if(!visitedPlaces.includes(name)) { visitedPlaces.push(name); localStorage.setItem('visitedPlaces', JSON.stringify(visitedPlaces)); } }
 
295
  function openPassport() { document.getElementById('passport-page').style.transform = 'translateX(0%)'; const grid = document.getElementById('stamp-grid'); grid.innerHTML = ""; for(let c in PLACE_DB) { PLACE_DB[c].forEach(p => { const active = visitedPlaces.includes(p.name); const div = document.createElement('div'); div.className = 'stamp' + (active ? ' active' : ''); div.innerHTML = active ? `🍷<br><b>${p.name}</b>` : `✈️`; grid.appendChild(div); }); } }
296
  function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
297
 
@@ -323,8 +369,9 @@ html_template = """
323
  </html>
324
  """
325
 
 
326
  html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
327
  html_code = html_code.replace("DB_DATA_BASE64", db_base64)
328
- html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)
329
 
330
  components.html(html_code, height=1000, scrolling=True)
 
8
  import io
9
 
10
  # ==========================================
11
+ # πŸ› οΈ 1. μ„€μ • 및 μ‹œν¬λ¦Ώ (여기에 ν‚€λ₯Ό μž…λ ₯ν•˜μ„Έμš”!)
12
  # ==========================================
13
+ # λ”°μ˜΄ν‘œ μ•ˆμ— API ν‚€λ₯Ό 직접 λΆ™μ—¬λ„£μœΌμ„Έμš”. 예: "gsk_..."
14
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
15
  SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")
16
 
17
  st.set_page_config(page_title="Drunken Plane", page_icon="✈️", layout="wide")
18
 
19
+ # μŠ€νƒ€μΌ: μ—¬λ°± 제거 및 전체 ν™”λ©΄ μ‚¬μš©
20
  st.markdown("""
21
  <style>
22
  .block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
 
26
  """, unsafe_allow_html=True)
27
 
28
  # ==========================================
29
+ # πŸ’Ύ 2. 데이터 λ‘œλ“œ (μ•ˆμ „ μž₯치 포함)
30
  # ==========================================
31
  PLACE_DB = {}
32
+
33
+ # [λΉ„μƒμš©] μ‹œνŠΈ λ‘œλ“œ μ‹€νŒ¨ μ‹œ μ‚¬μš©ν•  더미 데이터
34
+ DUMMY_DATA = {
35
+ "Korea": [{"name": "Zest", "lat": 37.525, "lon": 127.040, "category": "Bar", "label": "🍸 World Best", "desc_ko": "μ„œμšΈ 졜고의 μΉ΅ν…ŒμΌ λ°”", "address": "μ„œμšΈ 강남ꡬ λ„μ‚°λŒ€λ‘œ55κΈΈ 26"}],
36
+ "Malaysia": [{"name": "Bar Trigona", "lat": 3.159, "lon": 101.714, "category": "Bar", "label": "🐝 Sustainable", "desc_ko": "μΏ μ•ŒλΌλ£Έν‘Έλ₯΄μ˜ 지속 κ°€λŠ₯ν•œ λ°”", "address": "Four Seasons Hotel, Kuala Lumpur"}]
37
+ }
38
+
39
  try:
40
  if SHEET_URL:
41
+ response = requests.get(SHEET_URL, timeout=5) # 5초 νƒ€μž„μ•„μ›ƒ
42
  response.encoding = 'utf-8'
43
+ response.raise_for_status()
44
  df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
45
+ df = df.fillna("") # 빈칸 μ±„μš°κΈ°
46
  df.columns = df.columns.str.strip()
47
+
48
+ # 특수문자 μ΄μŠ€μΌ€μ΄ν”„ (JS 였λ₯˜ λ°©μ§€)
49
  for col in df.select_dtypes(include=['object']).columns:
50
  df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
51
+
52
  if 'Country' in df.columns:
53
  for country, group in df.groupby('Country'):
54
  PLACE_DB[country] = group.fillna("").to_dict(orient='records')
55
+ else:
56
+ # μ‹œνŠΈ URL이 μ—†μœΌλ©΄ 더미 데이터 μ‚¬μš© (μ•± 꺼짐 λ°©μ§€)
57
+ PLACE_DB = DUMMY_DATA
58
+
59
  except Exception as e:
60
+ st.error(f"⚠️ 데이터 λ‘œλ“œ μ‹€νŒ¨ (더미 λ°μ΄ν„°λ‘œ μ „ν™˜ν•©λ‹ˆλ‹€): {e}")
61
+ PLACE_DB = DUMMY_DATA
62
 
63
+ # 에밀리 이미지 처리
64
  emily_base64 = ""
65
  if os.path.exists('emily.jpg'):
66
+ try:
67
+ with open("emily.jpg", "rb") as f:
68
+ emily_base64 = base64.b64encode(f.read()).decode()
69
+ except: pass
70
 
71
+ # JSON 직렬화
72
  db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
73
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
74
 
75
  # ==========================================
76
+ # πŸ–₯️ 3. 톡합 ν”„λ‘ νŠΈμ—”λ“œ (JavaScript 볡ꡬ)
77
  # ==========================================
78
  html_template = """
79
  <!DOCTYPE html>
 
88
  body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
89
  .page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
90
 
91
+ /* UI Components */
92
+ .top-nav { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 500; background: rgba(0,0,0,0.8); }
93
  .passport-btn { font-size: 26px; cursor: pointer; background: rgba(255,215,0,0.1); padding: 8px; border-radius: 15px; border: 1px solid rgba(212,175,55,0.3); }
94
  .lang-switcher { display: flex; gap: 6px; }
95
  .lang-btn { background: rgba(0,0,0,0.6); border: 1px solid #444; color: #888; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 11px; }
96
  .lang-btn.active { background: var(--gold); color: black; font-weight: bold; border-color: var(--gold); }
97
 
 
 
 
 
98
  .place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
99
+ .place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; }
100
  .pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
101
+ .pc-name { font-size: 18px; font-weight: bold; color: var(--gold); flex: 1; }
102
  .pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
103
+ .pc-label { font-size: 11px; padding: 3px 8px; border-radius: 8px; background: rgba(212,175,55,0.15); color: var(--gold); border: 1px solid var(--gold); white-space: nowrap; }
104
+ .pc-desc { font-size: 13px; color: #aaa; margin: 10px 0; line-height: 1.5; }
105
  .btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
106
 
107
+ .type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; scrollbar-width: none; }
108
+ .type-btn { padding: 8px 16px; border-radius: 20px; font-size: 11px; font-weight: bold; background: #1a1a1a; color: #777; border: 1px solid #333; white-space: nowrap; cursor: pointer; }
109
+ .type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
110
+
111
  .bartender-btn { position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('IMAGE_DATA'); background-size: cover; border: 3px solid var(--gold); z-index: 999; box-shadow: 0 0 20px rgba(212, 175, 55, 0.5); cursor: pointer; }
112
 
113
  #world-map-page, #passport-page, #chat-page { background: #000; z-index: 2000; transform: translateY(100%); }
 
115
  #detail-page { background: #0a0a0a; z-index: 4000; transform: translateX(100%); }
116
  .nav-bar { height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; background: #111; }
117
 
118
+ /* Chat & Reco */
119
  .msg { max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; margin-bottom: 12px; }
120
  .msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }
121
  .msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }
122
  .reco-btn { display: block; margin-top: 8px; padding: 10px; background: var(--gold); color: black !important; border-radius: 10px; font-weight: bold; text-decoration: none; font-size: 12px; cursor: pointer; border:none; width: 100%; text-align: center; }
123
+
124
+ /* Passport */
125
  .stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
126
  .stamp { height: 90px; border-radius: 15px; border: 2px dashed #333; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #444; background: #161625; }
127
  .stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
 
134
  <div class="lang-switcher">
135
  <div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">πŸ‡°πŸ‡·</div>
136
  <div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">πŸ‡ΊπŸ‡Έ</div>
 
 
137
  </div>
138
  </div>
139
  <div style="text-align:center; padding: 5px 0 15px 0;">
140
  <div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
141
+ <button onclick="openMap()" style="margin-top:10px; padding:10px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer;">πŸ—ΊοΈ EXPLORE WORLD</button>
142
  </div>
143
  <center><select id="country-select" style="width:85%; max-width:400px; padding:12px; background:#111; border:1px solid var(--gold); color:white; border-radius:10px;" onchange="selectCountry(this.value)"></select></center>
144
  <div class="type-filter-container" id="filter-box"></div>
 
147
  </div>
148
 
149
  <div id="passport-page" class="page"><div class="nav-bar"><button onclick="closePassport()">←</button> MY PASSPORT</div><div id="stamp-grid" class="stamp-grid" style="overflow-y:auto;"></div></div>
150
+
151
  <div id="world-map-page" class="page"><div class="nav-bar"><button onclick="closeMap()">🏠 HOME</button></div><div id="full-map" style="width:100%; height:100%;"></div></div>
152
 
153
  <div id="chat-page" class="page">
 
162
  <div id="detail-page" class="page"><div class="nav-bar"><button onclick="closeDetail()">←</button> Review</div><div id="repo-content" style="padding:20px; white-space:pre-wrap; color:#ddd; line-height:1.7;"></div></div>
163
 
164
  <script>
165
+ // Base64 λ””μ½”λ”© (μ•ˆμ „ μž₯치 μΆ”κ°€)
166
+ function b64DecodeUnicode(str) {
167
+ try {
168
+ return decodeURIComponent(atob(str).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join(''));
169
+ } catch(e) { console.error("Base64 Error", e); return "{}"; }
170
+ }
171
+
172
  const PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));
173
  let currentLang = "KO", selectedCountry = "", selectedType = "All", chatHistory = [];
174
  let visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
175
  let userLat = null, userLon = null;
176
+ let worldMap = null; // λ§΅ 객체 μ „μ—­ λ³€μˆ˜
177
 
178
  const TRANSLATIONS = {
179
+ "KO": { "ai": "Korean", "greet": "μ•ˆλ…•? μ˜€λŠ˜μ€ μ–΄λ””μ„œ ν•œμž”ν• κΉŒ?", "aiBtn": "AI 리뷰", "mapBtn": "지도", "filters": ["🌐 전체", "🏺 전톡주", "πŸ₯ƒ μœ„μŠ€ν‚€", "🍺 λ§₯μ£Ό", "🍷 와인", "🍹 λ°”"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
180
+ "EN": { "ai": "English", "greet": "Hey! Where to drink tonight?", "aiBtn": "AI REVIEW", "mapBtn": "MAP", "filters": ["🌐 All", "🏺 Trad.", "πŸ₯ƒ Whiskey", "🍺 Beer", "🍷 Wine", "🍹 Bar"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
 
 
181
  };
182
 
183
+ // 거리 계산 (Haversine)
184
  function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
185
+ try {
186
+ var R = 6371; var dLat = deg2rad(lat2-lat1); var dLon = deg2rad(lon2-lon1);
187
+ var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2);
188
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
189
+ return (R * c).toFixed(1);
190
+ } catch(e) { return "?"; }
191
  }
192
  function deg2rad(deg) { return deg * (Math.PI/180); }
193
 
194
+ // 지도 URL 생성 (ν•œκ΅­ -> 넀이버 / ν•΄μ™Έ -> ꡬ글)
195
  function getMapUrl(p, country) {
196
  if (country.includes("Korea") || country.includes("ν•œκ΅­")) return "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name);
197
  return "https://www.google.com/maps/search/" + encodeURIComponent(p.name) + "/@" + p.lat + "," + p.lon + ",17z";
198
  }
199
 
200
+ // μ΄ˆκΈ°ν™”
201
  window.onload = function() {
202
+ try {
203
+ const keys = Object.keys(PLACE_DB).sort();
204
+ const select = document.getElementById('country-select');
205
+ keys.forEach(k => { const opt = document.createElement('option'); opt.value = k; opt.text = k; select.appendChild(opt); });
206
+
207
+ if(keys.length > 0) selectCountry(keys[0]);
208
+ renderFilters();
209
+
210
+ // GPS μ‹œλ„ (μ‹€νŒ¨ν•΄λ„ 앱은 λ™μž‘)
211
+ if(navigator.geolocation) {
212
+ navigator.geolocation.getCurrentPosition(function(p) {
213
+ userLat = p.coords.latitude; userLon = p.coords.longitude;
214
+ renderList(); // μœ„μΉ˜ 작으면 거리 κ°±μ‹ 
215
+ }, function(e) { console.log("GPS Failed", e); });
216
+ }
217
+ } catch(e) { console.error("Init Error", e); }
218
  };
219
 
220
  function setLanguage(l, el) { currentLang = l; document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); el.classList.add('active'); renderFilters(); renderList(); }
221
+
222
  function renderFilters() {
223
  const box = document.getElementById('filter-box'); box.innerHTML = "";
224
  TRANSLATIONS[currentLang].filters.forEach((f, i) => {
 
227
  box.appendChild(btn);
228
  });
229
  }
230
+
231
  function selectCountry(c) { selectedCountry = c; renderList(); }
232
 
233
  function renderList() {
 
240
  const card = document.createElement('div'); card.className = 'place-card';
241
  const displayLabel = p.label || p.category || "";
242
  const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
243
+
244
  let distHtml = "";
245
  if(userLat && userLon && p.lat && p.lon) {
246
  const dist = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
247
  distHtml = `<span class="pc-dist">(πŸ“ ${dist}km)</span>`;
248
  }
249
+
250
  card.innerHTML = `
251
+ <div class="pc-header"><div class="pc-name">${p.name} ${distHtml}</div><div class="pc-label">${displayLabel}</div></div>
 
 
 
252
  <div class="pc-desc">${desc}</div>
253
  <div style="display:flex; gap:10px; margin-top:15px;">
254
  <button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
 
258
  });
259
  }
260
 
261
+ // [μ€‘μš”] API 호좜 (μ•ˆμ „μ„± κ°•ν™”)
262
  async function callGroq(msgs) {
263
+ const apiKey = "GROQ_KEY_INJECTED"; // Pythonμ—μ„œ μΉ˜ν™˜λ¨
264
+ if(!apiKey || apiKey.length < 10) return "Error: API Key is missing inside the code.";
265
 
266
  try {
267
  const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
268
+ method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer " + apiKey },
 
 
269
  body: JSON.stringify({ model: "llama-3.1-70b-versatile", messages: msgs, temperature: 0.7 })
270
  });
271
 
272
+ if (!r.ok) return "Emily Error: " + r.status + " (Please check API Key)";
 
 
 
 
273
 
274
  const d = await r.json();
275
  return d.choices[0].message.content;
276
+ } catch(e) { return "Network Error: " + e.message; }
277
  }
278
 
279
  async function sendChat() {
 
281
  addChatMessage(msg, 'user'); inp.value = "";
282
  chatHistory.push({ role: "user", content: msg });
283
 
284
+ // 슀마트 μ»¨ν…μŠ€νŠΈ 생성 (거리 20km / λ„μ‹œ 전체)
285
  let nearbyContext = "";
286
+ let cityContext = "";
287
+
288
  if(userLat && userLon) {
289
  let nearbyPlaces = [];
290
  for(let c in PLACE_DB) {
291
  PLACE_DB[c].forEach(p => {
292
  if(p.lat && p.lon) {
293
  const d = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
294
+ if(parseFloat(d) <= 20) nearbyPlaces.push(p.name + "(" + d + "km)");
 
 
295
  }
296
  });
297
  }
298
+ if(nearbyPlaces.length > 0) nearbyContext = " [GPS: User is within 20km of: " + nearbyPlaces.join(", ") + "]";
 
 
299
  }
300
+
301
+ // λͺ¨λ“  λ„μ‹œ 정보도 제곡 (원거리 μΆ”μ²œμš©)
302
+ cityContext = " [Database Cities: " + Object.keys(PLACE_DB).join(", ") + "]";
303
 
304
+ const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
305
+ 1. If recommending a place, put name in [Brackets].
306
+ 2. If user says 'nearby', use GPS info.
307
+ 3. If user says city name, ignore GPS and recommend from that city.
308
+ ${nearbyContext} ${cityContext}`;
309
 
310
  const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
311
 
312
+ // 링크 생성 (μ •κ·œμ‹ μ΄μŠ€μΌ€μ΄ν”„ μˆ˜μ • μ™„λ£Œ)
313
  let finalHtml = botMsg;
314
+ const regex = /\[(.*?)\]/g;
315
  let match;
316
  while ((match = regex.exec(botMsg)) !== null) {
317
  const pName = match[1];
 
337
  }
338
 
339
  function markVisited(name) { if(!visitedPlaces.includes(name)) { visitedPlaces.push(name); localStorage.setItem('visitedPlaces', JSON.stringify(visitedPlaces)); } }
340
+
341
  function openPassport() { document.getElementById('passport-page').style.transform = 'translateX(0%)'; const grid = document.getElementById('stamp-grid'); grid.innerHTML = ""; for(let c in PLACE_DB) { PLACE_DB[c].forEach(p => { const active = visitedPlaces.includes(p.name); const div = document.createElement('div'); div.className = 'stamp' + (active ? ' active' : ''); div.innerHTML = active ? `🍷<br><b>${p.name}</b>` : `✈️`; grid.appendChild(div); }); } }
342
  function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
343
 
 
369
  </html>
370
  """
371
 
372
+ # ν‚€ μ£Όμž… 및 λ Œλ”λ§
373
  html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
374
  html_code = html_code.replace("DB_DATA_BASE64", db_base64)
375
+ html_code = html_code.replace("GROQ_KEY_INJECTED", GROQ_API_KEY) # μžλ°”μŠ€ν¬λ¦½νŠΈμ— ν‚€ μ£Όμž…
376
 
377
  components.html(html_code, height=1000, scrolling=True)