Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,14 +8,13 @@ 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", "")
|
| 15 |
|
| 16 |
st.set_page_config(page_title="Drunken Plane", page_icon="โ๏ธ", layout="wide")
|
| 17 |
|
| 18 |
-
# CSS ์ค๊ดํธ๋ f-string ํ์ถ์ ์ํด {{ }} ์ฌ์ฉ
|
| 19 |
st.markdown("""
|
| 20 |
<style>
|
| 21 |
.block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
|
|
@@ -35,7 +34,7 @@ try:
|
|
| 35 |
response.raise_for_status()
|
| 36 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 37 |
|
| 38 |
-
# ๋ฌธ์์ด ์ ์ (JS ๋ฌธ๋ฒ ์ถฉ๋ ๋ฐฉ์ง
|
| 39 |
for col in df.select_dtypes(include=['object']).columns:
|
| 40 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 41 |
|
|
@@ -60,7 +59,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
|
| 60 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 61 |
|
| 62 |
# ==========================================
|
| 63 |
-
# 3. ํตํฉ ํ๋ก ํธ์๋ (
|
| 64 |
# ==========================================
|
| 65 |
html_code = f"""
|
| 66 |
<!DOCTYPE html>
|
|
@@ -166,7 +165,6 @@ html_code = f"""
|
|
| 166 |
let chatHistory = [];
|
| 167 |
let currentLang = "KO";
|
| 168 |
let selectedCountry = "";
|
| 169 |
-
let currentDetailPlace = null;
|
| 170 |
|
| 171 |
const TRANSLATIONS = {{
|
| 172 |
"KO": {{ "ai": "Korean", "greet": "์๋
, ์๊ธฐ? ์ค๋ ์ ๋ง ๊ณ ์ ๋ง์์ด. ์๋ฐ๋ฆฌํํ
๋ญ๋ ๋ฌผ์ด๋ด~" }},
|
|
@@ -178,24 +176,22 @@ html_code = f"""
|
|
| 178 |
window.onload = function() {{
|
| 179 |
const keys = Object.keys(PLACE_DB).sort();
|
| 180 |
const select = document.getElementById('country-select');
|
| 181 |
-
keys.
|
| 182 |
-
const opt = document.createElement('option');
|
| 183 |
-
opt.value =
|
| 184 |
-
|
|
|
|
| 185 |
if(keys.length > 0) selectCountry(keys[0]);
|
| 186 |
navigator.geolocation.getCurrentPosition(function(p) {{
|
| 187 |
userLat = p.coords.latitude; userLon = p.coords.longitude;
|
| 188 |
}}, function(e) {{ console.log("GPS Denied"); }});
|
| 189 |
}};
|
| 190 |
|
| 191 |
-
function selectCountry(c) {{
|
| 192 |
-
selectedCountry = c;
|
| 193 |
-
renderList();
|
| 194 |
-
}}
|
| 195 |
-
|
| 196 |
function setLanguage(l, el) {{
|
| 197 |
currentLang = l;
|
| 198 |
-
document.querySelectorAll('.lang-btn')
|
|
|
|
| 199 |
el.classList.add('active');
|
| 200 |
renderList();
|
| 201 |
}}
|
|
@@ -214,7 +210,8 @@ html_code = f"""
|
|
| 214 |
list.innerHTML = "";
|
| 215 |
const countryPlaces = PLACE_DB[selectedCountry] || [];
|
| 216 |
|
| 217 |
-
countryPlaces.
|
|
|
|
| 218 |
const card = document.createElement('div');
|
| 219 |
card.className = 'place-card';
|
| 220 |
const descKey = 'desc_' + currentLang.toLowerCase();
|
|
@@ -228,7 +225,7 @@ html_code = f"""
|
|
| 228 |
"<button class='btn-action' style='background:#333; color:white; border:1px solid #555;' onclick=\\"window.open('" + mapUrl + "', '_blank')\\">MAP</button>" +
|
| 229 |
"</div>";
|
| 230 |
list.appendChild(card);
|
| 231 |
-
}}
|
| 232 |
}}
|
| 233 |
|
| 234 |
function openChat() {{
|
|
@@ -268,9 +265,15 @@ html_code = f"""
|
|
| 268 |
}}
|
| 269 |
|
| 270 |
async function openReview(name, country) {{
|
| 271 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
if(!p) return;
|
| 273 |
-
|
| 274 |
document.getElementById('repo-title').innerText = name;
|
| 275 |
document.getElementById('detail-page').style.transform = 'translateX(0%)';
|
| 276 |
document.getElementById('loader').style.display = 'flex';
|
|
@@ -307,7 +310,7 @@ html_code = f"""
|
|
| 307 |
}});
|
| 308 |
const d = await r.json();
|
| 309 |
return d.choices[0].message.content;
|
| 310 |
-
}
|
| 311 |
return "Sweetie, the connection is a bit unstable.";
|
| 312 |
}}
|
| 313 |
}}
|
|
@@ -317,13 +320,15 @@ html_code = f"""
|
|
| 317 |
if(!worldMap) {{
|
| 318 |
worldMap = L.map('full-map').setView([20, 0], 2);
|
| 319 |
L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
|
| 320 |
-
|
| 321 |
-
PLACE_DB[
|
|
|
|
|
|
|
| 322 |
if(p.lat && p.lon) {{
|
| 323 |
-
L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup("<b>" + p.name + "</b><br><button onclick=\\"openReview('" + p.name.replace(/'/g, "\\\\'") + "', '" +
|
| 324 |
}}
|
| 325 |
-
}}
|
| 326 |
-
}}
|
| 327 |
}}
|
| 328 |
setTimeout(function() {{ worldMap.invalidateSize(); }}, 400);
|
| 329 |
}}
|
|
@@ -340,11 +345,15 @@ html_code = f"""
|
|
| 340 |
function searchAndOpenMap(pName) {{
|
| 341 |
let found = null;
|
| 342 |
let fCountry = "";
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
if(found) {{
|
| 349 |
window.open(getMapUrl(found, fCountry), '_blank');
|
| 350 |
}} else {{
|
|
|
|
| 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", "")
|
| 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; }
|
|
|
|
| 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 |
|
|
|
|
| 59 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 60 |
|
| 61 |
# ==========================================
|
| 62 |
+
# 3. ํตํฉ ํ๋ก ํธ์๋ (์ฅ์ ์ถ์ฒ ๋ก์ง ๋ณด๊ฐ ๋ฒ์ )
|
| 63 |
# ==========================================
|
| 64 |
html_code = f"""
|
| 65 |
<!DOCTYPE html>
|
|
|
|
| 165 |
let chatHistory = [];
|
| 166 |
let currentLang = "KO";
|
| 167 |
let selectedCountry = "";
|
|
|
|
| 168 |
|
| 169 |
const TRANSLATIONS = {{
|
| 170 |
"KO": {{ "ai": "Korean", "greet": "์๋
, ์๊ธฐ? ์ค๋ ์ ๋ง ๊ณ ์ ๋ง์์ด. ์๋ฐ๋ฆฌํํ
๋ญ๋ ๋ฌผ์ด๋ด~" }},
|
|
|
|
| 176 |
window.onload = function() {{
|
| 177 |
const keys = Object.keys(PLACE_DB).sort();
|
| 178 |
const select = document.getElementById('country-select');
|
| 179 |
+
for(let i=0; i<keys.length; i++) {{
|
| 180 |
+
const opt = document.createElement('option');
|
| 181 |
+
opt.value = keys[i]; opt.text = keys[i];
|
| 182 |
+
select.appendChild(opt);
|
| 183 |
+
}}
|
| 184 |
if(keys.length > 0) selectCountry(keys[0]);
|
| 185 |
navigator.geolocation.getCurrentPosition(function(p) {{
|
| 186 |
userLat = p.coords.latitude; userLon = p.coords.longitude;
|
| 187 |
}}, function(e) {{ console.log("GPS Denied"); }});
|
| 188 |
}};
|
| 189 |
|
| 190 |
+
function selectCountry(c) {{ selectedCountry = c; renderList(); }}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
function setLanguage(l, el) {{
|
| 192 |
currentLang = l;
|
| 193 |
+
const btns = document.querySelectorAll('.lang-btn');
|
| 194 |
+
for(let i=0; i<btns.length; i++) {{ btns[i].classList.remove('active'); }}
|
| 195 |
el.classList.add('active');
|
| 196 |
renderList();
|
| 197 |
}}
|
|
|
|
| 210 |
list.innerHTML = "";
|
| 211 |
const countryPlaces = PLACE_DB[selectedCountry] || [];
|
| 212 |
|
| 213 |
+
for(let i=0; i<countryPlaces.length; i++) {{
|
| 214 |
+
const p = countryPlaces[i];
|
| 215 |
const card = document.createElement('div');
|
| 216 |
card.className = 'place-card';
|
| 217 |
const descKey = 'desc_' + currentLang.toLowerCase();
|
|
|
|
| 225 |
"<button class='btn-action' style='background:#333; color:white; border:1px solid #555;' onclick=\\"window.open('" + mapUrl + "', '_blank')\\">MAP</button>" +
|
| 226 |
"</div>";
|
| 227 |
list.appendChild(card);
|
| 228 |
+
}}
|
| 229 |
}}
|
| 230 |
|
| 231 |
function openChat() {{
|
|
|
|
| 265 |
}}
|
| 266 |
|
| 267 |
async function openReview(name, country) {{
|
| 268 |
+
const countryData = PLACE_DB[country];
|
| 269 |
+
let p = null;
|
| 270 |
+
if(countryData) {{
|
| 271 |
+
for(let i=0; i<countryData.length; i++) {{
|
| 272 |
+
if(countryData[i].name === name) {{ p = countryData[i]; break; }}
|
| 273 |
+
}}
|
| 274 |
+
}}
|
| 275 |
if(!p) return;
|
| 276 |
+
|
| 277 |
document.getElementById('repo-title').innerText = name;
|
| 278 |
document.getElementById('detail-page').style.transform = 'translateX(0%)';
|
| 279 |
document.getElementById('loader').style.display = 'flex';
|
|
|
|
| 310 |
}});
|
| 311 |
const d = await r.json();
|
| 312 |
return d.choices[0].message.content;
|
| 313 |
+
} catch(e) {{
|
| 314 |
return "Sweetie, the connection is a bit unstable.";
|
| 315 |
}}
|
| 316 |
}}
|
|
|
|
| 320 |
if(!worldMap) {{
|
| 321 |
worldMap = L.map('full-map').setView([20, 0], 2);
|
| 322 |
L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
|
| 323 |
+
for(let country in PLACE_DB) {{
|
| 324 |
+
const list = PLACE_DB[country];
|
| 325 |
+
for(let i=0; i<list.length; i++) {{
|
| 326 |
+
const p = list[i];
|
| 327 |
if(p.lat && p.lon) {{
|
| 328 |
+
L.marker([p.lat, p.lon]).addTo(worldMap).bindPopup("<b>" + p.name + "</b><br><button onclick=\\"openReview('" + p.name.replace(/'/g, "\\\\'") + "', '" + country.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>");
|
| 329 |
}}
|
| 330 |
+
}}
|
| 331 |
+
}}
|
| 332 |
}}
|
| 333 |
setTimeout(function() {{ worldMap.invalidateSize(); }}, 400);
|
| 334 |
}}
|
|
|
|
| 345 |
function searchAndOpenMap(pName) {{
|
| 346 |
let found = null;
|
| 347 |
let fCountry = "";
|
| 348 |
+
for(let country in PLACE_DB) {{
|
| 349 |
+
const list = PLACE_DB[country];
|
| 350 |
+
for(let i=0; i<list.length; i++) {{
|
| 351 |
+
if(list[i].name.includes(pName)) {{
|
| 352 |
+
found = list[i]; fCountry = country; break;
|
| 353 |
+
}}
|
| 354 |
+
}}
|
| 355 |
+
if(found) break;
|
| 356 |
+
}}
|
| 357 |
if(found) {{
|
| 358 |
window.open(getMapUrl(found, fCountry), '_blank');
|
| 359 |
}} else {{
|