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,7 +24,7 @@ st.markdown("""
|
|
| 24 |
""", unsafe_allow_html=True)
|
| 25 |
|
| 26 |
# ==========================================
|
| 27 |
-
# 2. 데이터 로드 (
|
| 28 |
# ==========================================
|
| 29 |
PLACE_DB = {}
|
| 30 |
try:
|
|
@@ -34,8 +34,9 @@ try:
|
|
| 34 |
response.raise_for_status()
|
| 35 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 36 |
|
|
|
|
| 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)
|
| 39 |
|
| 40 |
df.columns = df.columns.str.strip()
|
| 41 |
col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
|
|
@@ -58,7 +59,7 @@ 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. 프론트엔드 (
|
| 62 |
# ==========================================
|
| 63 |
html_code = f"""
|
| 64 |
<!DOCTYPE html>
|
|
@@ -66,90 +67,100 @@ html_code = f"""
|
|
| 66 |
<head>
|
| 67 |
<meta charset="utf-8">
|
| 68 |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
|
|
| 69 |
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
| 70 |
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
|
|
| 71 |
<style>
|
| 72 |
:root {{ --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }}
|
| 73 |
-
body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: sans-serif; overflow: hidden; }}
|
| 74 |
-
.page {{ position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.
|
| 75 |
|
| 76 |
#main-page {{ background: #000; z-index: 100; }}
|
| 77 |
.place-list-container {{ flex: 1; overflow-y: auto; padding: 20px; padding-bottom: 120px; }}
|
| 78 |
-
.place-card {{ background: #1a1a1a; border: 1px solid #333; border-radius:
|
| 79 |
.pc-name {{ font-size: 18px; font-weight: bold; color: var(--gold); }}
|
| 80 |
-
.pc-desc {{ font-size: 13px; color: #
|
| 81 |
|
| 82 |
.bartender-btn {{
|
| 83 |
-
position: fixed; bottom: 30%; right: 20px; width:
|
| 84 |
background: url('data:image/jpeg;base64,{emily_base64}') center/cover;
|
| 85 |
border: 3px solid var(--gold); z-index: 999; cursor: pointer;
|
| 86 |
-
box-shadow: 0 0
|
| 87 |
}}
|
|
|
|
| 88 |
|
| 89 |
#world-map-page {{ background: #111; z-index: 2000; transform: translateY(100%); }}
|
| 90 |
-
|
| 91 |
-
/* [중요] GPS 버튼 최상단 고정 */
|
| 92 |
.map-gps-btn {{
|
| 93 |
position: absolute; bottom: 30%; right: 20px; z-index: 9999 !important;
|
| 94 |
-
width:
|
| 95 |
-
border:
|
| 96 |
display: flex; align-items: center; justify-content: center;
|
| 97 |
-
box-shadow: 0 4px 15px rgba(0,0,0,0.
|
| 98 |
}}
|
| 99 |
|
| 100 |
#chat-page {{ background: #000; z-index: 3000; transform: translateY(100%); display: flex; flex-direction: column; }}
|
| 101 |
#detail-page {{ background: #0a0a0a; z-index: 4000; transform: translateX(100%); display: flex; flex-direction: column; }}
|
| 102 |
|
| 103 |
.nav-bar {{ height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; background: #111; }}
|
| 104 |
-
.btn-action {{ padding: 10px
|
| 105 |
|
| 106 |
-
.loading-screen {{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.
|
| 107 |
-
.loader-ring {{ width:
|
| 108 |
@keyframes spin {{ 0% {{ transform: rotate(0deg); }} 100% {{ transform: rotate(360deg); }} }}
|
| 109 |
|
| 110 |
-
.msg {{ max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; margin-bottom:
|
| 111 |
.msg.bot {{ align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }}
|
| 112 |
.msg.user {{ align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }}
|
| 113 |
|
| 114 |
-
.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; }}
|
|
|
|
|
|
|
|
|
|
| 115 |
</style>
|
| 116 |
</head>
|
| 117 |
<body>
|
| 118 |
-
|
| 119 |
<div id="main-page" class="page">
|
| 120 |
-
<div
|
| 121 |
-
<div
|
| 122 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
</div>
|
|
|
|
| 124 |
<div class="place-list-container" id="place-list"></div>
|
| 125 |
<div class="bartender-btn" onclick="openChat()"></div>
|
| 126 |
</div>
|
| 127 |
|
| 128 |
<div id="world-map-page" class="page">
|
| 129 |
-
<div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold); font-size:18px;">🏠 HOME</button></div>
|
| 130 |
<button class="map-gps-btn" onclick="flyToUser()">🎯</button>
|
| 131 |
<div id="full-map" style="width:100%; height:100%;"></div>
|
| 132 |
</div>
|
| 133 |
|
| 134 |
<div id="chat-page" class="page">
|
| 135 |
-
<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>
|
| 136 |
<div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column;"></div>
|
| 137 |
<div style="padding:15px; display:flex; gap:10px; background:#111;">
|
| 138 |
-
<input id="chat-input" type="text" style="flex:1; padding:
|
| 139 |
-
<button onclick="sendChat()" style="padding:10px
|
| 140 |
</div>
|
| 141 |
</div>
|
| 142 |
|
| 143 |
<div id="detail-page" class="page">
|
| 144 |
-
<div class="nav-bar"><button onclick="closeDetail()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button><div
|
| 145 |
-
<div id="mini-map" style="width:100%; height:
|
| 146 |
-
<div style="flex:1; overflow-y:auto; padding:
|
| 147 |
-
<div id="repo-title" style="font-size:
|
| 148 |
-
<div id="repo-content" style="
|
| 149 |
</div>
|
| 150 |
</div>
|
| 151 |
|
| 152 |
-
<div id="loader" class="loading-screen"><div class="loader-ring"></div><div style="color:var(--gold); margin-top:
|
| 153 |
|
| 154 |
<script>
|
| 155 |
function b64DecodeUnicode(str) {{
|
|
@@ -161,16 +172,35 @@ html_code = f"""
|
|
| 161 |
const PLACE_DB = JSON.parse(b64DecodeUnicode("{db_base64}"));
|
| 162 |
let userLat = null, userLon = null, worldMap = null, miniMap = null;
|
| 163 |
let chatHistory = [];
|
| 164 |
-
let currentLang = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
window.onload = function() {{
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
| 169 |
}};
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
function getMapUrl(p, country) {{
|
| 173 |
-
if (country.includes("Korea") || country.includes("한국")) {{
|
| 174 |
let query = p.address ? p.address : p.name;
|
| 175 |
return "https://map.naver.com/p/search/" + encodeURIComponent(query);
|
| 176 |
}} else {{
|
|
@@ -181,32 +211,34 @@ html_code = f"""
|
|
| 181 |
function renderList() {{
|
| 182 |
const list = document.getElementById('place-list');
|
| 183 |
list.innerHTML = "";
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
| 201 |
}});
|
| 202 |
}}
|
| 203 |
|
| 204 |
-
//
|
| 205 |
function openChat() {{
|
| 206 |
document.getElementById('chat-page').style.transform = 'translateY(0%)';
|
| 207 |
if(chatHistory.length === 0) {{
|
| 208 |
-
addChatMessage(
|
| 209 |
-
chatHistory.push({{ role: "system", content: "You are Emily, a flirtatious blonde bartender.
|
| 210 |
}}
|
| 211 |
}}
|
| 212 |
|
|
@@ -220,11 +252,10 @@ html_code = f"""
|
|
| 220 |
const res = await callGroq(chatHistory);
|
| 221 |
botMsgDiv.innerText = res;
|
| 222 |
|
| 223 |
-
// 상담 후 추천 장소가 있으면 링크 추가
|
| 224 |
const match = res.match(/\\[(.*?)\\]/);
|
| 225 |
if(match) {{
|
| 226 |
const pName = match[1];
|
| 227 |
-
botMsgDiv.innerHTML += `<br><button class="reco-btn" onclick="searchAndOpenMap('${{pName.replace(/'/g, "\\\\'")}}')">📍
|
| 228 |
}}
|
| 229 |
chatHistory.push({{ role: "assistant", content: res }});
|
| 230 |
}}
|
|
@@ -236,11 +267,9 @@ html_code = f"""
|
|
| 236 |
return div;
|
| 237 |
}}
|
| 238 |
|
| 239 |
-
//
|
| 240 |
async function openReview(name, country) {{
|
| 241 |
-
const p = PLACE_DB[country].find(x => x.name === name);
|
| 242 |
-
if(!p) return;
|
| 243 |
-
|
| 244 |
document.getElementById('repo-title').innerText = name;
|
| 245 |
document.getElementById('detail-page').style.transform = 'translateX(0%)';
|
| 246 |
document.getElementById('loader').style.display = 'flex';
|
|
@@ -256,15 +285,15 @@ html_code = f"""
|
|
| 256 |
}}, 400);
|
| 257 |
|
| 258 |
const prompt = [
|
| 259 |
-
{{ role: "system", content: "Act as Emily
|
| 260 |
-
{{ role: "user", content: `Write a review for '${{name}}' in ${{country}}
|
| 261 |
];
|
| 262 |
const res = await callGroq(prompt);
|
| 263 |
document.getElementById('repo-content').innerText = res;
|
| 264 |
document.getElementById('loader').style.display = 'none';
|
| 265 |
}}
|
| 266 |
|
| 267 |
-
//
|
| 268 |
async function callGroq(messages) {{
|
| 269 |
try {{
|
| 270 |
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {{
|
|
@@ -273,13 +302,11 @@ html_code = f"""
|
|
| 273 |
body: JSON.stringify({{
|
| 274 |
model: "llama-3.3-70b-versatile",
|
| 275 |
messages: messages,
|
| 276 |
-
temperature: 0.
|
| 277 |
-
top_p: 0.8,
|
| 278 |
-
frequency_penalty: 0.6 // 루프 방지 기강 잡기
|
| 279 |
}})
|
| 280 |
}});
|
| 281 |
const d = await r.json(); return d.choices[0].message.content;
|
| 282 |
-
} catch(e) {{ return "
|
| 283 |
}}
|
| 284 |
|
| 285 |
function openMap() {{
|
|
@@ -288,7 +315,7 @@ html_code = f"""
|
|
| 288 |
worldMap = L.map('full-map').setView([20, 0], 2);
|
| 289 |
L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
|
| 290 |
Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
|
| 291 |
-
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; border-radius:
|
| 292 |
}}));
|
| 293 |
}}
|
| 294 |
setTimeout(() => worldMap.invalidateSize(), 400);
|
|
@@ -297,12 +324,11 @@ html_code = f"""
|
|
| 297 |
function flyToUser() {{
|
| 298 |
if(userLat && userLon) {{
|
| 299 |
worldMap.flyTo([userLat, userLon], 15);
|
| 300 |
-
L.marker([userLat, userLon]).addTo(worldMap).bindPopup("📍
|
| 301 |
-
}} else alert("
|
| 302 |
}}
|
| 303 |
|
| 304 |
function searchAndOpenMap(pName) {{
|
| 305 |
-
// 상담 결과 나온 이름을 DB에서 찾아서 지도로 연결
|
| 306 |
let found = null; let fCountry = "";
|
| 307 |
Object.keys(PLACE_DB).some(c => {{
|
| 308 |
found = PLACE_DB[c].find(p => p.name.includes(pName));
|
|
|
|
| 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. 데이터 로드 (Google Sheet 연동 및 정제)
|
| 28 |
# ==========================================
|
| 29 |
PLACE_DB = {}
|
| 30 |
try:
|
|
|
|
| 34 |
response.raise_for_status()
|
| 35 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 36 |
|
| 37 |
+
# 데이터 클렌징: JS에서 문법 오류를 일으킬 수 있는 줄바꿈 및 특수 따옴표 정제
|
| 38 |
for col in df.select_dtypes(include=['object']).columns:
|
| 39 |
+
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 40 |
|
| 41 |
df.columns = df.columns.str.strip()
|
| 42 |
col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
|
|
|
|
| 59 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 60 |
|
| 61 |
# ==========================================
|
| 62 |
+
# 3. 통합 프론트엔드 (HTML/JS/CSS)
|
| 63 |
# ==========================================
|
| 64 |
html_code = f"""
|
| 65 |
<!DOCTYPE html>
|
|
|
|
| 67 |
<head>
|
| 68 |
<meta charset="utf-8">
|
| 69 |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
| 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; }}
|
| 77 |
+
.page {{ position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }}
|
| 78 |
|
| 79 |
#main-page {{ background: #000; z-index: 100; }}
|
| 80 |
.place-list-container {{ flex: 1; overflow-y: auto; padding: 20px; padding-bottom: 120px; }}
|
| 81 |
+
.place-card {{ background: #1a1a1a; border: 1px solid #333; border-radius: 15px; padding: 18px; margin-bottom: 15px; position: relative; }}
|
| 82 |
.pc-name {{ font-size: 18px; font-weight: bold; color: var(--gold); }}
|
| 83 |
+
.pc-desc {{ font-size: 13px; color: #bbb; margin: 8px 0; line-height: 1.5; }}
|
| 84 |
|
| 85 |
.bartender-btn {{
|
| 86 |
+
position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%;
|
| 87 |
background: url('data:image/jpeg;base64,{emily_base64}') center/cover;
|
| 88 |
border: 3px solid var(--gold); z-index: 999; cursor: pointer;
|
| 89 |
+
box-shadow: 0 0 25px rgba(212, 175, 55, 0.6); animation: bounce-float 3s ease-in-out infinite;
|
| 90 |
}}
|
| 91 |
+
@keyframes bounce-float {{ 0%, 100% {{ transform: translateY(0); }} 50% {{ transform: translateY(-15px); }} }}
|
| 92 |
|
| 93 |
#world-map-page {{ background: #111; z-index: 2000; transform: translateY(100%); }}
|
|
|
|
|
|
|
| 94 |
.map-gps-btn {{
|
| 95 |
position: absolute; bottom: 30%; right: 20px; z-index: 9999 !important;
|
| 96 |
+
width: 60px; height: 60px; border-radius: 50%; background: #222;
|
| 97 |
+
border: 3px solid var(--gold); color: var(--gold); font-size: 26px; cursor: pointer;
|
| 98 |
display: flex; align-items: center; justify-content: center;
|
| 99 |
+
box-shadow: 0 4px 15px rgba(0,0,0,0.8);
|
| 100 |
}}
|
| 101 |
|
| 102 |
#chat-page {{ background: #000; z-index: 3000; transform: translateY(100%); display: flex; flex-direction: column; }}
|
| 103 |
#detail-page {{ background: #0a0a0a; z-index: 4000; transform: translateX(100%); display: flex; flex-direction: column; }}
|
| 104 |
|
| 105 |
.nav-bar {{ height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; background: #111; }}
|
| 106 |
+
.btn-action {{ padding: 10px 18px; border-radius: 8px; border: none; cursor: pointer; font-weight: bold; margin-right: 8px; font-size: 12px; }}
|
| 107 |
|
| 108 |
+
.loading-screen {{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 8000; display: none; flex-direction: column; justify-content: center; align-items: center; }}
|
| 109 |
+
.loader-ring {{ width: 45px; height: 45px; border: 4px solid #333; border-top: 4px solid var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }}
|
| 110 |
@keyframes spin {{ 0% {{ transform: rotate(0deg); }} 100% {{ transform: rotate(360deg); }} }}
|
| 111 |
|
| 112 |
+
.msg {{ max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; margin-bottom: 12px; }}
|
| 113 |
.msg.bot {{ align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }}
|
| 114 |
.msg.user {{ align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }}
|
| 115 |
|
| 116 |
+
.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; }}
|
| 117 |
+
.lang-switcher {{ position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }}
|
| 118 |
+
.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; }}
|
| 119 |
+
.lang-btn.active {{ background: var(--gold); color: black; border-color: var(--gold); font-weight: bold; }}
|
| 120 |
</style>
|
| 121 |
</head>
|
| 122 |
<body>
|
|
|
|
| 123 |
<div id="main-page" class="page">
|
| 124 |
+
<div class="lang-switcher">
|
| 125 |
+
<div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">🇰🇷</div>
|
| 126 |
+
<div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">🇺🇸</div>
|
| 127 |
+
<div class="lang-btn" id="btn-JP" onclick="setLanguage('JP', this)">🇯🇵</div>
|
| 128 |
+
<div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">🇨🇳</div>
|
| 129 |
+
</div>
|
| 130 |
+
<div style="text-align:center; padding: 25px 0;">
|
| 131 |
+
<div style="color:var(--gold); font-size: 28px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
|
| 132 |
+
<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>
|
| 133 |
</div>
|
| 134 |
+
<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>
|
| 135 |
<div class="place-list-container" id="place-list"></div>
|
| 136 |
<div class="bartender-btn" onclick="openChat()"></div>
|
| 137 |
</div>
|
| 138 |
|
| 139 |
<div id="world-map-page" class="page">
|
| 140 |
+
<div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold); font-size:18px; cursor:pointer;">🏠 HOME</button></div>
|
| 141 |
<button class="map-gps-btn" onclick="flyToUser()">🎯</button>
|
| 142 |
<div id="full-map" style="width:100%; height:100%;"></div>
|
| 143 |
</div>
|
| 144 |
|
| 145 |
<div id="chat-page" class="page">
|
| 146 |
+
<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>
|
| 147 |
<div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column;"></div>
|
| 148 |
<div style="padding:15px; display:flex; gap:10px; background:#111;">
|
| 149 |
+
<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()">
|
| 150 |
+
<button onclick="sendChat()" style="padding:10px 25px; background:var(--gold); border:none; border-radius:10px; font-weight:bold; cursor:pointer;">SEND</button>
|
| 151 |
</div>
|
| 152 |
</div>
|
| 153 |
|
| 154 |
<div id="detail-page" class="page">
|
| 155 |
+
<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>
|
| 156 |
+
<div id="mini-map" style="width:100%; height:260px; border-bottom:1px solid var(--gold);"></div>
|
| 157 |
+
<div style="flex:1; overflow-y:auto; padding:25px;">
|
| 158 |
+
<div id="repo-title" style="font-size:24px; color:var(--gold); font-weight:bold; margin-bottom:10px;"></div>
|
| 159 |
+
<div id="repo-content" style="line-height:1.8; color:#ddd; white-space:pre-wrap; font-size:15px;"></div>
|
| 160 |
</div>
|
| 161 |
</div>
|
| 162 |
|
| 163 |
+
<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>
|
| 164 |
|
| 165 |
<script>
|
| 166 |
function b64DecodeUnicode(str) {{
|
|
|
|
| 172 |
const PLACE_DB = JSON.parse(b64DecodeUnicode("{db_base64}"));
|
| 173 |
let userLat = null, userLon = null, worldMap = null, miniMap = null;
|
| 174 |
let chatHistory = [];
|
| 175 |
+
let currentLang = "KO";
|
| 176 |
+
let selectedCountry = "";
|
| 177 |
+
|
| 178 |
+
const TRANSLATIONS = {{
|
| 179 |
+
"KO": {{ "ai": "Korean", "greet": "안녕, 자기? 오늘 정말 고생 많았어. 에밀리한테 뭐든 물어봐~" }},
|
| 180 |
+
"EN": {{ "ai": "English", "greet": "Hey darling, rough day? Let Emily find you a perfect spot to drink." }},
|
| 181 |
+
"JP": {{ "ai": "Japanese", "greet": "あら、ハニー。今日はお疲れ様。エ밀리になんでも聞いて?" }},
|
| 182 |
+
"CN": {{ "ai": "Chinese", "greet": "亲爱的,今天辛苦了。想喝点什么?尽管问艾米丽吧。" }}
|
| 183 |
+
}};
|
| 184 |
|
| 185 |
window.onload = function() {{
|
| 186 |
+
const keys = Object.keys(PLACE_DB).sort();
|
| 187 |
+
const select = document.getElementById('country-select');
|
| 188 |
+
keys.forEach(k => {{ const opt = document.createElement('option'); opt.value = k; opt.text = k; select.appendChild(opt); }});
|
| 189 |
+
if(keys.length > 0) selectCountry(keys[0]);
|
| 190 |
+
navigator.geolocation.getCurrentPosition(p => {{ userLat = p.coords.latitude; userLon = p.coords.longitude; }}, e => console.log("GPS Denied"));
|
| 191 |
}};
|
| 192 |
|
| 193 |
+
function selectCountry(c) {{ selectedCountry = c; renderList(); }}
|
| 194 |
+
function setLanguage(l, el) {{
|
| 195 |
+
currentLang = l;
|
| 196 |
+
document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
|
| 197 |
+
el.classList.add('active');
|
| 198 |
+
renderList();
|
| 199 |
+
}}
|
| 200 |
+
|
| 201 |
+
// [핵심 로직] 한국=네이버 주소 검색 / 해외=구글 좌표 줌인 검색
|
| 202 |
function getMapUrl(p, country) {{
|
| 203 |
+
if (country.includes("Korea") || country.includes("한국") || country.includes("대한민국")) {{
|
| 204 |
let query = p.address ? p.address : p.name;
|
| 205 |
return "https://map.naver.com/p/search/" + encodeURIComponent(query);
|
| 206 |
}} else {{
|
|
|
|
| 211 |
function renderList() {{
|
| 212 |
const list = document.getElementById('place-list');
|
| 213 |
list.innerHTML = "";
|
| 214 |
+
const countryPlaces = PLACE_DB[selectedCountry] || [];
|
| 215 |
+
|
| 216 |
+
countryPlaces.forEach(p => {{
|
| 217 |
+
const card = document.createElement('div');
|
| 218 |
+
card.className = 'place-card';
|
| 219 |
+
|
| 220 |
+
// unidentified 방지 Fallback 로직
|
| 221 |
+
const descKey = 'desc_' + currentLang.toLowerCase();
|
| 222 |
+
let desc = p[descKey] || p.desc_en || p.desc_ko || "Let's explore the heritage of this place.";
|
| 223 |
+
|
| 224 |
+
const mapUrl = getMapUrl(p, selectedCountry);
|
| 225 |
+
|
| 226 |
+
card.innerHTML = `<div class="pc-name">${{p.name}}</div>
|
| 227 |
+
<div class="pc-desc">${{desc}}</div>
|
| 228 |
+
<div style="margin-top:15px; display:flex; gap:10px;">
|
| 229 |
+
<button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${{p.name.replace(/'/g, "\\\\'")}}', '${{selectedCountry.replace(/'/g, "\\\\'")}}')">AI REVIEW</button>
|
| 230 |
+
<button class="btn-action" style="background:#333; color:white; border:1px solid #555;" onclick="window.open('${{mapUrl}}', '_blank')">MAP</button>
|
| 231 |
+
</div>`;
|
| 232 |
+
list.appendChild(card);
|
| 233 |
}});
|
| 234 |
}}
|
| 235 |
|
| 236 |
+
// 에밀리 상담 기능
|
| 237 |
function openChat() {{
|
| 238 |
document.getElementById('chat-page').style.transform = 'translateY(0%)';
|
| 239 |
if(chatHistory.length === 0) {{
|
| 240 |
+
addChatMessage(TRANSLATIONS[currentLang].greet, "bot");
|
| 241 |
+
chatHistory.push({{ role: "system", content: "You are Emily, a flirtatious blonde bartender. You must answer ONLY in " + TRANSLATIONS[currentLang].ai + ". Recommending a place from the list? Wrap it in brackets like [Place Name]." }});
|
| 242 |
}}
|
| 243 |
}}
|
| 244 |
|
|
|
|
| 252 |
const res = await callGroq(chatHistory);
|
| 253 |
botMsgDiv.innerText = res;
|
| 254 |
|
|
|
|
| 255 |
const match = res.match(/\\[(.*?)\\]/);
|
| 256 |
if(match) {{
|
| 257 |
const pName = match[1];
|
| 258 |
+
botMsgDiv.innerHTML += `<br><button class="reco-btn" onclick="searchAndOpenMap('${{pName.replace(/'/g, "\\\\'")}}')">📍 Open Location Map</button>`;
|
| 259 |
}}
|
| 260 |
chatHistory.push({{ role: "assistant", content: res }});
|
| 261 |
}}
|
|
|
|
| 267 |
return div;
|
| 268 |
}}
|
| 269 |
|
| 270 |
+
// AI 상세 리포트 기능
|
| 271 |
async function openReview(name, country) {{
|
| 272 |
+
const p = PLACE_DB[country].find(x => x.name === name); if(!p) return;
|
|
|
|
|
|
|
| 273 |
document.getElementById('repo-title').innerText = name;
|
| 274 |
document.getElementById('detail-page').style.transform = 'translateX(0%)';
|
| 275 |
document.getElementById('loader').style.display = 'flex';
|
|
|
|
| 285 |
}}, 400);
|
| 286 |
|
| 287 |
const prompt = [
|
| 288 |
+
{{ role: "system", content: "Act as Emily. Write a detailed review in " + TRANSLATIONS[currentLang].ai + ". Sections: Vibe, Must Try, Secret Tip." }},
|
| 289 |
+
{{ role: "user", content: `Write a review for '${{name}}' in ${{country}}` }}
|
| 290 |
];
|
| 291 |
const res = await callGroq(prompt);
|
| 292 |
document.getElementById('repo-content').innerText = res;
|
| 293 |
document.getElementById('loader').style.display = 'none';
|
| 294 |
}}
|
| 295 |
|
| 296 |
+
// Groq API 호출 (지능 복구 파라미터 적용)
|
| 297 |
async function callGroq(messages) {{
|
| 298 |
try {{
|
| 299 |
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {{
|
|
|
|
| 302 |
body: JSON.stringify({{
|
| 303 |
model: "llama-3.3-70b-versatile",
|
| 304 |
messages: messages,
|
| 305 |
+
temperature: 0.7, top_p: 0.85, frequency_penalty: 0.7 // 루프 방지 강화
|
|
|
|
|
|
|
| 306 |
}})
|
| 307 |
}});
|
| 308 |
const d = await r.json(); return d.choices[0].message.content;
|
| 309 |
+
} catch(e) {{ return "Sweetie, the connection is a bit unstable. Try again!"; }}
|
| 310 |
}}
|
| 311 |
|
| 312 |
function openMap() {{
|
|
|
|
| 315 |
worldMap = L.map('full-map').setView([20, 0], 2);
|
| 316 |
L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
|
| 317 |
Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
|
| 318 |
+
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>`);
|
| 319 |
}}));
|
| 320 |
}}
|
| 321 |
setTimeout(() => worldMap.invalidateSize(), 400);
|
|
|
|
| 324 |
function flyToUser() {{
|
| 325 |
if(userLat && userLon) {{
|
| 326 |
worldMap.flyTo([userLat, userLon], 15);
|
| 327 |
+
L.marker([userLat, userLon]).addTo(worldMap).bindPopup("📍 I'm Here!").openPopup();
|
| 328 |
+
}} else alert("Darling, I can't find your location. Check your GPS!");
|
| 329 |
}}
|
| 330 |
|
| 331 |
function searchAndOpenMap(pName) {{
|
|
|
|
| 332 |
let found = null; let fCountry = "";
|
| 333 |
Object.keys(PLACE_DB).some(c => {{
|
| 334 |
found = PLACE_DB[c].find(p => p.name.includes(pName));
|