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 = """