Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ st.markdown("""
|
|
| 41 |
""", unsafe_allow_html=True)
|
| 42 |
|
| 43 |
# ==========================================
|
| 44 |
-
# πΎ 2. λ°μ΄ν° λ‘λ (
|
| 45 |
# ==========================================
|
| 46 |
PLACE_DB = {}
|
| 47 |
DUMMY_DATA = {
|
|
@@ -58,8 +58,12 @@ try:
|
|
| 58 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 59 |
df = df.fillna("")
|
| 60 |
df.columns = df.columns.str.strip()
|
|
|
|
|
|
|
|
|
|
| 61 |
for col in df.select_dtypes(include=['object']).columns:
|
| 62 |
-
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True)
|
|
|
|
| 63 |
if 'Country' in df.columns:
|
| 64 |
df['Country'] = df['Country'].astype(str).str.strip()
|
| 65 |
for country, group in df.groupby('Country'):
|
|
@@ -81,7 +85,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
|
| 81 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 82 |
|
| 83 |
# ==========================================
|
| 84 |
-
# π₯οΈ 3. ν΅ν© νλ‘ νΈμλ (
|
| 85 |
# ==========================================
|
| 86 |
html_template = """
|
| 87 |
<!DOCTYPE html>
|
|
@@ -140,8 +144,6 @@ html_template = """
|
|
| 140 |
.reco-btn { display: block; margin-top: 8px; padding: 10px; background: var(--gold); color: black !important; border-radius: 10px; font-weight: bold; text-decoration: none; font-size: 12px; cursor: pointer; border:none; width: 100%; text-align: center; }
|
| 141 |
.popup-btn { background: var(--gold); color: black; border: none; padding: 6px 12px; border-radius: 5px; font-weight: bold; font-size: 11px; cursor: pointer; width: 100%; margin-top: 5px; }
|
| 142 |
.leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); }
|
| 143 |
-
.leaflet-popup-content { margin: 10px; }
|
| 144 |
-
|
| 145 |
.stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
|
| 146 |
.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; }
|
| 147 |
.stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
|
|
@@ -295,7 +297,7 @@ html_template = """
|
|
| 295 |
<div class="pc-desc">${desc}</div>
|
| 296 |
<div style="display:flex; gap:10px; margin-top:15px;">
|
| 297 |
<button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
|
| 298 |
-
<button class="btn-action" style="background:#333; color:white;" onclick="markVisited('${p.name
|
| 299 |
</div>`;
|
| 300 |
list.appendChild(card);
|
| 301 |
});
|
|
@@ -390,20 +392,20 @@ html_template = """
|
|
| 390 |
box.appendChild(div); box.scrollTop = box.scrollHeight;
|
| 391 |
}
|
| 392 |
|
|
|
|
| 393 |
function markVisited(name) {
|
| 394 |
-
// [ν¨μΉ] μ€ν¬ν λκΈ°ν λ‘μ§ κ°ν (μ΅μ κ° λ€μ λ‘λ)
|
| 395 |
let vp = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
|
| 396 |
if(!vp.includes(name)) {
|
| 397 |
vp.push(name);
|
| 398 |
localStorage.setItem('visitedPlaces', JSON.stringify(vp));
|
| 399 |
-
visitedPlaces = vp;
|
| 400 |
alert("βοΈ Stamped on Passport!");
|
| 401 |
} else { alert("You already visited here!"); }
|
| 402 |
}
|
| 403 |
|
|
|
|
| 404 |
function openPassport() {
|
| 405 |
document.getElementById('passport-page').style.transform = 'translateX(0%)';
|
| 406 |
-
// [ν¨μΉ] μ¬κΆ μ΄ λλ§λ€ λ‘컬μ€ν 리μ§μμ μ΅μ λ°μ΄ν° κ°μ λ‘λ
|
| 407 |
visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
|
| 408 |
|
| 409 |
const grid = document.getElementById('stamp-grid');
|
|
@@ -419,7 +421,6 @@ html_template = """
|
|
| 419 |
});
|
| 420 |
}
|
| 421 |
}
|
| 422 |
-
|
| 423 |
function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
|
| 424 |
|
| 425 |
function openMap() {
|
|
@@ -452,24 +453,19 @@ html_template = """
|
|
| 452 |
|
| 453 |
function closeMap() { document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }
|
| 454 |
|
| 455 |
-
// [ν¨μΉ] κ²μ κΈ°λ₯ κ°ν: μ΄λ¦, μ£Όμ, μ€λͺ
, λμμ΄λ¦(ν€κ°) λͺ¨λ κ²μ
|
| 456 |
function searchMap() {
|
| 457 |
const q = document.getElementById('map-input').value.toLowerCase();
|
| 458 |
if(!q) return;
|
| 459 |
|
| 460 |
let found = false;
|
| 461 |
for(let c in PLACE_DB) {
|
| 462 |
-
// 1. λλΌ/λμ μ΄λ¦ 체ν¬
|
| 463 |
if(c.toLowerCase().includes(q)) {
|
| 464 |
-
// ν΄λΉ λμμ 첫 λ²μ§Έ μ₯μλ‘ μ΄λ
|
| 465 |
if(PLACE_DB[c].length > 0 && PLACE_DB[c][0].lat && PLACE_DB[c][0].lon) {
|
| 466 |
worldMap.setView([PLACE_DB[c][0].lat, PLACE_DB[c][0].lon], 12);
|
| 467 |
found = true; break;
|
| 468 |
}
|
| 469 |
}
|
| 470 |
-
// 2. μ₯μ μμΈ μ²΄ν¬
|
| 471 |
for(let p of PLACE_DB[c]) {
|
| 472 |
-
// μ΄λ¦ + μ£Όμ + μ€λͺ
μ λͺ¨λ ν©μ³μ κ²μ
|
| 473 |
const content = (p.name + " " + (p.address||"") + " " + (p.desc_ko||"")).toLowerCase();
|
| 474 |
if(content.includes(q)) {
|
| 475 |
if(p.lat && p.lon) {
|
|
|
|
| 41 |
""", unsafe_allow_html=True)
|
| 42 |
|
| 43 |
# ==========================================
|
| 44 |
+
# πΎ 2. λ°μ΄ν° λ‘λ (κ³Όμ ν¬μ₯ μ κ±° μμ μλ£)
|
| 45 |
# ==========================================
|
| 46 |
PLACE_DB = {}
|
| 47 |
DUMMY_DATA = {
|
|
|
|
| 58 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 59 |
df = df.fillna("")
|
| 60 |
df.columns = df.columns.str.strip()
|
| 61 |
+
|
| 62 |
+
# [ν΅μ¬ μμ ] json.dumpsκ° μμμ νλ―λ‘ μ¬κΈ°μ λ°μ΄ν κ°μ μΉνμ νμ§ μμ΅λλ€.
|
| 63 |
+
# μ€λ°κΏ λ¬Έμλ§ κ³΅λ°±μΌλ‘ μ²λ¦¬ν©λλ€.
|
| 64 |
for col in df.select_dtypes(include=['object']).columns:
|
| 65 |
+
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True)
|
| 66 |
+
|
| 67 |
if 'Country' in df.columns:
|
| 68 |
df['Country'] = df['Country'].astype(str).str.strip()
|
| 69 |
for country, group in df.groupby('Country'):
|
|
|
|
| 85 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 86 |
|
| 87 |
# ==========================================
|
| 88 |
+
# π₯οΈ 3. ν΅ν© νλ‘ νΈμλ (μ€ν¬ν λ‘μ§ μ μν)
|
| 89 |
# ==========================================
|
| 90 |
html_template = """
|
| 91 |
<!DOCTYPE html>
|
|
|
|
| 144 |
.reco-btn { display: block; margin-top: 8px; padding: 10px; background: var(--gold); color: black !important; border-radius: 10px; font-weight: bold; text-decoration: none; font-size: 12px; cursor: pointer; border:none; width: 100%; text-align: center; }
|
| 145 |
.popup-btn { background: var(--gold); color: black; border: none; padding: 6px 12px; border-radius: 5px; font-weight: bold; font-size: 11px; cursor: pointer; width: 100%; margin-top: 5px; }
|
| 146 |
.leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); }
|
|
|
|
|
|
|
| 147 |
.stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
|
| 148 |
.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; }
|
| 149 |
.stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
|
|
|
|
| 297 |
<div class="pc-desc">${desc}</div>
|
| 298 |
<div style="display:flex; gap:10px; margin-top:15px;">
|
| 299 |
<button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
|
| 300 |
+
<button class="btn-action" style="background:#333; color:white;" onclick="markVisited('${p.name.replace(/'/g, "\\\\'")}')">${t.mapBtn}</button>
|
| 301 |
</div>`;
|
| 302 |
list.appendChild(card);
|
| 303 |
});
|
|
|
|
| 392 |
box.appendChild(div); box.scrollTop = box.scrollHeight;
|
| 393 |
}
|
| 394 |
|
| 395 |
+
// [ν΅μ¬] μ€ν¬ν μ μ₯ λ‘μ§ (λ°μ΄ν λ¬Έμ ν΄κ²°λ¨)
|
| 396 |
function markVisited(name) {
|
|
|
|
| 397 |
let vp = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
|
| 398 |
if(!vp.includes(name)) {
|
| 399 |
vp.push(name);
|
| 400 |
localStorage.setItem('visitedPlaces', JSON.stringify(vp));
|
| 401 |
+
visitedPlaces = vp;
|
| 402 |
alert("βοΈ Stamped on Passport!");
|
| 403 |
} else { alert("You already visited here!"); }
|
| 404 |
}
|
| 405 |
|
| 406 |
+
// [ν΅μ¬] μ¬κΆ μ΄ λ λ°μ΄ν° μλ‘κ³ μΉ¨
|
| 407 |
function openPassport() {
|
| 408 |
document.getElementById('passport-page').style.transform = 'translateX(0%)';
|
|
|
|
| 409 |
visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
|
| 410 |
|
| 411 |
const grid = document.getElementById('stamp-grid');
|
|
|
|
| 421 |
});
|
| 422 |
}
|
| 423 |
}
|
|
|
|
| 424 |
function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
|
| 425 |
|
| 426 |
function openMap() {
|
|
|
|
| 453 |
|
| 454 |
function closeMap() { document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }
|
| 455 |
|
|
|
|
| 456 |
function searchMap() {
|
| 457 |
const q = document.getElementById('map-input').value.toLowerCase();
|
| 458 |
if(!q) return;
|
| 459 |
|
| 460 |
let found = false;
|
| 461 |
for(let c in PLACE_DB) {
|
|
|
|
| 462 |
if(c.toLowerCase().includes(q)) {
|
|
|
|
| 463 |
if(PLACE_DB[c].length > 0 && PLACE_DB[c][0].lat && PLACE_DB[c][0].lon) {
|
| 464 |
worldMap.setView([PLACE_DB[c][0].lat, PLACE_DB[c][0].lon], 12);
|
| 465 |
found = true; break;
|
| 466 |
}
|
| 467 |
}
|
|
|
|
| 468 |
for(let p of PLACE_DB[c]) {
|
|
|
|
| 469 |
const content = (p.name + " " + (p.address||"") + " " + (p.desc_ko||"")).toLowerCase();
|
| 470 |
if(content.includes(q)) {
|
| 471 |
if(p.lat && p.lon) {
|