Spaces:
Sleeping
Sleeping
Update app.py
Browse files57 unmodified lines5859606162636465663 unmodified lines7071727374757628 unmodified lines1051061071081091101111121131141151161171181191201211221231241251261 unmodified line1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561575 unmodified lines1631641651661671681691701711721731741751761771789 unmodified lines18818919019119219319419519619719819912 unmodified lines2122132142152162172182196 unmodified lines22622722822923023123227 unmodified lines26026126226326426526626726826917 unmodified lines28728828929029129229324 unmodified lines31831932032132232332457 unmodified linesdb_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')# ==========================================# 3. ํตํฉ ํ๋ก ํธ์๋ (String Replacement ๋ฐฉ์ - ์๋ฌ ๋ฐฉ์ง)# ==========================================# f-string์ ์ฐ์ง ์๊ณ ์ผ๋ฐ ๋ฐ์ดํ๋ฅผ ์ฌ์ฉํ์ฌ ์๋ฐ์คํฌ๋ฆฝํธ ์ค๊ดํธ ๋ณด์กดhtml_template = """<!DOCTYPE html><html>3 unmodified lines<title>Drunken Plane</title><link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" /><script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script><link href="https://fonts.googleapis.com/css2?family=Special+Elite&display=swap" rel="stylesheet"><style>:root { --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }28 unmodified lines.msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }.msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }.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; }.lang-switcher { position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }.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; }.lang-btn.active { background: var(--gold); color: black; border-color: var(--gold); font-weight: bold; }</style></head><body><div id="main-page" class="page"><div class="lang-switcher"><div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">๐ฐ๐ท</div><div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">๐บ๐ธ</div><div class="lang-btn" id="btn-JP" onclick="setLanguage('JP', this)">๐ฏ๐ต</div><div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">๐จ๐ณ</div></div><div style="text-align:center; padding: 25px 0;"><div style="color:var(--gold); font-size: 28px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div><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></div><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><div class="place-list-container" id="place-list"></div>1 unmodified line</div><div id="world-map-page" class="page"><div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold); font-size:18px; cursor:pointer;">๐ HOME</button></div><button class="map-gps-btn" onclick="flyToUser()">๐ฏ</button><div id="full-map" style="width:100%; height:100%;"></div></div><div id="chat-page" class="page"><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><div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column;"></div><div style="padding:15px; display:flex; gap:10px; background:#111;"><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()"><button onclick="sendChat()" style="padding:10px 20px; background:var(--gold); border:none; border-radius:10px; font-weight:bold; cursor:pointer;">SEND</button></div></div><div id="detail-page" class="page"><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><div id="mini-map" style="width:100%; height:260px; border-bottom:1px solid var(--gold);"></div><div style="flex:1; overflow-y:auto; padding:25px;"><div id="repo-title" style="font-size:24px; color:var(--gold); font-weight:bold; margin-bottom:10px;"></div><div id="repo-content" style="line-height:1.8; color:#ddd; white-space:pre-wrap; font-size:15px;"></div></div></div><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><script>function b64DecodeUnicode(str) {5 unmodified linesconst PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));let userLat = null, userLon = null, worldMap = null, miniMap = null;let chatHistory = [];let currentLang = "KO";let selectedCountry = "";const TRANSLATIONS = {"KO": { "ai": "Korean", "greet": "์๋ , ์๊ธฐ? ์ค๋ ์ ๋ง ๊ณ ์ ๋ง์์ด. ์๋ฐ๋ฆฌํํ ๋ญ๋ ๋ฌผ์ด๋ด~" },"EN": { "ai": "English", "greet": "Hey darling, rough day? Let Emily find you a perfect spot to drink." },"JP": { "ai": "Japanese", "greet": "ใใใใใใผใไปๆฅใฏใ็ฒใๆง. ์๋ฐ๋ฆฌใซใชใใงใ่ใใฆ๏ผ" },"CN": { "ai": "Chinese", "greet": "ไบฒ็ฑ็๏ผไปๅคฉ่พ่ฆไบ. ๆณๅ็นไปไน๏ผ" }};window.onload = function() {const keys = Object.keys(PLACE_DB).sort();const select = document.getElementById('country-select');9 unmodified lines};function selectCountry(c) { selectedCountry = c; renderList(); }function setLanguage(l, el) {currentLang = l;document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));el.classList.add('active');renderList();}function getMapUrl(p, country) {if (country.includes("Korea") || country.includes("ํ๊ตญ")) {12 unmodified linesconst p = countryPlaces[i];const card = document.createElement('div');card.className = 'place-card';const descKey = 'desc_' + currentLang.toLowerCase();let desc = p[descKey] || p.desc_en || p.desc_ko || "Exploring heritage...";const mapUrl = getMapUrl(p, selectedCountry);card.innerHTML = `<div class="pc-name">${p.name}</div><div class="pc-desc">${desc}</div><div style="margin-top:15px; display:flex; gap:10px;">6 unmodified linesfunction openChat() {document.getElementById('chat-page').style.transform = 'translateY(0%)';if(chatHistory.length === 0) {addChatMessage(TRANSLATIONS[currentLang].greet, "bot");chatHistory.push({ role: "system", content: "You are Emily, a bartender. If recommending, use [Place Name]." });}}27 unmodified linesdocument.getElementById('loader').style.display = 'flex';if(!miniMap) {miniMap = L.map('mini-map');L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(miniMap);}setTimeout(() => { miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }, 400);const prompt = [{ role: "system", content: "Act as Emily. Write review in " + TRANSLATIONS[currentLang].ai }, { role: "user", content: "Review " + name }];const res = await callGroq(prompt);document.getElementById('repo-content').innerText = res;document.getElementById('loader').style.display = 'none';17 unmodified linesL.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(worldMap);for(let c in PLACE_DB) {PLACE_DB[c].forEach(p => {if(p.lat && p.lon) L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup(`<b>${p.name}</b>`);});}}24 unmodified lines</html>"""# ํ์ด์ฌ ๋ณ์ ์ฃผ์ (f-string ์๋ฌ ์์ฒ ์ฐจ๋จ)html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")html_code = html_code.replace("DB_DATA_BASE64", db_base64)html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)57 unmodified lines58596061626364653 unmodified lines69707172737428 unmodified lines1031041051061071081091101111121131141151161171181191201 unmodified line1221231241251261271281291301311321331341351361371381391401411421431441451461471481491505 unmodified lines1561571581591601611621639 unmodified lines17317417517617717812 unmodified lines1911921931941951961976 unmodified lines20420520620720820921027 unmodified lines23823924024124224324424524624717 unmodified lines26526626726826927027127227327427527627727827928028128224 unmodified lines30730830931031131231357 unmodified linesdb_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')# ==========================================# 3. ํตํฉ ํ๋ก ํธ์๋ (Popup ๋ณต๊ตฌ ๋ฒ์ )# ==========================================html_template = """<!DOCTYPE html><html>3 unmodified lines<title>Drunken Plane</title><link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" /><script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script><style>:root { --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }28 unmodified lines.msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }.msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }.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; }/* ํ์ ์คํ์ผ๋ง */.leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); border-radius: 10px; }.leaflet-popup-tip { background: var(--gold); }.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; }</style></head><body><div id="main-page" class="page"><div style="text-align:center; padding: 25px 0;"><div style="color:var(--gold); font-size: 28px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div><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></div><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><div class="place-list-container" id="place-list"></div>1 unmodified line</div><div id="world-map-page" class="page"><div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold); font-size:18px;">๐ HOME</button></div><button class="map-gps-btn" onclick="flyToUser()">๐ฏ</button><div id="full-map" style="width:100%; height:100%;"></div></div><div id="chat-page" class="page"><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><div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column;"></div><div style="padding:15px; display:flex; gap:10px; background:#111;"><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></div></div><div id="detail-page" class="page"><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><div id="mini-map" style="width:100%; height:250px;"></div><div style="flex:1; overflow-y:auto; padding:20px;"><div id="repo-title" style="font-size:22px; color:var(--gold); font-weight:bold;"></div><div id="repo-content" style="margin-top:15px; line-height:1.7; color:#ddd; white-space:pre-wrap; font-size:14px;"></div></div></div><div id="loader" class="loading-screen"><div class="loader-ring"></div></div><script>function b64DecodeUnicode(str) {5 unmodified linesconst PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));let userLat = null, userLon = null, worldMap = null, miniMap = null;let chatHistory = [];let selectedCountry = "";window.onload = function() {const keys = Object.keys(PLACE_DB).sort();const select = document.getElementById('country-select');9 unmodified lines};function selectCountry(c) { selectedCountry = c; renderList(); }function getMapUrl(p, country) {if (country.includes("Korea") || country.includes("ํ๊ตญ")) {12 unmodified linesconst p = countryPlaces[i];const card = document.createElement('div');card.className = 'place-card';let desc = p.desc_en || p.desc_ko || "Exploring heritage...";const mapUrl = getMapUrl(p, selectedCountry);card.innerHTML = `<div class="pc-name">${p.name}</div><div class="pc-desc">${desc}</div><div style="margin-top:15px; display:flex; gap:10px;">6 unmodified linesfunction openChat() {document.getElementById('chat-page').style.transform = 'translateY(0%)';if(chatHistory.length === 0) {addChatMessage("Hey darling, what's your mood for a drink?", "bot");chatHistory.push({ role: "system", content: "You are Emily, a bartender. If recommending, use [Place Name]." });}}27 unmodified linesdocument.getElementById('loader').style.display = 'flex';if(!miniMap) {miniMap = L.map('mini-map');L.tileLayer('https://{s}.tile.openstreetmap.org/etc/').addTo(miniMap);}setTimeout(() => { miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }, 400);const prompt = [{ role: "system", content: "Act as Emily. Detailed review." }, { role: "user", content: "Review " + name }];const res = await callGroq(prompt);document.getElementById('repo-content').innerText = res;document.getElementById('loader').style.display = 'none';17 unmodified linesL.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(worldMap);for(let c in PLACE_DB) {PLACE_DB[c].forEach(p => {if(p.lat && p.lon) {const mapUrl = getMapUrl(p, c);// [์์ ] ํ์ ๋ด์ฉ ๋ณต๊ตฌ: ์ด๋ฆ + ์นดํ ๊ณ ๋ฆฌ + ๋ฆฌ๋ทฐ ๋ฒํผ + ๋งต ์ด๋ ๋ฒํผconst popupHtml = `<div style="text-align:center;"><b style="color:var(--gold);">${p.name}</b><br><small style="color:#aaa;">${p.category || ""}</small><br><button class="popup-btn" onclick="closeMap(); openReview('${p.name}', '${c}')">๐ค REVIEW</button><button class="popup-btn" style="background:#333; color:white; border:1px solid #555;" onclick="window.open('${mapUrl}', '_blank')">๐ MAP</button></div>`;L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup(popupHtml);}});}}24 unmodified lines</html>"""# ํ์ด์ฌ ๋ณ์ ์ฃผ์ (replace ๋ฐฉ์์ผ๋ก ์ค๊ดํธ ์๋ฌ ๋ฐฉ์ง)html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")html_code = html_code.replace("DB_DATA_BASE64", db_base64)html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)
app.py+33-44