import streamlit as st import streamlit.components.v1 as components import json import base64 import os import pandas as pd import requests import io # ========================================== # πŸ› οΈ 1. μ„€μ • 및 μ‹œν¬λ¦Ώ (μœ μ§€) # ========================================== st.set_page_config(page_title="Drunken Plane", page_icon="✈️", layout="wide") GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "").strip() if not GROQ_API_KEY and "GROQ_API_KEY" in st.secrets: GROQ_API_KEY = st.secrets["GROQ_API_KEY"].strip() SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "").strip() if not SHEET_URL and "PRIVATE_SHEET_URL" in st.secrets: SHEET_URL = st.secrets["PRIVATE_SHEET_URL"].strip() with st.sidebar: st.write("### πŸ”§ System Status") if GROQ_API_KEY and len(GROQ_API_KEY) > 10: st.success(f"🟒 API Key Ready") else: st.error("πŸ”΄ API Key Missing") if SHEET_URL: st.success("🟒 DB Connected") else: st.warning("🟠 Using Dummy Data") st.markdown(""" """, unsafe_allow_html=True) # ========================================== # πŸ’Ύ 2. 데이터 λ‘œλ“œ (μœ μ§€) # ========================================== PLACE_DB = {} DUMMY_DATA = { "Korea": [{"name": "Zest", "lat": 37.525, "lon": 127.040, "category": "Bar", "label": "🍸 World Best", "desc_ko": "μ„œμšΈ 졜고의 μΉ΅ν…ŒμΌ λ°”", "address": "μ„œμšΈ 강남ꡬ λ„μ‚°λŒ€λ‘œ55κΈΈ 26"}], "Malaysia": [{"name": "Bar Trigona", "lat": 3.159, "lon": 101.714, "category": "Bar", "label": "🐝 Sustainable", "desc_ko": "μΏ μ•ŒλΌλ£Έν‘Έλ₯΄μ˜ λŸ­μ…”λ¦¬ λ°”", "address": "Four Seasons Hotel, Kuala Lumpur"}], "Japan": [{"name": "Bar Benfiddich", "lat": 35.693, "lon": 139.699, "category": "Bar", "label": "🌿 Herbal", "desc_ko": "도쿄 μ‹ μ£ΌμΏ μ˜ μ•½μ΄ˆ μΉ΅ν…ŒμΌ λ°”", "address": "Tokyo, Shinjuku"}] } try: if SHEET_URL: response = requests.get(SHEET_URL, timeout=5) response.encoding = 'utf-8' response.raise_for_status() df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip') df = df.fillna("") df.columns = df.columns.str.strip() for col in df.select_dtypes(include=['object']).columns: df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True) if 'Country' in df.columns: df['Country'] = df['Country'].astype(str).str.strip() for country, group in df.groupby('Country'): if country and country.lower() != 'nan' and len(country) > 1: PLACE_DB[country] = group.fillna("").to_dict(orient='records') else: PLACE_DB = DUMMY_DATA except: PLACE_DB = DUMMY_DATA emily_base64 = "" if os.path.exists('emily.jpg'): try: with open("emily.jpg", "rb") as f: emily_base64 = base64.b64encode(f.read()).decode() except: pass db_json_str = json.dumps(PLACE_DB, ensure_ascii=False) db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8') # ========================================== # πŸ–₯️ 3. 톡합 ν”„λ‘ νŠΈμ—”λ“œ (λ²„νŠΌ 클릭 μ—λŸ¬ ν•€ν¬μΈνŠΈ μˆ˜μ •) # ========================================== html_template = """
🎫
πŸ‡°πŸ‡·
πŸ‡ΊπŸ‡Έ
πŸ‡―πŸ‡΅
πŸ‡¨πŸ‡³
DRUNKEN PLANE
Loading...
Please wait while Emily recalls this place... 🍸
""" html_code = html_template.replace("IMAGE_DATA", f"data:image/jpeg;base64,{emily_base64}") html_code = html_code.replace("DB_DATA_BASE64", db_base64) html_code = html_code.replace("GROQ_KEY_INJECTED", GROQ_API_KEY) components.html(html_code, height=1000, scrolling=True)