Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ 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")
|
|
@@ -24,37 +24,33 @@ st.markdown("""
|
|
| 24 |
""", unsafe_allow_html=True)
|
| 25 |
|
| 26 |
# ==========================================
|
| 27 |
-
# 2. ๋ฐ์ดํฐ ๋ก๋ ๋ฐ
|
| 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)
|
| 37 |
response.raise_for_status()
|
| 38 |
|
| 39 |
-
# 1. CSV ํ์ฑ
|
| 40 |
try:
|
| 41 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 42 |
except:
|
| 43 |
df = pd.read_csv(io.StringIO(response.text), engine='python', on_bad_lines='skip')
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
# ์ค๋ฐ๊ฟ, ํญ
|
| 47 |
-
df = df.replace({r'\r': ' ', r'\n': ' ', r'
|
| 48 |
-
|
| 49 |
-
# ์ปฌ๋ผ ์ด๋ฆ ์ ๋ฆฌ
|
| 50 |
df.columns = df.columns.str.strip()
|
| 51 |
col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
|
| 52 |
df.rename(columns=col_mapping, inplace=True)
|
| 53 |
|
| 54 |
-
# 3. JSON ๊ตฌ์กฐ ๋ณํ
|
| 55 |
if 'Country' in df.columns:
|
| 56 |
for country, group in df.groupby('Country'):
|
| 57 |
-
# NaN ๊ฐ์ ๋น ๋ฌธ์์ด๋ก ์ฒ๋ฆฌ
|
| 58 |
cleaned_group = group.fillna("").to_dict(orient='records')
|
| 59 |
PLACE_DB[country] = cleaned_group
|
| 60 |
else:
|
|
@@ -78,12 +74,11 @@ if os.path.exists('emily.jpg'):
|
|
| 78 |
emily_base64 = base64.b64encode(f.read()).decode()
|
| 79 |
except: pass
|
| 80 |
|
| 81 |
-
# JSON ๋คํ ์ ensure_ascii=False๋ก ํ๊ธ ๊นจ์ง ๋ฐฉ์ง
|
| 82 |
db_json_raw = json.dumps(PLACE_DB, ensure_ascii=False)
|
| 83 |
db_base64 = base64.b64encode(db_json_raw.encode('utf-8')).decode('utf-8')
|
| 84 |
|
| 85 |
# ==========================================
|
| 86 |
-
# 4. ํ๋ก ํธ์๋ (HTML/JS/CSS) -
|
| 87 |
# ==========================================
|
| 88 |
html_code = f"""
|
| 89 |
<!DOCTYPE html>
|
|
@@ -102,43 +97,33 @@ html_code = f"""
|
|
| 102 |
body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }}
|
| 103 |
.page {{ position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }}
|
| 104 |
#main-page {{ background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.95)), url('https://images.unsplash.com/photo-1516981879613-9f5da904015f?q=80&w=2560&auto=format&fit=crop'); background-size: cover; background-position: center; z-index: 100; align-items: center; justify-content: flex-start; padding-top: 20px; }}
|
| 105 |
-
|
| 106 |
.bartender-btn {{ position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('data:image/jpeg;base64,{emily_base64}'); background-size: cover; background-position: center; background-color: #222; border: 3px solid var(--gold); box-shadow: 0 8px 30px rgba(212, 175, 55, 0.6); cursor: pointer; z-index: 999; animation: bounce-float 3s ease-in-out infinite; }}
|
| 107 |
@keyframes bounce-float {{ 0%, 100% {{ transform: translateY(0); }} 50% {{ transform: translateY(-15px); }} }}
|
| 108 |
-
|
| 109 |
.lang-switcher {{ position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }}
|
| 110 |
.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; }}
|
| 111 |
.lang-btn.active {{ background: var(--gold); color: black; border-color: var(--gold); font-weight: bold; }}
|
| 112 |
-
|
| 113 |
.brand-title {{ font-size: 26px; font-weight: 900; color: var(--gold); letter-spacing: 4px; margin-top: 10px; text-transform: uppercase; }}
|
| 114 |
.brand-subtitle {{ font-size: 11px; color: #ccc; letter-spacing: 2px; margin-bottom: 15px; }}
|
| 115 |
-
|
| 116 |
.world-map-btn {{ background: rgba(212, 175, 55, 0.2); border: 1px solid var(--gold); color: var(--gold); padding: 12px 25px; border-radius: 30px; font-weight: bold; cursor: pointer; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; backdrop-filter: blur(5px); }}
|
| 117 |
.passport-btn {{ background: rgba(0,0,0,0.6); border: 1px solid var(--gold); color: var(--gold); padding: 8px 15px; border-radius: 20px; font-size: 12px; cursor: pointer; margin-top: 10px; display: flex; align-items: center; gap: 5px; }}
|
| 118 |
-
|
| 119 |
.country-select-wrapper {{ width: 85%; max-width: 400px; margin-bottom: 15px; }}
|
| 120 |
.country-select {{ width: 100%; padding: 14px; background: rgba(30,30,30,0.9); border: 1px solid var(--gold); color: white; font-size: 16px; border-radius: 10px; outline: none; }}
|
| 121 |
-
|
| 122 |
.type-filter-container {{ width: 100%; padding: 10px 20px; overflow-x: auto; display: flex; gap: 8px; scrollbar-width: none; }}
|
| 123 |
.type-btn {{ padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: bold; cursor: pointer; background: #222; color: #888; border: 1px solid #444; white-space: nowrap; }}
|
| 124 |
.type-btn.selected {{ background: var(--gold); color: black; border-color: var(--gold); }}
|
| 125 |
-
|
| 126 |
.place-list-container {{ width: 100%; max-width: 600px; flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; box-sizing: border-box; }}
|
| 127 |
.place-card {{ background: rgba(30,30,30,0.6); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.1); border-radius: 15px; padding: 18px; margin-bottom: 15px; position: relative; transition: all 0.3s ease; }}
|
| 128 |
.place-card.visited {{ background: linear-gradient(135deg, rgba(40,10,10,0.9), rgba(20,20,20,0.9)); border: 1px solid var(--gold); box-shadow: 0 0 15px rgba(212, 175, 55, 0.2); }}
|
| 129 |
.visited-badge {{ position: absolute; top: 10px; right: 10px; background: var(--gold); color: black; font-size: 10px; font-weight: bold; padding: 3px 8px; border-radius: 10px; display: none; }}
|
| 130 |
.place-card.visited .visited-badge {{ display: block; }}
|
| 131 |
-
|
| 132 |
.pc-name {{ font-size: 18px; font-weight: bold; color: white; }}
|
| 133 |
.place-card.visited .pc-name {{ color: var(--gold); }}
|
| 134 |
.pc-cat {{ font-size: 11px; color: var(--gold); font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }}
|
| 135 |
.pc-desc {{ font-size: 13px; color: #bbb; line-height: 1.5; margin-top: 5px; }}
|
| 136 |
-
|
| 137 |
.card-actions {{ display: flex; gap: 10px; margin-top: 15px; }}
|
| 138 |
.btn-action {{ flex: 1; padding: 12px; border-radius: 8px; font-size: 12px; font-weight: bold; border: none; cursor: pointer; }}
|
| 139 |
.btn-ai {{ background: var(--gold); color: black; }}
|
| 140 |
.btn-map {{ background: #333; color: white; border: 1px solid #555; }}
|
| 141 |
-
|
| 142 |
#chat-page {{ background: var(--dark); z-index: 1000; transform: translateY(100%); display: flex; flex-direction: column; }}
|
| 143 |
#chat-messages {{ flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }}
|
| 144 |
.msg {{ max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; position: relative; }}
|
|
@@ -147,13 +132,11 @@ html_code = f"""
|
|
| 147 |
.reco-btn {{ display: inline-block; margin-top: 10px; padding: 12px 20px; background: var(--gold); color: black !important; border-radius: 20px; font-weight: 900; text-decoration: none; font-size: 13px; text-align: center; border: none; cursor: pointer; }}
|
| 148 |
.chat-input-area {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; }}
|
| 149 |
.chat-input {{ flex: 1; background: #222; border: 1px solid #444; color: white; padding: 14px; border-radius: 10px; outline: none; }}
|
| 150 |
-
|
| 151 |
#detail-page {{ background: #111; z-index: 300; transform: translateX(100%); display: flex; flex-direction: column; }}
|
| 152 |
.nav-bar {{ height: 60px; background: rgba(0,0,0,0.9); border-bottom: 1px solid #333; display: flex; align-items: center; padding: 0 20px; justify-content: space-between; }}
|
| 153 |
#mini-map {{ width: 100%; height: 35%; border-bottom: 2px solid var(--gold); }}
|
| 154 |
.stamp-btn {{ width: 100%; background: #4a1c1c; color: #ffcc00; border: 2px dashed #ffcc00; padding: 15px; margin-top: 20px; border-radius: 10px; font-weight: bold; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; }}
|
| 155 |
.stamp-btn:hover {{ background: #ffcc00; color: #4a1c1c; border-style: solid; }}
|
| 156 |
-
|
| 157 |
#passport-page {{ background: #1a1a1a; z-index: 400; transform: translateY(100%); display: flex; flex-direction: column; }}
|
| 158 |
.passport-cover {{ padding: 20px; border-bottom: 1px solid #333; display: flex; justify-content: space-between; align-items: center; background: #2c0b0e; }}
|
| 159 |
.passport-grid {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px; padding: 25px; overflow-y: auto; flex: 1; background-image: radial-gradient(#333 15%, transparent 16%), radial-gradient(#333 15%, transparent 16%); background-size: 20px 20px; }}
|
|
@@ -164,7 +147,6 @@ html_code = f"""
|
|
| 164 |
.stamp-date {{ font-size: 10px; font-family: monospace; }}
|
| 165 |
.data-controls {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; justify-content: center; }}
|
| 166 |
.data-btn {{ background: #333; border: 1px solid #555; color: #ccc; padding: 10px 15px; border-radius: 5px; cursor: pointer; font-size: 12px; }}
|
| 167 |
-
|
| 168 |
#world-map-page {{ background: #111; z-index: 200; transform: translateY(100%); }}
|
| 169 |
#full-map {{ width: 100%; height: 100%; }}
|
| 170 |
.map-search-bar {{ position: absolute; top: 80px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; gap: 10px; background: rgba(0,0,0,0.85); padding: 10px 20px; border-radius: 30px; border: 1px solid var(--gold); box-shadow: 0 4px 15px rgba(0,0,0,0.5); }}
|
|
@@ -258,11 +240,11 @@ html_code = f"""
|
|
| 258 |
let miniMap = null, worldMap = null, worldMarkers = L.layerGroup();
|
| 259 |
let chatHistory = [];
|
| 260 |
let currentDetailPlace = null;
|
|
|
|
| 261 |
|
| 262 |
-
// [ํต์ฌ ๋ณ๊ฒฝ
|
| 263 |
-
// HTML์ ๋ฐ์ดํฐ๋ฅผ ์ง์ ๋ฃ์ง ์๊ณ , ์ด๊ณณ์ ์ ์ฅ ํ "๋ฒํธํ(Key)"๋ก๋ง ๋ถ๋ฌ์ต๋๋ค.
|
| 264 |
-
let LIST_CACHE = [];
|
| 265 |
let MAP_CACHE = {{}};
|
|
|
|
| 266 |
|
| 267 |
const TRANSLATIONS = {{
|
| 268 |
"KO": {{ "sub": "๊ธ๋ก๋ฒ ์ฃผ๋ฅ ํค๋ฆฌํฐ์ง ํฌ์ด", "ai": "Korean", "mapBtn": "๐บ๏ธ ์๋๋งต ํํ", "passBtn": "๐ ๋ด ์ฌ๊ถ", "filters": ["๐ ์ ์ฒด", "๐บ ์ ํต์ฃผ", "๐ฅ ์์คํค", "๐บ ๋งฅ์ฃผ", "๐ท ์์ธ", "๐น ๋ฐ"], "chatPlace": "์๋ฐ๋ฆฌ์๊ฒ ๋งํด๋ด, ์๊ธฐ์ผ...", "send": "์ ์ก", "home": "๐ ํ", "searchPlace": "์ฅ์ ๊ฒ์ (์: ๊ฐ๋จ)", "emilyName": "์๋ฐ๋ฆฌ (Emily)", "reportHeader": "๋ฆฌํฌํธ", "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapLinkBtn": "์ง๋" }},
|
|
@@ -293,9 +275,15 @@ html_code = f"""
|
|
| 293 |
document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
|
| 294 |
el.classList.add('active');
|
| 295 |
const t = TRANSLATIONS[currentLang];
|
| 296 |
-
document.getElementById('app-subtitle').innerText = t.sub;
|
| 297 |
-
document.getElementById('
|
| 298 |
-
document.getElementById('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
for(let i=0; i<6; i++) {{ document.getElementById('f-btn-' + i).innerText = t.filters[i]; }}
|
| 300 |
renderList();
|
| 301 |
}}
|
|
@@ -308,52 +296,38 @@ html_code = f"""
|
|
| 308 |
else {{ return "https://www.google.com/maps/search/" + encodeURIComponent(name) + "/@" + lat + "," + lon + ",18z"; }}
|
| 309 |
}}
|
| 310 |
|
| 311 |
-
|
|
|
|
| 312 |
function renderList() {{
|
| 313 |
const list = document.getElementById('place-list'); list.innerHTML = "";
|
| 314 |
const stamps = getStamps();
|
| 315 |
const visitedSet = new Set(stamps.map(s => s ? s.name + '|' + s.country : ''));
|
| 316 |
-
|
| 317 |
const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
|
| 318 |
-
|
| 319 |
-
|
| 320 |
const t = TRANSLATIONS[currentLang];
|
| 321 |
|
| 322 |
filtered.forEach((p, idx) => {{
|
| 323 |
-
const card = document.createElement('div');
|
| 324 |
const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
|
| 325 |
card.className = isVisited ? 'place-card visited' : 'place-card';
|
| 326 |
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.";
|
| 327 |
|
| 328 |
// HTML ํ์์ฉ (๋ฐ์ดํ ์ ๊ฑฐ)
|
| 329 |
-
const
|
| 330 |
-
const
|
| 331 |
-
|
|
|
|
| 332 |
let catIdx = CAT_MAP[p.category] || 0;
|
| 333 |
let translatedCat = t.filters[catIdx] || p.category;
|
| 334 |
|
| 335 |
-
// onclick์๋ ์ค์ง
|
| 336 |
-
card.innerHTML = "<div class='visited-badge'>VISITED ๐ฎ</div><b>" +
|
| 337 |
-
"<div class='card-actions'><button class='btn-action btn-ai' onclick='
|
| 338 |
-
"<button class='btn-action btn-map' onclick='
|
| 339 |
list.appendChild(card);
|
| 340 |
}});
|
| 341 |
}}
|
| 342 |
|
| 343 |
-
// [ํต์ฌ ๋ณ๊ฒฝ 3] ๋ฆฌ์คํธ ํด๋ฆญ ํธ๋ค๋ฌ (์ธ๋ฑ์ค๋ก ๋ฐ์ดํฐ ์ฐพ๊ธฐ)
|
| 344 |
-
function clickListDetail(idx) {{
|
| 345 |
-
const p = LIST_CACHE[idx];
|
| 346 |
-
if(p) openDetail(p.name, selectedCountry);
|
| 347 |
-
}}
|
| 348 |
-
|
| 349 |
-
function clickListMap(idx) {{
|
| 350 |
-
const p = LIST_CACHE[idx];
|
| 351 |
-
if(p) {{
|
| 352 |
-
const url = getMapUrl(p.name, selectedCountry, p.lat, p.lon, p.address || "");
|
| 353 |
-
window.open(url, '_blank');
|
| 354 |
-
}}
|
| 355 |
-
}}
|
| 356 |
-
|
| 357 |
function getStamps() {{
|
| 358 |
try {{ return JSON.parse(localStorage.getItem('drunk_passport') || '[]'); }}
|
| 359 |
catch(e) {{ localStorage.setItem('drunk_passport', '[]'); return []; }}
|
|
@@ -446,26 +420,27 @@ html_code = f"""
|
|
| 446 |
|
| 447 |
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; }}
|
| 448 |
|
| 449 |
-
// [ํต์ฌ ๋ณ๊ฒฝ 4] ์๋๋งต ํ์
|
| 450 |
function openWorldMapPage() {{
|
| 451 |
document.getElementById('world-map-page').style.transform = 'translateY(0%)';
|
| 452 |
if(!worldMap) {{
|
| 453 |
worldMap = L.map('full-map').setView([20, 0], 2); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
|
| 454 |
-
MAP_CACHE = {{}};
|
|
|
|
| 455 |
|
| 456 |
Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
|
| 457 |
if(p.lat && p.lon) {{
|
| 458 |
-
//
|
| 459 |
-
const
|
| 460 |
-
MAP_CACHE[
|
| 461 |
|
| 462 |
const safeName = String(p.name).replace(/['"]/g, "");
|
| 463 |
|
| 464 |
-
// onclick์๋ ์ค์ง
|
| 465 |
const popupContent = "<div style='text-align:center'><b>" + safeName + "</b><br>" +
|
| 466 |
"<div style='display:flex; gap:5px; margin-top:5px; justify-content:center;'>" +
|
| 467 |
-
"<button onclick=
|
| 468 |
-
"<button onclick=
|
| 469 |
"</div></div>";
|
| 470 |
L.marker([p.lat, p.lon]).bindPopup(popupContent).addTo(worldMap);
|
| 471 |
}}
|
|
@@ -474,14 +449,14 @@ html_code = f"""
|
|
| 474 |
setTimeout(() => worldMap.invalidateSize(), 400);
|
| 475 |
}}
|
| 476 |
|
| 477 |
-
// ๋งต ํด๋ฆญ ํธ๋ค๋ฌ (
|
| 478 |
-
function clickMapDetail(
|
| 479 |
-
const data = MAP_CACHE[
|
| 480 |
if(data) {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
|
| 481 |
}}
|
| 482 |
|
| 483 |
-
function clickMapLink(
|
| 484 |
-
const data = MAP_CACHE[
|
| 485 |
if(data) window.open(data.url, '_blank');
|
| 486 |
}}
|
| 487 |
|
|
@@ -495,7 +470,8 @@ html_code = f"""
|
|
| 495 |
function flyToUserLocation() {{ if(userLat && userLon) {{ worldMap.flyTo([userLat, userLon], 13); L.marker([userLat, userLon]).addTo(worldMap).bindPopup("๐ You").openPopup(); }} else alert("GPS..."); }}
|
| 496 |
function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
|
| 497 |
|
| 498 |
-
function
|
|
|
|
| 499 |
async function openDetail(n, c) {{
|
| 500 |
const p = (PLACE_DB[c] || []).find(x => x.name === n); if(!p) return;
|
| 501 |
currentDetailPlace = {{ name: n, country: c }};
|
|
@@ -508,6 +484,8 @@ html_code = f"""
|
|
| 508 |
}}
|
| 509 |
|
| 510 |
function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
|
|
|
|
|
|
|
| 511 |
function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
|
| 512 |
</script>
|
| 513 |
</body>
|
|
|
|
| 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")
|
|
|
|
| 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)
|
| 37 |
response.raise_for_status()
|
| 38 |
|
|
|
|
| 39 |
try:
|
| 40 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 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'}
|
| 50 |
df.rename(columns=col_mapping, inplace=True)
|
| 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:
|
|
|
|
| 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>
|
|
|
|
| 97 |
body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }}
|
| 98 |
.page {{ position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }}
|
| 99 |
#main-page {{ background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.95)), url('https://images.unsplash.com/photo-1516981879613-9f5da904015f?q=80&w=2560&auto=format&fit=crop'); background-size: cover; background-position: center; z-index: 100; align-items: center; justify-content: flex-start; padding-top: 20px; }}
|
|
|
|
| 100 |
.bartender-btn {{ position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('data:image/jpeg;base64,{emily_base64}'); background-size: cover; background-position: center; background-color: #222; border: 3px solid var(--gold); box-shadow: 0 8px 30px rgba(212, 175, 55, 0.6); cursor: pointer; z-index: 999; animation: bounce-float 3s ease-in-out infinite; }}
|
| 101 |
@keyframes bounce-float {{ 0%, 100% {{ transform: translateY(0); }} 50% {{ transform: translateY(-15px); }} }}
|
|
|
|
| 102 |
.lang-switcher {{ position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }}
|
| 103 |
.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; }}
|
| 104 |
.lang-btn.active {{ background: var(--gold); color: black; border-color: var(--gold); font-weight: bold; }}
|
|
|
|
| 105 |
.brand-title {{ font-size: 26px; font-weight: 900; color: var(--gold); letter-spacing: 4px; margin-top: 10px; text-transform: uppercase; }}
|
| 106 |
.brand-subtitle {{ font-size: 11px; color: #ccc; letter-spacing: 2px; margin-bottom: 15px; }}
|
|
|
|
| 107 |
.world-map-btn {{ background: rgba(212, 175, 55, 0.2); border: 1px solid var(--gold); color: var(--gold); padding: 12px 25px; border-radius: 30px; font-weight: bold; cursor: pointer; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; backdrop-filter: blur(5px); }}
|
| 108 |
.passport-btn {{ background: rgba(0,0,0,0.6); border: 1px solid var(--gold); color: var(--gold); padding: 8px 15px; border-radius: 20px; font-size: 12px; cursor: pointer; margin-top: 10px; display: flex; align-items: center; gap: 5px; }}
|
|
|
|
| 109 |
.country-select-wrapper {{ width: 85%; max-width: 400px; margin-bottom: 15px; }}
|
| 110 |
.country-select {{ width: 100%; padding: 14px; background: rgba(30,30,30,0.9); border: 1px solid var(--gold); color: white; font-size: 16px; border-radius: 10px; outline: none; }}
|
|
|
|
| 111 |
.type-filter-container {{ width: 100%; padding: 10px 20px; overflow-x: auto; display: flex; gap: 8px; scrollbar-width: none; }}
|
| 112 |
.type-btn {{ padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: bold; cursor: pointer; background: #222; color: #888; border: 1px solid #444; white-space: nowrap; }}
|
| 113 |
.type-btn.selected {{ background: var(--gold); color: black; border-color: var(--gold); }}
|
|
|
|
| 114 |
.place-list-container {{ width: 100%; max-width: 600px; flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; box-sizing: border-box; }}
|
| 115 |
.place-card {{ background: rgba(30,30,30,0.6); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.1); border-radius: 15px; padding: 18px; margin-bottom: 15px; position: relative; transition: all 0.3s ease; }}
|
| 116 |
.place-card.visited {{ background: linear-gradient(135deg, rgba(40,10,10,0.9), rgba(20,20,20,0.9)); border: 1px solid var(--gold); box-shadow: 0 0 15px rgba(212, 175, 55, 0.2); }}
|
| 117 |
.visited-badge {{ position: absolute; top: 10px; right: 10px; background: var(--gold); color: black; font-size: 10px; font-weight: bold; padding: 3px 8px; border-radius: 10px; display: none; }}
|
| 118 |
.place-card.visited .visited-badge {{ display: block; }}
|
|
|
|
| 119 |
.pc-name {{ font-size: 18px; font-weight: bold; color: white; }}
|
| 120 |
.place-card.visited .pc-name {{ color: var(--gold); }}
|
| 121 |
.pc-cat {{ font-size: 11px; color: var(--gold); font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }}
|
| 122 |
.pc-desc {{ font-size: 13px; color: #bbb; line-height: 1.5; margin-top: 5px; }}
|
|
|
|
| 123 |
.card-actions {{ display: flex; gap: 10px; margin-top: 15px; }}
|
| 124 |
.btn-action {{ flex: 1; padding: 12px; border-radius: 8px; font-size: 12px; font-weight: bold; border: none; cursor: pointer; }}
|
| 125 |
.btn-ai {{ background: var(--gold); color: black; }}
|
| 126 |
.btn-map {{ background: #333; color: white; border: 1px solid #555; }}
|
|
|
|
| 127 |
#chat-page {{ background: var(--dark); z-index: 1000; transform: translateY(100%); display: flex; flex-direction: column; }}
|
| 128 |
#chat-messages {{ flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }}
|
| 129 |
.msg {{ max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; position: relative; }}
|
|
|
|
| 132 |
.reco-btn {{ display: inline-block; margin-top: 10px; padding: 12px 20px; background: var(--gold); color: black !important; border-radius: 20px; font-weight: 900; text-decoration: none; font-size: 13px; text-align: center; border: none; cursor: pointer; }}
|
| 133 |
.chat-input-area {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; }}
|
| 134 |
.chat-input {{ flex: 1; background: #222; border: 1px solid #444; color: white; padding: 14px; border-radius: 10px; outline: none; }}
|
|
|
|
| 135 |
#detail-page {{ background: #111; z-index: 300; transform: translateX(100%); display: flex; flex-direction: column; }}
|
| 136 |
.nav-bar {{ height: 60px; background: rgba(0,0,0,0.9); border-bottom: 1px solid #333; display: flex; align-items: center; padding: 0 20px; justify-content: space-between; }}
|
| 137 |
#mini-map {{ width: 100%; height: 35%; border-bottom: 2px solid var(--gold); }}
|
| 138 |
.stamp-btn {{ width: 100%; background: #4a1c1c; color: #ffcc00; border: 2px dashed #ffcc00; padding: 15px; margin-top: 20px; border-radius: 10px; font-weight: bold; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; }}
|
| 139 |
.stamp-btn:hover {{ background: #ffcc00; color: #4a1c1c; border-style: solid; }}
|
|
|
|
| 140 |
#passport-page {{ background: #1a1a1a; z-index: 400; transform: translateY(100%); display: flex; flex-direction: column; }}
|
| 141 |
.passport-cover {{ padding: 20px; border-bottom: 1px solid #333; display: flex; justify-content: space-between; align-items: center; background: #2c0b0e; }}
|
| 142 |
.passport-grid {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px; padding: 25px; overflow-y: auto; flex: 1; background-image: radial-gradient(#333 15%, transparent 16%), radial-gradient(#333 15%, transparent 16%); background-size: 20px 20px; }}
|
|
|
|
| 147 |
.stamp-date {{ font-size: 10px; font-family: monospace; }}
|
| 148 |
.data-controls {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; justify-content: center; }}
|
| 149 |
.data-btn {{ background: #333; border: 1px solid #555; color: #ccc; padding: 10px 15px; border-radius: 5px; cursor: pointer; font-size: 12px; }}
|
|
|
|
| 150 |
#world-map-page {{ background: #111; z-index: 200; transform: translateY(100%); }}
|
| 151 |
#full-map {{ width: 100%; height: 100%; }}
|
| 152 |
.map-search-bar {{ position: absolute; top: 80px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; gap: 10px; background: rgba(0,0,0,0.85); padding: 10px 20px; border-radius: 30px; border: 1px solid var(--gold); box-shadow: 0 4px 15px rgba(0,0,0,0.5); }}
|
|
|
|
| 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": "์ง๋" }},
|
|
|
|
| 275 |
document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
|
| 276 |
el.classList.add('active');
|
| 277 |
const t = TRANSLATIONS[currentLang];
|
| 278 |
+
document.getElementById('app-subtitle').innerText = t.sub;
|
| 279 |
+
document.getElementById('world-map-btn').innerText = t.mapBtn;
|
| 280 |
+
document.getElementById('passport-btn').innerText = t.passBtn;
|
| 281 |
+
document.getElementById('chat-input').placeholder = t.chatPlace;
|
| 282 |
+
document.getElementById('chat-send-btn').innerText = t.send;
|
| 283 |
+
document.getElementById('nav-home-btn').innerText = t.home;
|
| 284 |
+
document.getElementById('map-search-input').placeholder = t.searchPlace;
|
| 285 |
+
document.getElementById('emily-name').innerText = t.emilyName;
|
| 286 |
+
document.getElementById('repo-header').innerText = t.reportHeader;
|
| 287 |
for(let i=0; i<6; i++) {{ document.getElementById('f-btn-' + i).innerText = t.filters[i]; }}
|
| 288 |
renderList();
|
| 289 |
}}
|
|
|
|
| 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 []; }}
|
|
|
|
| 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 |
}}
|
|
|
|
| 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 |
|
|
|
|
| 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 }};
|
|
|
|
| 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>
|