Spaces:
Sleeping
Sleeping
Update app.py
Browse files7 unmodified lines8910111213149 unmodified lines242526272829303 unmodified lines34353637383918 unmodified lines58596061626364110 unmodified lines17517617717817918018118218318418518618718818912 unmodified lines20220320420520620720820921021121221321421521621721821922017 unmodified lines2382392402412422432446 unmodified lines2512522532542552562571 unmodified line25926026126226326426523 unmodified lines2892902912922932942952962972982993003013023033043053063073083093103113123133143153167 unmodified linesimport io# ==========================================# ๐ 1. ์ํฌ๋ฆฟ ๋ก๋# ==========================================GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")9 unmodified lines""", unsafe_allow_html=True)# ==========================================# 2. ๋ฐ์ดํฐ ๋ก๋ (Google Sheet ์ฐ๋)# ==========================================PLACE_DB = {}try:3 unmodified linesresponse.raise_for_status()df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')for col in df.select_dtypes(include=['object']).columns:df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")18 unmodified linesdb_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')# ==========================================# 3. ํตํฉ ํ๋ก ํธ์๋ (์ค๊ดํธ ์๋ฒฝ ์ด์ค์ผ์ดํ)# ==========================================html_code = f"""<!DOCTYPE html>110 unmodified lineswindow.onload = function() {{const keys = Object.keys(PLACE_DB).sort();const select = document.getElementById('country-select');keys.forEach(k => {{ const opt = document.createElement('option'); opt.value = k; opt.text = k; select.appendChild(opt); }});if(keys.length > 0) selectCountry(keys[0]);navigator.geolocation.getCurrentPosition(p => {{ userLat = p.coords.latitude; userLon = p.coords.longitude; }});}};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();}}12 unmodified lineslist.innerHTML = "";const countryPlaces = PLACE_DB[selectedCountry] || [];countryPlaces.forEach(p => {{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 the taste of 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;"><button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${{p.name.replace(/'/g, "\\\\'")}}', '${{selectedCountry.replace(/'/g, "\\\\'")}}')">AI REVIEW</button><button class="btn-action" style="background:#333; color:white; border:1px solid #555;" onclick="window.open('${{mapUrl}}', '_blank')">MAP</button></div>`;list.appendChild(card);}});}}17 unmodified linesconst match = res.match(/\\[(.*?)\\]/);if(match) {{const pName = match[1];botMsgDiv.innerHTML += `<br><button class="reco-btn" onclick="searchAndOpenMap('${{pName.replace(/'/g, "\\\\'")}}')">๐ View on Map</button>`;}}chatHistory.push({{ role: "assistant", content: res }});}}6 unmodified lines}}async function openReview(name, country) {{const p = PLACE_DB[country].find(x => x.name === name); if(!p) return;document.getElementById('repo-title').innerText = name;document.getElementById('detail-page').style.transform = 'translateX(0%)';document.getElementById('loader').style.display = 'flex';1 unmodified lineminiMap = 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 + ". Sections: Vibe, Must Try, Secret Tip." }},{{ role: "user", content: "Write review for " + name + " in " + country }}23 unmodified linesif(!worldMap) {{worldMap = L.map('full-map').setView([20, 0], 2);L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{if(p.lat && p.lon) L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup(`<b>${{p.name}}</b><br><button onclick="openReview('${{p.name.replace(/'/g, "\\\\'")}}', '${{c.replace(/'/g, "\\\\'")}}')" style="background:var(--gold); border:none; padding:5px 10px; border-radius:5px; font-weight:bold; cursor:pointer; margin-top:8px;">AI REVIEW</button>`);}}));}}setTimeout(() => worldMap.invalidateSize(), 400);}}function flyToUser() {{if(userLat && userLon) {{worldMap.flyTo([userLat, userLon], 15);L.marker([userLat, userLon]).addTo(worldMap).bindPopup("๐ My Spot").openPopup();}} else alert("GPS off, honey!");}}function searchAndOpenMap(pName) {{let found = null; let fCountry = "";Object.keys(PLACE_DB).some(c => {{found = PLACE_DB[c].find(p => p.name.includes(pName));if(found) {{ fCountry = c; return true; }}}});if(found) window.open(getMapUrl(found, fCountry), '_blank');else window.open("https://www.google.com/maps/search/" + encodeURIComponent(pName), '_blank');}}function closeMap() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}7 unmodified lines8910111213149 unmodified lines242526272829303 unmodified lines3435363738394018 unmodified lines59606162636465110 unmodified lines17617717817918018118218318418518618718818919019119219319419512 unmodified lines20820921021121221321421521621721821922022122222322422522617 unmodified lines2442452462472482492506 unmodified lines2572582592602612622631 unmodified line26526626726826927027123 unmodified lines2952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253267 unmodified linesimport io# ==========================================# ๐ 1. ์ํฌ๋ฆฟ ๋ฐ ์ค์ ๋ก๋# ==========================================GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")9 unmodified lines""", unsafe_allow_html=True)# ==========================================# 2. ๋ฐ์ดํฐ ๋ก๋ (Google Sheet ์ฐ๋ ๋ฐ ์ ์ )# ==========================================PLACE_DB = {}try:3 unmodified linesresponse.raise_for_status()df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')# ๋ฌธ์์ด ์ ์ (JS ๋ฌธ๋ฒ ์ถฉ๋ ๋ฐฉ์ง)for col in df.select_dtypes(include=['object']).columns:df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")18 unmodified linesdb_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')# ==========================================# 3. ํตํฉ ํ๋ก ํธ์๋ (์ค๊ดํธ ์์ ์ด์ค์ผ์ดํ ์๋ฃ)# ==========================================html_code = f"""<!DOCTYPE html>110 unmodified lineswindow.onload = function() {{const keys = Object.keys(PLACE_DB).sort();const select = document.getElementById('country-select');keys.forEach(function(k) {{const opt = document.createElement('option');opt.value = k; opt.text = k; select.appendChild(opt);}});if(keys.length > 0) selectCountry(keys[0]);navigator.geolocation.getCurrentPosition(function(p) {{userLat = p.coords.latitude; userLon = p.coords.longitude;}}, function(e) {{ console.log("GPS Denied"); }});}};function selectCountry(c) {{ selectedCountry = c; renderList(); }}function setLanguage(l, el) {{currentLang = l;document.querySelectorAll('.lang-btn').forEach(function(b) {{ b.classList.remove('active'); }});el.classList.add('active');renderList();}}12 unmodified lineslist.innerHTML = "";const countryPlaces = PLACE_DB[selectedCountry] || [];countryPlaces.forEach(function(p) {{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 the taste of 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;'>" +"<button class='btn-action' style='background:var(--gold); color:black;' onclick=\\"openReview('" + p.name.replace(/'/g, "\\\\'") + "', '" + selectedCountry.replace(/'/g, "\\\\'") + "')\\">AI REVIEW</button>" +"<button class='btn-action' style='background:#333; color:white; border:1px solid #555;' onclick=\\"window.open('" + mapUrl + "', '_blank')\\">MAP</button>" +"</div>";list.appendChild(card);}});}}17 unmodified linesconst match = res.match(/\\[(.*?)\\]/);if(match) {{const pName = match[1];botMsgDiv.innerHTML += "<br><button class='reco-btn' onclick=\\"searchAndOpenMap('" + pName.replace(/'/g, "\\\\'") + "')\\">๐ View on Map</button>";}}chatHistory.push({{ role: "assistant", content: res }});}}6 unmodified lines}}async function openReview(name, country) {{const p = PLACE_DB[country].find(function(x) {{ return x.name === name; }}); if(!p) return;document.getElementById('repo-title').innerText = name;document.getElementById('detail-page').style.transform = 'translateX(0%)';document.getElementById('loader').style.display = 'flex';1 unmodified lineminiMap = L.map('mini-map');L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(miniMap);}}setTimeout(function() {{ 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 + ". Sections: Vibe, Must Try, Secret Tip." }},{{ role: "user", content: "Write review for " + name + " in " + country }}23 unmodified linesif(!worldMap) {{worldMap = L.map('full-map').setView([20, 0], 2);L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);Object.keys(PLACE_DB).forEach(function(c) {{PLACE_DB[c].forEach(function(p) {{if(p.lat && p.lon) {{L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup("<b>" + p.name + "</b><br><button onclick=\\"openReview('" + p.name.replace(/'/g, "\\\\'") + "', '" + c.replace(/'/g, "\\\\'") + "')\\" style='background:var(--gold); border:none; padding:5px 10px; border-radius:5px; font-weight:bold; cursor:pointer; margin-top:8px;'>AI REVIEW</button>");}}}});}});}}setTimeout(function() {{ worldMap.invalidateSize(); }}, 400);}}function flyToUser() {{if(userLat && userLon) {{worldMap.flyTo([userLat, userLon], 15);L.marker([userLat, userLon]).addTo(worldMap).bindPopup("๐ My Spot").openPopup();}} else {{ alert("GPS off, honey!"); }}}}function searchAndOpenMap(pName) {{let found = null; let fCountry = "";Object.keys(PLACE_DB).some(function(c) {{found = PLACE_DB[c].find(function(p) {{ return p.name.includes(pName); }});if(found) {{ fCountry = c; return true; }}}});if(found) {{ window.open(getMapUrl(found, fCountry), '_blank'); }}else {{ window.open("https://www.google.com/maps/search/" + encodeURIComponent(pName), '_blank'); }}}}function closeMap() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
app.py+35-25