Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,6 @@ try:
|
|
| 33 |
response.encoding = 'utf-8'
|
| 34 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 35 |
|
| 36 |
-
# ํ
์คํธ ์ ์ (JSON ํ์ฑ ์๋ฌ ๋ฐฉ์ง)
|
| 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).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 39 |
|
|
@@ -52,7 +51,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
|
| 52 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 53 |
|
| 54 |
# ==========================================
|
| 55 |
-
# 3. ํตํฉ ํ๋ก ํธ์๋ (
|
| 56 |
# ==========================================
|
| 57 |
html_template = """
|
| 58 |
<!DOCTYPE html>
|
|
@@ -67,37 +66,35 @@ html_template = """
|
|
| 67 |
body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
|
| 68 |
.page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
|
| 69 |
|
| 70 |
-
/* ๋ค๋น๊ฒ์ด์
& UI */
|
| 71 |
.top-nav { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 500; }
|
| 72 |
.passport-btn { font-size: 26px; cursor: pointer; background: rgba(255,215,0,0.1); padding: 8px; border-radius: 15px; border: 1px solid rgba(212,175,55,0.3); }
|
| 73 |
.lang-switcher { display: flex; gap: 6px; }
|
| 74 |
.lang-btn { background: rgba(0,0,0,0.6); border: 1px solid #444; color: #888; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 11px; }
|
| 75 |
.lang-btn.active { background: var(--gold); color: black; font-weight: bold; border-color: var(--gold); }
|
| 76 |
|
| 77 |
-
|
| 78 |
-
.type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; }
|
| 79 |
.type-btn { padding: 8px 16px; border-radius: 20px; font-size: 11px; font-weight: bold; background: #1a1a1a; color: #777; border: 1px solid #333; white-space: nowrap; cursor: pointer; }
|
| 80 |
.type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
|
| 81 |
|
| 82 |
-
/* ์ฅ์ ์นด๋ */
|
| 83 |
.place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
|
| 84 |
.place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; }
|
| 85 |
-
.pc-header { display: flex; justify-content: space-between; align-items: flex-start; }
|
| 86 |
-
.pc-name { font-size: 19px; font-weight: bold; color: var(--gold);
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
.btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
|
| 90 |
|
| 91 |
-
|
| 92 |
-
#passport-page { background: #0f0f1b; z-index: 5000; transform: translateX(-100%); }
|
| 93 |
-
.stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
|
| 94 |
-
.stamp { height: 90px; border-radius: 15px; border: 2px dashed #333; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #444; background: #161625; }
|
| 95 |
-
.stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
|
| 96 |
-
|
| 97 |
-
/* ์๋ฐ๋ฆฌ ๋ฒํผ */
|
| 98 |
-
.bartender-btn { position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('IMAGE_DATA'); background-size: cover; border: 3px solid var(--gold); z-index: 999; box-shadow: 0 0 20px rgba(212,175,55,0.5); }
|
| 99 |
|
| 100 |
#world-map-page { background: #000; z-index: 2000; transform: translateY(100%); }
|
|
|
|
| 101 |
#chat-page { background: #000; z-index: 3000; transform: translateY(100%); }
|
| 102 |
#detail-page { background: #0a0a0a; z-index: 4000; transform: translateX(100%); }
|
| 103 |
.nav-bar { height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; }
|
|
@@ -115,30 +112,22 @@ html_template = """
|
|
| 115 |
</div>
|
| 116 |
</div>
|
| 117 |
|
| 118 |
-
<div style="text-align:center; padding:
|
| 119 |
-
<div style="color:var(--gold); font-size:
|
| 120 |
-
<button onclick="openMap()" style="margin-top:
|
| 121 |
</div>
|
| 122 |
|
| 123 |
-
<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;
|
| 124 |
|
| 125 |
<div class="type-filter-container" id="filter-box"></div>
|
| 126 |
<div class="place-list-container" id="place-list"></div>
|
| 127 |
<div class="bartender-btn" onclick="openChat()"></div>
|
| 128 |
</div>
|
| 129 |
|
| 130 |
-
<div id="passport-page" class="page">
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
<h1 id="passport-stat" style="color:var(--gold); margin:10px 0;">0 STAMPS</h1>
|
| 135 |
-
</div>
|
| 136 |
-
<div class="stamp-grid" id="stamp-grid" style="overflow-y:auto;"></div>
|
| 137 |
-
</div>
|
| 138 |
-
|
| 139 |
-
<div id="world-map-page" class="page"><div class="nav-bar"><button onclick="closeMap()" style="background:none; border:none; color:var(--gold);">๐ HOME</button></div><div id="full-map" style="width:100%; height:100%;"></div></div>
|
| 140 |
-
<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 Chat</span></div><div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px;"></div></div>
|
| 141 |
-
<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><span id="repo-header" style="margin-left:15px; font-weight:bold;">Report</span></div><div id="repo-content" style="padding:20px; white-space:pre-wrap; line-height:1.7; color:#ddd;"></div></div>
|
| 142 |
|
| 143 |
<script>
|
| 144 |
function b64DecodeUnicode(str) { return decodeURIComponent(atob(str).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }
|
|
@@ -180,64 +169,47 @@ html_template = """
|
|
| 180 |
|
| 181 |
function selectCountry(c) { selectedCountry = c; renderList(); }
|
| 182 |
|
| 183 |
-
function markVisited(name) {
|
| 184 |
-
if(!visitedPlaces.includes(name)) {
|
| 185 |
-
visitedPlaces.push(name);
|
| 186 |
-
localStorage.setItem('visitedPlaces', JSON.stringify(visitedPlaces));
|
| 187 |
-
}
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
function renderList() {
|
| 191 |
const list = document.getElementById('place-list'); list.innerHTML = "";
|
| 192 |
-
const
|
|
|
|
| 193 |
const t = TRANSLATIONS[currentLang];
|
| 194 |
|
| 195 |
filtered.forEach(p => {
|
| 196 |
const card = document.createElement('div'); card.className = 'place-card';
|
| 197 |
-
const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "Discovering...";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
card.innerHTML = `
|
| 199 |
-
<div class="pc-header">
|
|
|
|
|
|
|
|
|
|
| 200 |
<div class="pc-desc">${desc}</div>
|
| 201 |
<div style="display:flex; gap:10px; margin-top:15px;">
|
| 202 |
-
<button class="btn-action" style="background:var(--gold); color:black;" onclick="
|
| 203 |
-
<button class="btn-action" style="background:#333; color:white;" onclick="
|
| 204 |
</div>`;
|
| 205 |
list.appendChild(card);
|
| 206 |
});
|
| 207 |
}
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
const grid = document.getElementById('stamp-grid'); grid.innerHTML = "";
|
| 212 |
-
document.getElementById('passport-stat').innerText = visitedPlaces.length + " STAMPS";
|
| 213 |
-
for(let c in PLACE_DB) {
|
| 214 |
-
PLACE_DB[c].forEach(p => {
|
| 215 |
-
const active = visitedPlaces.includes(p.name);
|
| 216 |
-
const div = document.createElement('div'); div.className = 'stamp' + (active ? ' active' : '');
|
| 217 |
-
div.innerHTML = active ? `<span style="font-size:20px;">๐ท</span><br><b>${p.name}</b><br>${c}` : `<span style="font-size:20px; filter:grayscale(1);">โ๏ธ</span>`;
|
| 218 |
-
grid.appendChild(div);
|
| 219 |
-
});
|
| 220 |
-
}
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
// --- ๊ธฐ๋ฅ ํจ์๋ค ---
|
| 224 |
function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
|
| 225 |
function openMap() { document.getElementById('world-map-page').style.transform = 'translateY(0%)'; }
|
| 226 |
function closeMap() { document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }
|
| 227 |
function openChat() { document.getElementById('chat-page').style.transform = 'translateY(0%)'; }
|
| 228 |
function closeChat() { document.getElementById('chat-page').style.transform = 'translateY(100%)'; }
|
| 229 |
-
function openReview(n, c) {
|
| 230 |
-
document.getElementById('detail-page').style.transform = 'translateX(0%)';
|
| 231 |
-
document.getElementById('repo-header').innerText = n;
|
| 232 |
-
document.getElementById('repo-content').innerText = "Emily is writing a review for " + n + "...";
|
| 233 |
-
}
|
| 234 |
function closeDetail() { document.getElementById('detail-page').style.transform = 'translateX(100%)'; }
|
| 235 |
</script>
|
| 236 |
</body>
|
| 237 |
</html>
|
| 238 |
"""
|
| 239 |
|
| 240 |
-
# ์ต์ข
๋ฐ์ดํฐ ์ฃผ์
|
| 241 |
html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
|
| 242 |
html_code = html_code.replace("DB_DATA_BASE64", db_base64)
|
| 243 |
html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)
|
|
|
|
| 33 |
response.encoding = 'utf-8'
|
| 34 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 35 |
|
|
|
|
| 36 |
for col in df.select_dtypes(include=['object']).columns:
|
| 37 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 38 |
|
|
|
|
| 51 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 52 |
|
| 53 |
# ==========================================
|
| 54 |
+
# 3. ํตํฉ ํ๋ก ํธ์๋ (๋ผ๋ฒจ๋ง ์ ๋ฐ ์์ ๋ฒ์ )
|
| 55 |
# ==========================================
|
| 56 |
html_template = """
|
| 57 |
<!DOCTYPE html>
|
|
|
|
| 66 |
body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
|
| 67 |
.page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
|
| 68 |
|
|
|
|
| 69 |
.top-nav { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 500; }
|
| 70 |
.passport-btn { font-size: 26px; cursor: pointer; background: rgba(255,215,0,0.1); padding: 8px; border-radius: 15px; border: 1px solid rgba(212,175,55,0.3); }
|
| 71 |
.lang-switcher { display: flex; gap: 6px; }
|
| 72 |
.lang-btn { background: rgba(0,0,0,0.6); border: 1px solid #444; color: #888; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 11px; }
|
| 73 |
.lang-btn.active { background: var(--gold); color: black; font-weight: bold; border-color: var(--gold); }
|
| 74 |
|
| 75 |
+
.type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; scrollbar-width: none; }
|
|
|
|
| 76 |
.type-btn { padding: 8px 16px; border-radius: 20px; font-size: 11px; font-weight: bold; background: #1a1a1a; color: #777; border: 1px solid #333; white-space: nowrap; cursor: pointer; }
|
| 77 |
.type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
|
| 78 |
|
|
|
|
| 79 |
.place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
|
| 80 |
.place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; }
|
| 81 |
+
.pc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
|
| 82 |
+
.pc-name { font-size: 19px; font-weight: bold; color: var(--gold); line-height: 1.2; flex: 1; }
|
| 83 |
+
|
| 84 |
+
/* ๋ผ๋ฒจ ๋์์ธ ์์ : DB ๋ฐ์ดํฐ ๊ทธ๋๋ก ์ถ๋ ฅ */
|
| 85 |
+
.pc-label {
|
| 86 |
+
font-size: 10px; padding: 4px 10px; border-radius: 8px;
|
| 87 |
+
background: rgba(212,175,55,0.15); color: var(--gold);
|
| 88 |
+
border: 1px solid var(--gold); font-weight: 900; white-space: nowrap;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.pc-desc { font-size: 13.5px; color: #aaa; line-height: 1.6; margin: 12px 0; }
|
| 92 |
.btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
|
| 93 |
|
| 94 |
+
.bartender-btn { position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('IMAGE_DATA'); background-size: cover; border: 3px solid var(--gold); z-index: 999; box-shadow: 0 0 20px rgba(212, 175, 55, 0.5); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
#world-map-page { background: #000; z-index: 2000; transform: translateY(100%); }
|
| 97 |
+
#passport-page { background: #0f0f1b; z-index: 5000; transform: translateX(-100%); }
|
| 98 |
#chat-page { background: #000; z-index: 3000; transform: translateY(100%); }
|
| 99 |
#detail-page { background: #0a0a0a; z-index: 4000; transform: translateX(100%); }
|
| 100 |
.nav-bar { height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; }
|
|
|
|
| 112 |
</div>
|
| 113 |
</div>
|
| 114 |
|
| 115 |
+
<div style="text-align:center; padding: 5px 0 15px 0;">
|
| 116 |
+
<div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
|
| 117 |
+
<button onclick="openMap()" style="margin-top:10px; padding:12px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer;">๐บ๏ธ EXPLORE WORLD MAP</button>
|
| 118 |
</div>
|
| 119 |
|
| 120 |
+
<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;" onchange="selectCountry(this.value)"></select></center>
|
| 121 |
|
| 122 |
<div class="type-filter-container" id="filter-box"></div>
|
| 123 |
<div class="place-list-container" id="place-list"></div>
|
| 124 |
<div class="bartender-btn" onclick="openChat()"></div>
|
| 125 |
</div>
|
| 126 |
|
| 127 |
+
<div id="passport-page" class="page"><div class="nav-bar"><button onclick="closePassport()">โ</button> PASSPORT</div><div id="stamp-grid" class="stamp-grid"></div></div>
|
| 128 |
+
<div id="world-map-page" class="page"><div class="nav-bar"><button onclick="closeMap()">๐ HOME</button></div><div id="full-map" style="width:100%; height:100%;"></div></div>
|
| 129 |
+
<div id="chat-page" class="page"><div class="nav-bar"><button onclick="closeChat()">โ</button> Emily</div><div id="chat-messages" style="flex:1; overflow-y:auto; padding:20px;"></div></div>
|
| 130 |
+
<div id="detail-page" class="page"><div class="nav-bar"><button onclick="closeDetail()">โ</button> Report</div><div id="repo-content" style="padding:20px;"></div></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
<script>
|
| 133 |
function b64DecodeUnicode(str) { return decodeURIComponent(atob(str).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }
|
|
|
|
| 169 |
|
| 170 |
function selectCountry(c) { selectedCountry = c; renderList(); }
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
function renderList() {
|
| 173 |
const list = document.getElementById('place-list'); list.innerHTML = "";
|
| 174 |
+
const countryPlaces = PLACE_DB[selectedCountry] || [];
|
| 175 |
+
const filtered = countryPlaces.filter(p => selectedType === "All" || p.category.includes(selectedType) || p.category === selectedType);
|
| 176 |
const t = TRANSLATIONS[currentLang];
|
| 177 |
|
| 178 |
filtered.forEach(p => {
|
| 179 |
const card = document.createElement('div'); card.className = 'place-card';
|
| 180 |
+
const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_en || p.desc_ko || "Discovering heritage...";
|
| 181 |
+
|
| 182 |
+
// [์์ ] ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ผ๋ฒจ(category) ๊ทธ๋๋ก ์ฌ์ฉ
|
| 183 |
+
const dbLabel = p.category || "";
|
| 184 |
+
|
| 185 |
card.innerHTML = `
|
| 186 |
+
<div class="pc-header">
|
| 187 |
+
<div class="pc-name">${p.name}</div>
|
| 188 |
+
<div class="pc-label">${dbLabel}</div>
|
| 189 |
+
</div>
|
| 190 |
<div class="pc-desc">${desc}</div>
|
| 191 |
<div style="display:flex; gap:10px; margin-top:15px;">
|
| 192 |
+
<button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
|
| 193 |
+
<button class="btn-action" style="background:#333; color:white;" onclick="window.open('http://googleusercontent.com/maps.google.com/3{p.name}', '_blank')">${t.mapBtn}</button>
|
| 194 |
</div>`;
|
| 195 |
list.appendChild(card);
|
| 196 |
});
|
| 197 |
}
|
| 198 |
|
| 199 |
+
// --- ๊ธฐ๋ฅ ํจ์๋ค (์ด์ ๊ณผ ๋์ผ) ---
|
| 200 |
+
function openPassport() { document.getElementById('passport-page').style.transform = 'translateX(0%)'; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
|
| 202 |
function openMap() { document.getElementById('world-map-page').style.transform = 'translateY(0%)'; }
|
| 203 |
function closeMap() { document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }
|
| 204 |
function openChat() { document.getElementById('chat-page').style.transform = 'translateY(0%)'; }
|
| 205 |
function closeChat() { document.getElementById('chat-page').style.transform = 'translateY(100%)'; }
|
| 206 |
+
function openReview(n, c) { document.getElementById('detail-page').style.transform = 'translateX(0%)'; document.getElementById('repo-content').innerText = n + " Review Loading..."; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
function closeDetail() { document.getElementById('detail-page').style.transform = 'translateX(100%)'; }
|
| 208 |
</script>
|
| 209 |
</body>
|
| 210 |
</html>
|
| 211 |
"""
|
| 212 |
|
|
|
|
| 213 |
html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
|
| 214 |
html_code = html_code.replace("DB_DATA_BASE64", db_base64)
|
| 215 |
html_code = html_code.replace("GROQ_KEY", GROQ_API_KEY)
|