Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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. ํตํฉ ํ๋ก ํธ์๋ (
|
| 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 |
-
|
| 109 |
-
|
| 110 |
-
.
|
|
|
|
|
|
|
| 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;
|
| 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;
|
| 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;
|
| 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:
|
| 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;
|
| 147 |
-
<div id="mini-map" style="width:100%; height:
|
| 148 |
-
<div style="flex:1; overflow-y:auto; padding:
|
| 149 |
-
<div id="repo-title" style="font-size:
|
| 150 |
-
<div id="repo-content" style="line-height:1.
|
| 151 |
</div>
|
| 152 |
</div>
|
| 153 |
|
| 154 |
-
<div id="loader" class="loading-screen"><div class="loader-ring"></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 |
-
|
| 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(
|
| 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/
|
| 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.
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
});
|
| 292 |
}
|
| 293 |
}
|
|
@@ -318,7 +307,7 @@ html_template = """
|
|
| 318 |
</html>
|
| 319 |
"""
|
| 320 |
|
| 321 |
-
# ํ์ด์ฌ ๋ณ์ ์ฃผ์
(
|
| 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)
|