benjamin5607 commited on
Commit
4d15b3f
ยท
verified ยท
1 Parent(s): 16f458a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -44
app.py CHANGED
@@ -58,9 +58,8 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
58
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
59
 
60
  # ==========================================
61
- # 3. ํ†ตํ•ฉ ํ”„๋ก ํŠธ์—”๋“œ (String Replacement ๋ฐฉ์‹ - ์—๋Ÿฌ ๋ฐฉ์ง€)
62
  # ==========================================
63
- # f-string์„ ์“ฐ์ง€ ์•Š๊ณ  ์ผ๋ฐ˜ ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ค‘๊ด„ํ˜ธ ๋ณด์กด
64
  html_template = """
65
  <!DOCTYPE html>
66
  <html>
@@ -70,7 +69,6 @@ html_template = """
70
  <title>Drunken Plane</title>
71
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
72
  <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
73
- <link href="https://fonts.googleapis.com/css2?family=Special+Elite&display=swap" rel="stylesheet">
74
  <style>
75
  :root { --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }
76
  body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
@@ -105,22 +103,18 @@ html_template = """
105
  .msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }
106
  .msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }
107
  .reco-btn { display: inline-block; margin-top: 10px; padding: 8px 15px; background: var(--gold); color: black !important; border-radius: 15px; font-weight: bold; text-decoration: none; font-size: 12px; border:none; cursor:pointer; }
108
- .lang-switcher { position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }
109
- .lang-btn { background: rgba(0,0,0,0.5); border: 1px solid #555; color: #aaa; padding: 5px 10px; border-radius: 15px; cursor: pointer; font-size: 11px; }
110
- .lang-btn.active { background: var(--gold); color: black; border-color: var(--gold); font-weight: bold; }
 
 
111
  </style>
112
  </head>
113
  <body>
114
  <div id="main-page" class="page">
115
- <div class="lang-switcher">
116
- <div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">๐Ÿ‡ฐ๐Ÿ‡ท</div>
117
- <div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">๐Ÿ‡บ๐Ÿ‡ธ</div>
118
- <div class="lang-btn" id="btn-JP" onclick="setLanguage('JP', this)">๐Ÿ‡ฏ๐Ÿ‡ต</div>
119
- <div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">๐Ÿ‡จ๐Ÿ‡ณ</div>
120
- </div>
121
  <div style="text-align:center; padding: 25px 0;">
122
  <div style="color:var(--gold); font-size: 28px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
123
- <button onclick="openMap()" style="margin-top:15px; padding:12px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer; font-size:14px;">๐Ÿ—บ๏ธ EXPLORE WORLD MAP</button>
124
  </div>
125
  <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; margin-bottom:15px;" onchange="selectCountry(this.value)"></select></center>
126
  <div class="place-list-container" id="place-list"></div>
@@ -128,30 +122,29 @@ html_template = """
128
  </div>
129
 
130
  <div id="world-map-page" class="page">
131
- <div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold); font-size:18px; cursor:pointer;">๐Ÿ  HOME</button></div>
132
  <button class="map-gps-btn" onclick="flyToUser()">๐ŸŽฏ</button>
133
  <div id="full-map" style="width:100%; height:100%;"></div>
134
  </div>
135
 
136
  <div id="chat-page" class="page">
137
- <div class="nav-bar"><button onclick="closeChat()" style="background:none; border:none; color:var(--gold); font-size:24px; cursor:pointer;">โ†</button><span style="margin-left:15px; font-weight:bold; color:var(--gold); font-size:18px;">Emily</span></div>
138
  <div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column;"></div>
139
  <div style="padding:15px; display:flex; gap:10px; background:#111;">
140
- <input id="chat-input" type="text" style="flex:1; padding:14px; border-radius:10px; border:1px solid #333; background:#222; color:#fff;" placeholder="Whisper to Emily..." onkeydown="if(event.key==='Enter') sendChat()">
141
- <button onclick="sendChat()" style="padding:10px 20px; background:var(--gold); border:none; border-radius:10px; font-weight:bold; cursor:pointer;">SEND</button>
142
  </div>
143
  </div>
144
 
145
  <div id="detail-page" class="page">
146
- <div class="nav-bar"><button onclick="closeDetail()" style="background:none; border:none; color:var(--gold); font-size:24px; cursor:pointer;">โ†</button><div style="color:white; font-weight:bold; margin-left:15px;">Travel Report</div></div>
147
- <div id="mini-map" style="width:100%; height:260px; border-bottom:1px solid var(--gold);"></div>
148
- <div style="flex:1; overflow-y:auto; padding:25px;">
149
- <div id="repo-title" style="font-size:24px; color:var(--gold); font-weight:bold; margin-bottom:10px;"></div>
150
- <div id="repo-content" style="line-height:1.8; color:#ddd; white-space:pre-wrap; font-size:15px;"></div>
151
  </div>
152
  </div>
153
 
154
- <div id="loader" class="loading-screen"><div class="loader-ring"></div><div style="color:var(--gold); margin-top:15px; font-weight:bold;">Emily is writing...</div></div>
155
 
156
  <script>
157
  function b64DecodeUnicode(str) {
@@ -163,16 +156,8 @@ html_template = """
163
  const PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));
164
  let userLat = null, userLon = null, worldMap = null, miniMap = null;
165
  let chatHistory = [];
166
- let currentLang = "KO";
167
  let selectedCountry = "";
168
 
169
- const TRANSLATIONS = {
170
- "KO": { "ai": "Korean", "greet": "์•ˆ๋…•, ์ž๊ธฐ? ์˜ค๋Š˜ ์ •๋ง ๊ณ ์ƒ ๋งŽ์•˜์–ด. ์—๋ฐ€๋ฆฌํ•œํ…Œ ๋ญ๋“  ๋ฌผ์–ด๋ด~" },
171
- "EN": { "ai": "English", "greet": "Hey darling, rough day? Let Emily find you a perfect spot to drink." },
172
- "JP": { "ai": "Japanese", "greet": "ใ‚ใ‚‰ใ€ใƒใƒ‹ใƒผใ€‚ไปŠๆ—ฅใฏใŠ็–ฒใ‚Œๆง˜. ์—๋ฐ€๋ฆฌใซใชใ‚“ใงใ‚‚่žใ„ใฆ๏ผŸ" },
173
- "CN": { "ai": "Chinese", "greet": "ไบฒ็ˆฑ็š„๏ผŒไปŠๅคฉ่พ›่‹ฆไบ†. ๆƒณๅ–็‚นไป€ไนˆ๏ผŸ" }
174
- };
175
-
176
  window.onload = function() {
177
  const keys = Object.keys(PLACE_DB).sort();
178
  const select = document.getElementById('country-select');
@@ -188,12 +173,6 @@ html_template = """
188
  };
189
 
190
  function selectCountry(c) { selectedCountry = c; renderList(); }
191
- function setLanguage(l, el) {
192
- currentLang = l;
193
- document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
194
- el.classList.add('active');
195
- renderList();
196
- }
197
 
198
  function getMapUrl(p, country) {
199
  if (country.includes("Korea") || country.includes("ํ•œ๊ตญ")) {
@@ -212,8 +191,7 @@ html_template = """
212
  const p = countryPlaces[i];
213
  const card = document.createElement('div');
214
  card.className = 'place-card';
215
- const descKey = 'desc_' + currentLang.toLowerCase();
216
- let desc = p[descKey] || p.desc_en || p.desc_ko || "Exploring heritage...";
217
  const mapUrl = getMapUrl(p, selectedCountry);
218
  card.innerHTML = `<div class="pc-name">${p.name}</div><div class="pc-desc">${desc}</div>
219
  <div style="margin-top:15px; display:flex; gap:10px;">
@@ -226,7 +204,7 @@ html_template = """
226
  function openChat() {
227
  document.getElementById('chat-page').style.transform = 'translateY(0%)';
228
  if(chatHistory.length === 0) {
229
- addChatMessage(TRANSLATIONS[currentLang].greet, "bot");
230
  chatHistory.push({ role: "system", content: "You are Emily, a bartender. If recommending, use [Place Name]." });
231
  }
232
  }
@@ -260,10 +238,10 @@ html_template = """
260
  document.getElementById('loader').style.display = 'flex';
261
  if(!miniMap) {
262
  miniMap = L.map('mini-map');
263
- L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(miniMap);
264
  }
265
  setTimeout(() => { miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }, 400);
266
- const prompt = [{ role: "system", content: "Act as Emily. Write review in " + TRANSLATIONS[currentLang].ai }, { role: "user", content: "Review " + name }];
267
  const res = await callGroq(prompt);
268
  document.getElementById('repo-content').innerText = res;
269
  document.getElementById('loader').style.display = 'none';
@@ -287,7 +265,18 @@ html_template = """
287
  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(worldMap);
288
  for(let c in PLACE_DB) {
289
  PLACE_DB[c].forEach(p => {
290
- if(p.lat && p.lon) L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup(`<b>${p.name}</b>`);
 
 
 
 
 
 
 
 
 
 
 
291
  });
292
  }
293
  }
@@ -318,7 +307,7 @@ html_template = """
318
  </html>
319
  """
320
 
321
- # ํŒŒ์ด์ฌ ๋ณ€์ˆ˜ ์ฃผ์ž… (f-string ์—๋Ÿฌ ์›์ฒœ ์ฐจ๋‹จ)
322
  html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
323
  html_code = html_code.replace("DB_DATA_BASE64", db_base64)
324
  html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)
 
58
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
59
 
60
  # ==========================================
61
+ # 3. ํ†ตํ•ฉ ํ”„๋ก ํŠธ์—”๋“œ (Popup ๋ณต๊ตฌ ๋ฒ„์ „)
62
  # ==========================================
 
63
  html_template = """
64
  <!DOCTYPE html>
65
  <html>
 
69
  <title>Drunken Plane</title>
70
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
71
  <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
 
72
  <style>
73
  :root { --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }
74
  body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
 
103
  .msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }
104
  .msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }
105
  .reco-btn { display: inline-block; margin-top: 10px; padding: 8px 15px; background: var(--gold); color: black !important; border-radius: 15px; font-weight: bold; text-decoration: none; font-size: 12px; border:none; cursor:pointer; }
106
+
107
+ /* ํŒ์—… ์Šคํƒ€์ผ๋ง */
108
+ .leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); border-radius: 10px; }
109
+ .leaflet-popup-tip { background: var(--gold); }
110
+ .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; }
111
  </style>
112
  </head>
113
  <body>
114
  <div id="main-page" class="page">
 
 
 
 
 
 
115
  <div style="text-align:center; padding: 25px 0;">
116
  <div style="color:var(--gold); font-size: 28px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
117
+ <button onclick="openMap()" style="margin-top:15px; padding:12px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer;">๐Ÿ—บ๏ธ EXPLORE WORLD MAP</button>
118
  </div>
119
  <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; margin-bottom:15px;" onchange="selectCountry(this.value)"></select></center>
120
  <div class="place-list-container" id="place-list"></div>
 
122
  </div>
123
 
124
  <div id="world-map-page" class="page">
125
+ <div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold); font-size:18px;">๐Ÿ  HOME</button></div>
126
  <button class="map-gps-btn" onclick="flyToUser()">๐ŸŽฏ</button>
127
  <div id="full-map" style="width:100%; height:100%;"></div>
128
  </div>
129
 
130
  <div id="chat-page" class="page">
131
+ <div class="nav-bar"><button onclick="closeChat()" style="background:none; border:none; color:var(--gold); font-size:24px;">โ†</button><span style="margin-left:15px; font-weight:bold; color:var(--gold)">Emily</span></div>
132
  <div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column;"></div>
133
  <div style="padding:15px; display:flex; gap:10px; background:#111;">
134
+ <input id="chat-input" type="text" style="flex:1; padding:12px; border-radius:8px; border:1px solid #333; background:#222; color:#fff;" placeholder="Talk to Emily..."><button onclick="sendChat()" style="padding:10px 20px; background:var(--gold); border:none; border-radius:10px; font-weight:bold;">SEND</button>
 
135
  </div>
136
  </div>
137
 
138
  <div id="detail-page" class="page">
139
+ <div class="nav-bar"><button onclick="closeDetail()" style="background:none; border:none; color:var(--gold); font-size:24px;">โ†</button><div style="color:white; font-weight:bold; margin-left:15px;">Report</div></div>
140
+ <div id="mini-map" style="width:100%; height:250px;"></div>
141
+ <div style="flex:1; overflow-y:auto; padding:20px;">
142
+ <div id="repo-title" style="font-size:22px; color:var(--gold); font-weight:bold;"></div>
143
+ <div id="repo-content" style="margin-top:15px; line-height:1.7; color:#ddd; white-space:pre-wrap; font-size:14px;"></div>
144
  </div>
145
  </div>
146
 
147
+ <div id="loader" class="loading-screen"><div class="loader-ring"></div></div>
148
 
149
  <script>
150
  function b64DecodeUnicode(str) {
 
156
  const PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));
157
  let userLat = null, userLon = null, worldMap = null, miniMap = null;
158
  let chatHistory = [];
 
159
  let selectedCountry = "";
160
 
 
 
 
 
 
 
 
161
  window.onload = function() {
162
  const keys = Object.keys(PLACE_DB).sort();
163
  const select = document.getElementById('country-select');
 
173
  };
174
 
175
  function selectCountry(c) { selectedCountry = c; renderList(); }
 
 
 
 
 
 
176
 
177
  function getMapUrl(p, country) {
178
  if (country.includes("Korea") || country.includes("ํ•œ๊ตญ")) {
 
191
  const p = countryPlaces[i];
192
  const card = document.createElement('div');
193
  card.className = 'place-card';
194
+ let desc = p.desc_en || p.desc_ko || "Exploring heritage...";
 
195
  const mapUrl = getMapUrl(p, selectedCountry);
196
  card.innerHTML = `<div class="pc-name">${p.name}</div><div class="pc-desc">${desc}</div>
197
  <div style="margin-top:15px; display:flex; gap:10px;">
 
204
  function openChat() {
205
  document.getElementById('chat-page').style.transform = 'translateY(0%)';
206
  if(chatHistory.length === 0) {
207
+ addChatMessage("Hey darling, what's your mood for a drink?", "bot");
208
  chatHistory.push({ role: "system", content: "You are Emily, a bartender. If recommending, use [Place Name]." });
209
  }
210
  }
 
238
  document.getElementById('loader').style.display = 'flex';
239
  if(!miniMap) {
240
  miniMap = L.map('mini-map');
241
+ L.tileLayer('https://{s}.tile.openstreetmap.org/etc/').addTo(miniMap);
242
  }
243
  setTimeout(() => { miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }, 400);
244
+ const prompt = [{ role: "system", content: "Act as Emily. Detailed review." }, { role: "user", content: "Review " + name }];
245
  const res = await callGroq(prompt);
246
  document.getElementById('repo-content').innerText = res;
247
  document.getElementById('loader').style.display = 'none';
 
265
  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(worldMap);
266
  for(let c in PLACE_DB) {
267
  PLACE_DB[c].forEach(p => {
268
+ if(p.lat && p.lon) {
269
+ const mapUrl = getMapUrl(p, c);
270
+ // [์ˆ˜์ •] ํŒ์—… ๋‚ด์šฉ ๋ณต๊ตฌ: ์ด๋ฆ„ + ์นดํ…Œ๊ณ ๋ฆฌ + ๋ฆฌ๋ทฐ ๋ฒ„ํŠผ + ๋งต ์ด๋™ ๋ฒ„ํŠผ
271
+ const popupHtml = `
272
+ <div style="text-align:center;">
273
+ <b style="color:var(--gold);">${p.name}</b><br>
274
+ <small style="color:#aaa;">${p.category || ""}</small><br>
275
+ <button class="popup-btn" onclick="closeMap(); openReview('${p.name}', '${c}')">๐Ÿค– REVIEW</button>
276
+ <button class="popup-btn" style="background:#333; color:white; border:1px solid #555;" onclick="window.open('${mapUrl}', '_blank')">๐Ÿ“ MAP</button>
277
+ </div>`;
278
+ L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup(popupHtml);
279
+ }
280
  });
281
  }
282
  }
 
307
  </html>
308
  """
309
 
310
+ # ํŒŒ์ด์ฌ ๋ณ€์ˆ˜ ์ฃผ์ž… (replace ๋ฐฉ์‹์œผ๋กœ ์ค‘๊ด„ํ˜ธ ์—๋Ÿฌ ๋ฐฉ์ง€)
311
  html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
312
  html_code = html_code.replace("DB_DATA_BASE64", db_base64)
313
  html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)