Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,13 +8,15 @@ import requests
|
|
| 8 |
import io
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
-
#
|
| 12 |
# ==========================================
|
| 13 |
-
|
|
|
|
| 14 |
SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")
|
| 15 |
|
| 16 |
st.set_page_config(page_title="Drunken Plane", page_icon="βοΈ", layout="wide")
|
| 17 |
|
|
|
|
| 18 |
st.markdown("""
|
| 19 |
<style>
|
| 20 |
.block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
|
|
@@ -24,34 +26,54 @@ st.markdown("""
|
|
| 24 |
""", unsafe_allow_html=True)
|
| 25 |
|
| 26 |
# ==========================================
|
| 27 |
-
# 2. λ°μ΄ν° λ‘λ
|
| 28 |
# ==========================================
|
| 29 |
PLACE_DB = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
try:
|
| 31 |
if SHEET_URL:
|
| 32 |
-
response = requests.get(SHEET_URL)
|
| 33 |
response.encoding = 'utf-8'
|
|
|
|
| 34 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 35 |
-
df = df.fillna("")
|
| 36 |
df.columns = df.columns.str.strip()
|
|
|
|
|
|
|
| 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 |
if 'Country' in df.columns:
|
| 40 |
for country, group in df.groupby('Country'):
|
| 41 |
PLACE_DB[country] = group.fillna("").to_dict(orient='records')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
-
st.error(f"
|
|
|
|
| 44 |
|
|
|
|
| 45 |
emily_base64 = ""
|
| 46 |
if os.path.exists('emily.jpg'):
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
|
|
|
| 50 |
db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
| 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,25 +88,26 @@ html_template = """
|
|
| 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 |
-
|
|
|
|
| 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;
|
| 81 |
.pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
| 82 |
-
.pc-name { font-size:
|
| 83 |
.pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
|
| 84 |
-
.pc-label { font-size: 11px; padding:
|
| 85 |
-
.pc-desc { font-size:
|
| 86 |
.btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
.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); cursor: pointer; }
|
| 89 |
|
| 90 |
#world-map-page, #passport-page, #chat-page { background: #000; z-index: 2000; transform: translateY(100%); }
|
|
@@ -92,12 +115,13 @@ html_template = """
|
|
| 92 |
#detail-page { background: #0a0a0a; z-index: 4000; transform: translateX(100%); }
|
| 93 |
.nav-bar { height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; background: #111; }
|
| 94 |
|
|
|
|
| 95 |
.msg { max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; margin-bottom: 12px; }
|
| 96 |
.msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }
|
| 97 |
.msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }
|
| 98 |
.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; }
|
| 99 |
-
|
| 100 |
-
|
| 101 |
.stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
|
| 102 |
.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; }
|
| 103 |
.stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
|
|
@@ -110,13 +134,11 @@ html_template = """
|
|
| 110 |
<div class="lang-switcher">
|
| 111 |
<div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">π°π·</div>
|
| 112 |
<div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">πΊπΈ</div>
|
| 113 |
-
<div class="lang-btn" id="btn-JP" onclick="setLanguage('JP', this)">π―π΅</div>
|
| 114 |
-
<div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">π¨π³</div>
|
| 115 |
</div>
|
| 116 |
</div>
|
| 117 |
<div style="text-align:center; padding: 5px 0 15px 0;">
|
| 118 |
<div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
|
| 119 |
-
<button onclick="openMap()" style="margin-top:10px; padding:10px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer;">πΊοΈ EXPLORE WORLD
|
| 120 |
</div>
|
| 121 |
<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>
|
| 122 |
<div class="type-filter-container" id="filter-box"></div>
|
|
@@ -125,6 +147,7 @@ html_template = """
|
|
| 125 |
</div>
|
| 126 |
|
| 127 |
<div id="passport-page" class="page"><div class="nav-bar"><button onclick="closePassport()">β</button> MY PASSPORT</div><div id="stamp-grid" class="stamp-grid" style="overflow-y:auto;"></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 |
|
| 130 |
<div id="chat-page" class="page">
|
|
@@ -139,42 +162,63 @@ html_template = """
|
|
| 139 |
<div id="detail-page" class="page"><div class="nav-bar"><button onclick="closeDetail()">β</button> Review</div><div id="repo-content" style="padding:20px; white-space:pre-wrap; color:#ddd; line-height:1.7;"></div></div>
|
| 140 |
|
| 141 |
<script>
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
const PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));
|
| 144 |
let currentLang = "KO", selectedCountry = "", selectedType = "All", chatHistory = [];
|
| 145 |
let visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
|
| 146 |
let userLat = null, userLon = null;
|
|
|
|
| 147 |
|
| 148 |
const TRANSLATIONS = {
|
| 149 |
-
"KO": { "ai": "Korean", "aiBtn": "AI 리뷰", "mapBtn": "μ§λ", "filters": ["π μ 체", "πΊ μ ν΅μ£Ό", "π₯ μμ€ν€", "πΊ λ§₯μ£Ό", "π· μμΈ", "πΉ λ°"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
|
| 150 |
-
"EN": { "ai": "English", "aiBtn": "AI REVIEW", "mapBtn": "MAP", "filters": ["π All", "πΊ Trad.", "π₯ Whiskey", "πΊ Beer", "π· Wine", "πΉ Bar"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
|
| 151 |
-
"JP": { "ai": "Japanese", "aiBtn": "AI γ¬γγ₯γΌ", "mapBtn": "ε°ε³", "filters": ["π ε
¨ι¨", "πΊ δΌη΅±ι
", "π₯ γ¦γ€γΉν€", "πΊ γγΌγ«", "π· γ―γ€γ³", "πΉ γγΌ"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
|
| 152 |
-
"CN": { "ai": "Chinese", "aiBtn": "AI ηΉθ―", "mapBtn": "ε°εΎ", "filters": ["π ε
¨ι¨", "πΊ δΌ η»ι
", "π₯ ε¨ε£«εΏ", "πΊ ε€ι
", "π· θ‘θι
", "πΉ ι
ε§"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
|
| 153 |
};
|
| 154 |
|
|
|
|
| 155 |
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
}
|
| 161 |
function deg2rad(deg) { return deg * (Math.PI/180); }
|
| 162 |
|
|
|
|
| 163 |
function getMapUrl(p, country) {
|
| 164 |
if (country.includes("Korea") || country.includes("νκ΅")) return "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name);
|
| 165 |
return "https://www.google.com/maps/search/" + encodeURIComponent(p.name) + "/@" + p.lat + "," + p.lon + ",17z";
|
| 166 |
}
|
| 167 |
|
|
|
|
| 168 |
window.onload = function() {
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
};
|
| 176 |
|
| 177 |
function setLanguage(l, el) { currentLang = l; document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); el.classList.add('active'); renderFilters(); renderList(); }
|
|
|
|
| 178 |
function renderFilters() {
|
| 179 |
const box = document.getElementById('filter-box'); box.innerHTML = "";
|
| 180 |
TRANSLATIONS[currentLang].filters.forEach((f, i) => {
|
|
@@ -183,6 +227,7 @@ html_template = """
|
|
| 183 |
box.appendChild(btn);
|
| 184 |
});
|
| 185 |
}
|
|
|
|
| 186 |
function selectCountry(c) { selectedCountry = c; renderList(); }
|
| 187 |
|
| 188 |
function renderList() {
|
|
@@ -195,16 +240,15 @@ html_template = """
|
|
| 195 |
const card = document.createElement('div'); card.className = 'place-card';
|
| 196 |
const displayLabel = p.label || p.category || "";
|
| 197 |
const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
|
|
|
|
| 198 |
let distHtml = "";
|
| 199 |
if(userLat && userLon && p.lat && p.lon) {
|
| 200 |
const dist = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
|
| 201 |
distHtml = `<span class="pc-dist">(π ${dist}km)</span>`;
|
| 202 |
}
|
|
|
|
| 203 |
card.innerHTML = `
|
| 204 |
-
<div class="pc-header">
|
| 205 |
-
<div class="pc-name">${p.name} ${distHtml}</div>
|
| 206 |
-
<div class="pc-label">${displayLabel}</div>
|
| 207 |
-
</div>
|
| 208 |
<div class="pc-desc">${desc}</div>
|
| 209 |
<div style="display:flex; gap:10px; margin-top:15px;">
|
| 210 |
<button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
|
|
@@ -214,28 +258,22 @@ html_template = """
|
|
| 214 |
});
|
| 215 |
}
|
| 216 |
|
| 217 |
-
// [μ€μ]
|
| 218 |
async function callGroq(msgs) {
|
| 219 |
-
const apiKey = "
|
| 220 |
-
if(!apiKey || apiKey.length <
|
| 221 |
|
| 222 |
try {
|
| 223 |
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
| 224 |
-
method: "POST",
|
| 225 |
-
headers: { "Content-Type": "application/json", "Authorization": "Bearer " + apiKey },
|
| 226 |
-
// λͺ¨λΈμ κ°μ₯ μμ μ μΈ llama-3.1-70b-versatile λ‘ λ³κ²½
|
| 227 |
body: JSON.stringify({ model: "llama-3.1-70b-versatile", messages: msgs, temperature: 0.7 })
|
| 228 |
});
|
| 229 |
|
| 230 |
-
if (!r.ok)
|
| 231 |
-
const errData = await r.json();
|
| 232 |
-
const errMsg = errData.error ? errData.error.message : r.statusText;
|
| 233 |
-
return "Emily Error: " + r.status + " (" + errMsg + ")";
|
| 234 |
-
}
|
| 235 |
|
| 236 |
const d = await r.json();
|
| 237 |
return d.choices[0].message.content;
|
| 238 |
-
} catch(e) { return "
|
| 239 |
}
|
| 240 |
|
| 241 |
async function sendChat() {
|
|
@@ -243,30 +281,37 @@ html_template = """
|
|
| 243 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 244 |
chatHistory.push({ role: "user", content: msg });
|
| 245 |
|
|
|
|
| 246 |
let nearbyContext = "";
|
|
|
|
|
|
|
| 247 |
if(userLat && userLon) {
|
| 248 |
let nearbyPlaces = [];
|
| 249 |
for(let c in PLACE_DB) {
|
| 250 |
PLACE_DB[c].forEach(p => {
|
| 251 |
if(p.lat && p.lon) {
|
| 252 |
const d = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
|
| 253 |
-
if(parseFloat(d) <= 20)
|
| 254 |
-
nearbyPlaces.push(p.name + "(" + d + "km)");
|
| 255 |
-
}
|
| 256 |
}
|
| 257 |
});
|
| 258 |
}
|
| 259 |
-
if(nearbyPlaces.length > 0)
|
| 260 |
-
nearbyContext = " [System: User GPS (" + userLat + "," + userLon + "). Places within 20km: " + nearbyPlaces.join(", ") + ". Prioritize these if user asks 'nearby'.]";
|
| 261 |
-
}
|
| 262 |
}
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
-
const sysPrompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
|
| 267 |
|
|
|
|
| 268 |
let finalHtml = botMsg;
|
| 269 |
-
const regex = /\
|
| 270 |
let match;
|
| 271 |
while ((match = regex.exec(botMsg)) !== null) {
|
| 272 |
const pName = match[1];
|
|
@@ -292,6 +337,7 @@ html_template = """
|
|
| 292 |
}
|
| 293 |
|
| 294 |
function markVisited(name) { if(!visitedPlaces.includes(name)) { visitedPlaces.push(name); localStorage.setItem('visitedPlaces', JSON.stringify(visitedPlaces)); } }
|
|
|
|
| 295 |
function openPassport() { document.getElementById('passport-page').style.transform = 'translateX(0%)'; const grid = document.getElementById('stamp-grid'); grid.innerHTML = ""; for(let c in PLACE_DB) { PLACE_DB[c].forEach(p => { const active = visitedPlaces.includes(p.name); const div = document.createElement('div'); div.className = 'stamp' + (active ? ' active' : ''); div.innerHTML = active ? `π·<br><b>${p.name}</b>` : `βοΈ`; grid.appendChild(div); }); } }
|
| 296 |
function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
|
| 297 |
|
|
@@ -323,8 +369,9 @@ html_template = """
|
|
| 323 |
</html>
|
| 324 |
"""
|
| 325 |
|
|
|
|
| 326 |
html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
|
| 327 |
html_code = html_code.replace("DB_DATA_BASE64", db_base64)
|
| 328 |
-
html_code = html_code.replace("
|
| 329 |
|
| 330 |
components.html(html_code, height=1000, scrolling=True)
|
|
|
|
| 8 |
import io
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
+
# π οΈ 1. μ€μ λ° μν¬λ¦Ώ (μ¬κΈ°μ ν€λ₯Ό μ
λ ₯νμΈμ!)
|
| 12 |
# ==========================================
|
| 13 |
+
# λ°μ΄ν μμ API ν€λ₯Ό μ§μ λΆμ¬λ£μΌμΈμ. μ: "gsk_..."
|
| 14 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
|
| 15 |
SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")
|
| 16 |
|
| 17 |
st.set_page_config(page_title="Drunken Plane", page_icon="βοΈ", layout="wide")
|
| 18 |
|
| 19 |
+
# μ€νμΌ: μ¬λ°± μ κ±° λ° μ 체 νλ©΄ μ¬μ©
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
.block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
|
|
|
|
| 26 |
""", unsafe_allow_html=True)
|
| 27 |
|
| 28 |
# ==========================================
|
| 29 |
+
# πΎ 2. λ°μ΄ν° λ‘λ (μμ μ₯μΉ ν¬ν¨)
|
| 30 |
# ==========================================
|
| 31 |
PLACE_DB = {}
|
| 32 |
+
|
| 33 |
+
# [λΉμμ©] μνΈ λ‘λ μ€ν¨ μ μ¬μ©ν λλ―Έ λ°μ΄ν°
|
| 34 |
+
DUMMY_DATA = {
|
| 35 |
+
"Korea": [{"name": "Zest", "lat": 37.525, "lon": 127.040, "category": "Bar", "label": "πΈ World Best", "desc_ko": "μμΈ μ΅κ³ μ μΉ΅ν
μΌ λ°", "address": "μμΈ κ°λ¨κ΅¬ λμ°λλ‘55κΈΈ 26"}],
|
| 36 |
+
"Malaysia": [{"name": "Bar Trigona", "lat": 3.159, "lon": 101.714, "category": "Bar", "label": "π Sustainable", "desc_ko": "μΏ μλΌλ£ΈνΈλ₯΄μ μ§μ κ°λ₯ν λ°", "address": "Four Seasons Hotel, Kuala Lumpur"}]
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
try:
|
| 40 |
if SHEET_URL:
|
| 41 |
+
response = requests.get(SHEET_URL, timeout=5) # 5μ΄ νμμμ
|
| 42 |
response.encoding = 'utf-8'
|
| 43 |
+
response.raise_for_status()
|
| 44 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 45 |
+
df = df.fillna("") # λΉμΉΈ μ±μ°κΈ°
|
| 46 |
df.columns = df.columns.str.strip()
|
| 47 |
+
|
| 48 |
+
# νΉμλ¬Έμ μ΄μ€μΌμ΄ν (JS μ€λ₯ λ°©μ§)
|
| 49 |
for col in df.select_dtypes(include=['object']).columns:
|
| 50 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 51 |
+
|
| 52 |
if 'Country' in df.columns:
|
| 53 |
for country, group in df.groupby('Country'):
|
| 54 |
PLACE_DB[country] = group.fillna("").to_dict(orient='records')
|
| 55 |
+
else:
|
| 56 |
+
# μνΈ URLμ΄ μμΌλ©΄ λλ―Έ λ°μ΄ν° μ¬μ© (μ± κΊΌμ§ λ°©μ§)
|
| 57 |
+
PLACE_DB = DUMMY_DATA
|
| 58 |
+
|
| 59 |
except Exception as e:
|
| 60 |
+
st.error(f"β οΈ λ°μ΄ν° λ‘λ μ€ν¨ (λλ―Έ λ°μ΄ν°λ‘ μ νν©λλ€): {e}")
|
| 61 |
+
PLACE_DB = DUMMY_DATA
|
| 62 |
|
| 63 |
+
# μλ°λ¦¬ μ΄λ―Έμ§ μ²λ¦¬
|
| 64 |
emily_base64 = ""
|
| 65 |
if os.path.exists('emily.jpg'):
|
| 66 |
+
try:
|
| 67 |
+
with open("emily.jpg", "rb") as f:
|
| 68 |
+
emily_base64 = base64.b64encode(f.read()).decode()
|
| 69 |
+
except: pass
|
| 70 |
|
| 71 |
+
# JSON μ§λ ¬ν
|
| 72 |
db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
| 73 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 74 |
|
| 75 |
# ==========================================
|
| 76 |
+
# π₯οΈ 3. ν΅ν© νλ‘ νΈμλ (JavaScript 볡ꡬ)
|
| 77 |
# ==========================================
|
| 78 |
html_template = """
|
| 79 |
<!DOCTYPE html>
|
|
|
|
| 88 |
body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
|
| 89 |
.page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
|
| 90 |
|
| 91 |
+
/* UI Components */
|
| 92 |
+
.top-nav { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 500; background: rgba(0,0,0,0.8); }
|
| 93 |
.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); }
|
| 94 |
.lang-switcher { display: flex; gap: 6px; }
|
| 95 |
.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; }
|
| 96 |
.lang-btn.active { background: var(--gold); color: black; font-weight: bold; border-color: var(--gold); }
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
.place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
|
| 99 |
+
.place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; }
|
| 100 |
.pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
| 101 |
+
.pc-name { font-size: 18px; font-weight: bold; color: var(--gold); flex: 1; }
|
| 102 |
.pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
|
| 103 |
+
.pc-label { font-size: 11px; padding: 3px 8px; border-radius: 8px; background: rgba(212,175,55,0.15); color: var(--gold); border: 1px solid var(--gold); white-space: nowrap; }
|
| 104 |
+
.pc-desc { font-size: 13px; color: #aaa; margin: 10px 0; line-height: 1.5; }
|
| 105 |
.btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
|
| 106 |
|
| 107 |
+
.type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; scrollbar-width: none; }
|
| 108 |
+
.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; }
|
| 109 |
+
.type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
|
| 110 |
+
|
| 111 |
.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); cursor: pointer; }
|
| 112 |
|
| 113 |
#world-map-page, #passport-page, #chat-page { background: #000; z-index: 2000; transform: translateY(100%); }
|
|
|
|
| 115 |
#detail-page { background: #0a0a0a; z-index: 4000; transform: translateX(100%); }
|
| 116 |
.nav-bar { height: 60px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #222; background: #111; }
|
| 117 |
|
| 118 |
+
/* Chat & Reco */
|
| 119 |
.msg { max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; margin-bottom: 12px; }
|
| 120 |
.msg.bot { align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }
|
| 121 |
.msg.user { align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }
|
| 122 |
.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; }
|
| 123 |
+
|
| 124 |
+
/* Passport */
|
| 125 |
.stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
|
| 126 |
.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; }
|
| 127 |
.stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
|
|
|
|
| 134 |
<div class="lang-switcher">
|
| 135 |
<div class="lang-btn active" id="btn-KO" onclick="setLanguage('KO', this)">π°π·</div>
|
| 136 |
<div class="lang-btn" id="btn-EN" onclick="setLanguage('EN', this)">πΊπΈ</div>
|
|
|
|
|
|
|
| 137 |
</div>
|
| 138 |
</div>
|
| 139 |
<div style="text-align:center; padding: 5px 0 15px 0;">
|
| 140 |
<div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
|
| 141 |
+
<button onclick="openMap()" style="margin-top:10px; padding:10px 25px; background:var(--gold); border:none; border-radius:30px; font-weight:bold; cursor:pointer;">πΊοΈ EXPLORE WORLD</button>
|
| 142 |
</div>
|
| 143 |
<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>
|
| 144 |
<div class="type-filter-container" id="filter-box"></div>
|
|
|
|
| 147 |
</div>
|
| 148 |
|
| 149 |
<div id="passport-page" class="page"><div class="nav-bar"><button onclick="closePassport()">β</button> MY PASSPORT</div><div id="stamp-grid" class="stamp-grid" style="overflow-y:auto;"></div></div>
|
| 150 |
+
|
| 151 |
<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>
|
| 152 |
|
| 153 |
<div id="chat-page" class="page">
|
|
|
|
| 162 |
<div id="detail-page" class="page"><div class="nav-bar"><button onclick="closeDetail()">β</button> Review</div><div id="repo-content" style="padding:20px; white-space:pre-wrap; color:#ddd; line-height:1.7;"></div></div>
|
| 163 |
|
| 164 |
<script>
|
| 165 |
+
// Base64 λμ½λ© (μμ μ₯μΉ μΆκ°)
|
| 166 |
+
function b64DecodeUnicode(str) {
|
| 167 |
+
try {
|
| 168 |
+
return decodeURIComponent(atob(str).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join(''));
|
| 169 |
+
} catch(e) { console.error("Base64 Error", e); return "{}"; }
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
const PLACE_DB = JSON.parse(b64DecodeUnicode("DB_DATA_BASE64"));
|
| 173 |
let currentLang = "KO", selectedCountry = "", selectedType = "All", chatHistory = [];
|
| 174 |
let visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
|
| 175 |
let userLat = null, userLon = null;
|
| 176 |
+
let worldMap = null; // λ§΅ κ°μ²΄ μ μ λ³μ
|
| 177 |
|
| 178 |
const TRANSLATIONS = {
|
| 179 |
+
"KO": { "ai": "Korean", "greet": "μλ
? μ€λμ μ΄λμ νμν κΉ?", "aiBtn": "AI 리뷰", "mapBtn": "μ§λ", "filters": ["π μ 체", "πΊ μ ν΅μ£Ό", "π₯ μμ€ν€", "πΊ λ§₯μ£Ό", "π· μμΈ", "πΉ λ°"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
|
| 180 |
+
"EN": { "ai": "English", "greet": "Hey! Where to drink tonight?", "aiBtn": "AI REVIEW", "mapBtn": "MAP", "filters": ["π All", "πΊ Trad.", "π₯ Whiskey", "πΊ Beer", "π· Wine", "πΉ Bar"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
|
|
|
|
|
|
|
| 181 |
};
|
| 182 |
|
| 183 |
+
// 거리 κ³μ° (Haversine)
|
| 184 |
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
|
| 185 |
+
try {
|
| 186 |
+
var R = 6371; var dLat = deg2rad(lat2-lat1); var dLon = deg2rad(lon2-lon1);
|
| 187 |
+
var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2);
|
| 188 |
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
| 189 |
+
return (R * c).toFixed(1);
|
| 190 |
+
} catch(e) { return "?"; }
|
| 191 |
}
|
| 192 |
function deg2rad(deg) { return deg * (Math.PI/180); }
|
| 193 |
|
| 194 |
+
// μ§λ URL μμ± (νκ΅ -> λ€μ΄λ² / ν΄μΈ -> ꡬκΈ)
|
| 195 |
function getMapUrl(p, country) {
|
| 196 |
if (country.includes("Korea") || country.includes("νκ΅")) return "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name);
|
| 197 |
return "https://www.google.com/maps/search/" + encodeURIComponent(p.name) + "/@" + p.lat + "," + p.lon + ",17z";
|
| 198 |
}
|
| 199 |
|
| 200 |
+
// μ΄κΈ°ν
|
| 201 |
window.onload = function() {
|
| 202 |
+
try {
|
| 203 |
+
const keys = Object.keys(PLACE_DB).sort();
|
| 204 |
+
const select = document.getElementById('country-select');
|
| 205 |
+
keys.forEach(k => { const opt = document.createElement('option'); opt.value = k; opt.text = k; select.appendChild(opt); });
|
| 206 |
+
|
| 207 |
+
if(keys.length > 0) selectCountry(keys[0]);
|
| 208 |
+
renderFilters();
|
| 209 |
+
|
| 210 |
+
// GPS μλ (μ€ν¨ν΄λ μ±μ λμ)
|
| 211 |
+
if(navigator.geolocation) {
|
| 212 |
+
navigator.geolocation.getCurrentPosition(function(p) {
|
| 213 |
+
userLat = p.coords.latitude; userLon = p.coords.longitude;
|
| 214 |
+
renderList(); // μμΉ μ‘μΌλ©΄ 거리 κ°±μ
|
| 215 |
+
}, function(e) { console.log("GPS Failed", e); });
|
| 216 |
+
}
|
| 217 |
+
} catch(e) { console.error("Init Error", e); }
|
| 218 |
};
|
| 219 |
|
| 220 |
function setLanguage(l, el) { currentLang = l; document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); el.classList.add('active'); renderFilters(); renderList(); }
|
| 221 |
+
|
| 222 |
function renderFilters() {
|
| 223 |
const box = document.getElementById('filter-box'); box.innerHTML = "";
|
| 224 |
TRANSLATIONS[currentLang].filters.forEach((f, i) => {
|
|
|
|
| 227 |
box.appendChild(btn);
|
| 228 |
});
|
| 229 |
}
|
| 230 |
+
|
| 231 |
function selectCountry(c) { selectedCountry = c; renderList(); }
|
| 232 |
|
| 233 |
function renderList() {
|
|
|
|
| 240 |
const card = document.createElement('div'); card.className = 'place-card';
|
| 241 |
const displayLabel = p.label || p.category || "";
|
| 242 |
const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
|
| 243 |
+
|
| 244 |
let distHtml = "";
|
| 245 |
if(userLat && userLon && p.lat && p.lon) {
|
| 246 |
const dist = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
|
| 247 |
distHtml = `<span class="pc-dist">(π ${dist}km)</span>`;
|
| 248 |
}
|
| 249 |
+
|
| 250 |
card.innerHTML = `
|
| 251 |
+
<div class="pc-header"><div class="pc-name">${p.name} ${distHtml}</div><div class="pc-label">${displayLabel}</div></div>
|
|
|
|
|
|
|
|
|
|
| 252 |
<div class="pc-desc">${desc}</div>
|
| 253 |
<div style="display:flex; gap:10px; margin-top:15px;">
|
| 254 |
<button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
|
|
|
|
| 258 |
});
|
| 259 |
}
|
| 260 |
|
| 261 |
+
// [μ€μ] API νΈμΆ (μμ μ± κ°ν)
|
| 262 |
async function callGroq(msgs) {
|
| 263 |
+
const apiKey = "GROQ_KEY_INJECTED"; // Pythonμμ μΉνλ¨
|
| 264 |
+
if(!apiKey || apiKey.length < 10) return "Error: API Key is missing inside the code.";
|
| 265 |
|
| 266 |
try {
|
| 267 |
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
| 268 |
+
method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer " + apiKey },
|
|
|
|
|
|
|
| 269 |
body: JSON.stringify({ model: "llama-3.1-70b-versatile", messages: msgs, temperature: 0.7 })
|
| 270 |
});
|
| 271 |
|
| 272 |
+
if (!r.ok) return "Emily Error: " + r.status + " (Please check API Key)";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
const d = await r.json();
|
| 275 |
return d.choices[0].message.content;
|
| 276 |
+
} catch(e) { return "Network Error: " + e.message; }
|
| 277 |
}
|
| 278 |
|
| 279 |
async function sendChat() {
|
|
|
|
| 281 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 282 |
chatHistory.push({ role: "user", content: msg });
|
| 283 |
|
| 284 |
+
// μ€λ§νΈ 컨ν
μ€νΈ μμ± (거리 20km / λμ μ 체)
|
| 285 |
let nearbyContext = "";
|
| 286 |
+
let cityContext = "";
|
| 287 |
+
|
| 288 |
if(userLat && userLon) {
|
| 289 |
let nearbyPlaces = [];
|
| 290 |
for(let c in PLACE_DB) {
|
| 291 |
PLACE_DB[c].forEach(p => {
|
| 292 |
if(p.lat && p.lon) {
|
| 293 |
const d = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
|
| 294 |
+
if(parseFloat(d) <= 20) nearbyPlaces.push(p.name + "(" + d + "km)");
|
|
|
|
|
|
|
| 295 |
}
|
| 296 |
});
|
| 297 |
}
|
| 298 |
+
if(nearbyPlaces.length > 0) nearbyContext = " [GPS: User is within 20km of: " + nearbyPlaces.join(", ") + "]";
|
|
|
|
|
|
|
| 299 |
}
|
| 300 |
+
|
| 301 |
+
// λͺ¨λ λμ μ 보λ μ 곡 (μ거리 μΆμ²μ©)
|
| 302 |
+
cityContext = " [Database Cities: " + Object.keys(PLACE_DB).join(", ") + "]";
|
| 303 |
|
| 304 |
+
const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
|
| 305 |
+
1. If recommending a place, put name in [Brackets].
|
| 306 |
+
2. If user says 'nearby', use GPS info.
|
| 307 |
+
3. If user says city name, ignore GPS and recommend from that city.
|
| 308 |
+
${nearbyContext} ${cityContext}`;
|
| 309 |
|
| 310 |
const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
|
| 311 |
|
| 312 |
+
// λ§ν¬ μμ± (μ κ·μ μ΄μ€μΌμ΄ν μμ μλ£)
|
| 313 |
let finalHtml = botMsg;
|
| 314 |
+
const regex = /\[(.*?)\]/g;
|
| 315 |
let match;
|
| 316 |
while ((match = regex.exec(botMsg)) !== null) {
|
| 317 |
const pName = match[1];
|
|
|
|
| 337 |
}
|
| 338 |
|
| 339 |
function markVisited(name) { if(!visitedPlaces.includes(name)) { visitedPlaces.push(name); localStorage.setItem('visitedPlaces', JSON.stringify(visitedPlaces)); } }
|
| 340 |
+
|
| 341 |
function openPassport() { document.getElementById('passport-page').style.transform = 'translateX(0%)'; const grid = document.getElementById('stamp-grid'); grid.innerHTML = ""; for(let c in PLACE_DB) { PLACE_DB[c].forEach(p => { const active = visitedPlaces.includes(p.name); const div = document.createElement('div'); div.className = 'stamp' + (active ? ' active' : ''); div.innerHTML = active ? `π·<br><b>${p.name}</b>` : `βοΈ`; grid.appendChild(div); }); } }
|
| 342 |
function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
|
| 343 |
|
|
|
|
| 369 |
</html>
|
| 370 |
"""
|
| 371 |
|
| 372 |
+
# ν€ μ£Όμ
λ° λ λλ§
|
| 373 |
html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}")
|
| 374 |
html_code = html_code.replace("DB_DATA_BASE64", db_base64)
|
| 375 |
+
html_code = html_code.replace("GROQ_KEY_INJECTED", GROQ_API_KEY) # μλ°μ€ν¬λ¦½νΈμ ν€ μ£Όμ
|
| 376 |
|
| 377 |
components.html(html_code, height=1000, scrolling=True)
|