Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,11 +8,11 @@ import requests
|
|
| 8 |
import io
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
-
# ๐ ๏ธ 1. ์ค์ ๋ฐ ์ํฌ๋ฆฟ (
|
| 12 |
# ==========================================
|
| 13 |
st.set_page_config(page_title="Drunken Plane", page_icon="โ๏ธ", layout="wide")
|
| 14 |
|
| 15 |
-
#
|
| 16 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "").strip()
|
| 17 |
if not GROQ_API_KEY and "GROQ_API_KEY" in st.secrets:
|
| 18 |
GROQ_API_KEY = st.secrets["GROQ_API_KEY"].strip()
|
|
@@ -21,13 +21,14 @@ SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "").strip()
|
|
| 21 |
if not SHEET_URL and "PRIVATE_SHEET_URL" in st.secrets:
|
| 22 |
SHEET_URL = st.secrets["PRIVATE_SHEET_URL"].strip()
|
| 23 |
|
| 24 |
-
# [๋๋ฒ๊น
] ์ฌ์ด๋๋ฐ ์ํ
|
| 25 |
with st.sidebar:
|
| 26 |
-
st.write("### ๐ง System
|
| 27 |
if GROQ_API_KEY and len(GROQ_API_KEY) > 10:
|
| 28 |
-
st.success(f"๐ข API Key
|
| 29 |
else:
|
| 30 |
st.error("๐ด API Key Missing")
|
|
|
|
| 31 |
|
| 32 |
if SHEET_URL:
|
| 33 |
st.success("๐ข DB Connected")
|
|
@@ -43,7 +44,7 @@ st.markdown("""
|
|
| 43 |
""", unsafe_allow_html=True)
|
| 44 |
|
| 45 |
# ==========================================
|
| 46 |
-
# ๐พ 2. ๋ฐ์ดํฐ ๋ก๋
|
| 47 |
# ==========================================
|
| 48 |
PLACE_DB = {}
|
| 49 |
DUMMY_DATA = {
|
|
@@ -57,18 +58,22 @@ try:
|
|
| 57 |
response.encoding = 'utf-8'
|
| 58 |
response.raise_for_status()
|
| 59 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 60 |
-
df = df.fillna("")
|
| 61 |
df.columns = df.columns.str.strip()
|
|
|
|
|
|
|
| 62 |
for col in df.select_dtypes(include=['object']).columns:
|
| 63 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
|
|
|
| 64 |
if 'Country' in df.columns:
|
| 65 |
df['Country'] = df['Country'].astype(str).str.strip()
|
| 66 |
for country, group in df.groupby('Country'):
|
|
|
|
| 67 |
if country and country.lower() != 'nan' and len(country) > 1:
|
| 68 |
PLACE_DB[country] = group.fillna("").to_dict(orient='records')
|
| 69 |
else:
|
| 70 |
PLACE_DB = DUMMY_DATA
|
| 71 |
-
except:
|
| 72 |
PLACE_DB = DUMMY_DATA
|
| 73 |
|
| 74 |
emily_base64 = ""
|
|
@@ -82,7 +87,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
|
| 82 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 83 |
|
| 84 |
# ==========================================
|
| 85 |
-
# ๐ฅ๏ธ 3. ํตํฉ ํ๋ก ํธ์๋ (
|
| 86 |
# ==========================================
|
| 87 |
html_template = """
|
| 88 |
<!DOCTYPE html>
|
|
@@ -97,13 +102,13 @@ html_template = """
|
|
| 97 |
body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
|
| 98 |
.page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
|
| 99 |
|
| 100 |
-
/* [๋ณต
|
| 101 |
-
.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); }
|
| 102 |
.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); }
|
| 103 |
|
| 104 |
.lang-switcher { display: flex; gap: 8px; }
|
| 105 |
-
.lang-btn { background: rgba(0,0,0,0.6); border: 1px solid #444; color: #888; padding: 5px
|
| 106 |
-
.lang-btn.active { background: var(--gold); color: black; border-color: var(--gold); transform: scale(1.1); }
|
| 107 |
|
| 108 |
.type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; scrollbar-width: none; }
|
| 109 |
.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; }
|
|
@@ -111,10 +116,13 @@ html_template = """
|
|
| 111 |
|
| 112 |
.place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
|
| 113 |
.place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; }
|
|
|
|
|
|
|
| 114 |
.pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
| 115 |
.pc-name { font-size: 18px; font-weight: bold; color: var(--gold); flex: 1; }
|
| 116 |
.pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
|
| 117 |
.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; }
|
|
|
|
| 118 |
.pc-desc { font-size: 13px; color: #aaa; margin: 10px 0; line-height: 1.5; }
|
| 119 |
.btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
|
| 120 |
|
|
@@ -147,7 +155,6 @@ html_template = """
|
|
| 147 |
<div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">๐จ๐ณ</div>
|
| 148 |
</div>
|
| 149 |
</div>
|
| 150 |
-
|
| 151 |
<div style="text-align:center; padding: 5px 0 15px 0;">
|
| 152 |
<div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
|
| 153 |
<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>
|
|
@@ -183,7 +190,7 @@ html_template = """
|
|
| 183 |
const TRANSLATIONS = {
|
| 184 |
"KO": { "ai": "Korean", "greet": "์๋
? ์ค๋์ ์ด๋์ ํ์ํ ๊น?", "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapBtn": "์ง๋", "filters": ["๐ ์ ์ฒด", "๐บ ์ ํต์ฃผ", "๐ฅ ์์คํค", "๐บ ๋งฅ์ฃผ", "๐ท ์์ธ", "๐น ๋ฐ"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
|
| 185 |
"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"] },
|
| 186 |
-
"JP": { "ai": "Japanese", "greet": "ใใใใใใผ. ไฝใซใใ๏ผ", "aiBtn": "AI ใฌใใฅใผ", "mapBtn": "ๅฐๅณ", "filters": ["๐ ๅ
จ้จ", "๐บ ไผ็ตฑ้
", "๐ฅ ใฆใคในใญใผ", "๐บ ใใผใซ", "๐ท ใฏ
|
| 187 |
"CN": { "ai": "Chinese", "greet": "ไบฒ็ฑ็, ๆณๅ็นไปไน?", "aiBtn": "AI ็น่ฏ", "mapBtn": "ๅฐๅพ", "filters": ["๐ ๅ
จ้จ", "๐บ ไผ ็ป้
", "๐ฅ ๅจๅฃซๅฟ", "๐บ ๅค้
", "๐ท ่ก่้
", "๐น ้
ๅง"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
|
| 188 |
};
|
| 189 |
|
|
@@ -221,8 +228,6 @@ html_template = """
|
|
| 221 |
currentLang = l;
|
| 222 |
document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
|
| 223 |
el.classList.add('active');
|
| 224 |
-
|
| 225 |
-
// [์ค์] ํํฐ ์ด๋ฆ๋ ์ธ์ด์ ๋ง๊ฒ ๊ฐฑ์
|
| 226 |
renderFilters();
|
| 227 |
renderList();
|
| 228 |
}
|
|
@@ -246,13 +251,17 @@ html_template = """
|
|
| 246 |
|
| 247 |
filtered.forEach(p => {
|
| 248 |
const card = document.createElement('div'); card.className = 'place-card';
|
|
|
|
| 249 |
const displayLabel = p.label || p.category || "";
|
| 250 |
const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
|
|
|
|
|
|
|
| 251 |
let distHtml = "";
|
| 252 |
if(userLat && userLon && p.lat && p.lon) {
|
| 253 |
const dist = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
|
| 254 |
distHtml = `<span class="pc-dist">(๐ ${dist}km)</span>`;
|
| 255 |
}
|
|
|
|
| 256 |
card.innerHTML = `
|
| 257 |
<div class="pc-header"><div class="pc-name">${p.name} ${distHtml}</div><div class="pc-label">${displayLabel}</div></div>
|
| 258 |
<div class="pc-desc">${desc}</div>
|
|
@@ -264,26 +273,23 @@ html_template = """
|
|
| 264 |
});
|
| 265 |
}
|
| 266 |
|
| 267 |
-
// [์ค์] API ํธ์ถ - ๋ชจ๋ธ
|
| 268 |
async function callGroq(msgs) {
|
| 269 |
-
let apiKey = "GROQ_KEY_INJECTED".trim();
|
| 270 |
-
|
| 271 |
-
if(!apiKey || apiKey.includes("INJECTED") || apiKey.length < 10) {
|
| 272 |
-
return "Emily Error: 400 (Please check API Key in HF Settings)";
|
| 273 |
-
}
|
| 274 |
|
| 275 |
try {
|
| 276 |
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
| 277 |
method: "POST",
|
| 278 |
headers: { "Content-Type": "application/json", "Authorization": "Bearer " + apiKey },
|
| 279 |
-
// [๋ณ๊ฒฝ]
|
| 280 |
-
body: JSON.stringify({ model: "
|
| 281 |
});
|
| 282 |
|
| 283 |
if (!r.ok) {
|
|
|
|
| 284 |
if(r.status === 401) return "Error 401: Unauthorized (Check Key)";
|
| 285 |
-
if(r.status ===
|
| 286 |
-
if(r.status === 429) return "Emily is busy (Too many requests)";
|
| 287 |
return "Emily Error: " + r.status;
|
| 288 |
}
|
| 289 |
const d = await r.json(); return d.choices[0].message.content;
|
|
@@ -295,6 +301,7 @@ html_template = """
|
|
| 295 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 296 |
chatHistory.push({ role: "user", content: msg });
|
| 297 |
|
|
|
|
| 298 |
let nearbyContext = "";
|
| 299 |
let cityContext = " [DB Cities: " + Object.keys(PLACE_DB).join(", ") + "]";
|
| 300 |
if(userLat && userLon) {
|
|
|
|
| 8 |
import io
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
+
# ๐ ๏ธ 1. ์ค์ ๋ฐ ์ํฌ๋ฆฟ (ํ๊น
ํ์ด์ค ์๋ฒฝ ํธํ)
|
| 12 |
# ==========================================
|
| 13 |
st.set_page_config(page_title="Drunken Plane", page_icon="โ๏ธ", layout="wide")
|
| 14 |
|
| 15 |
+
# ๊ณต๋ฐฑ ์ ๊ฑฐ(.strip)๋ฅผ ํฌํจํ์ฌ ํค ๋ก๋ฉ ์์ ์ฑ ํ๋ณด
|
| 16 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "").strip()
|
| 17 |
if not GROQ_API_KEY and "GROQ_API_KEY" in st.secrets:
|
| 18 |
GROQ_API_KEY = st.secrets["GROQ_API_KEY"].strip()
|
|
|
|
| 21 |
if not SHEET_URL and "PRIVATE_SHEET_URL" in st.secrets:
|
| 22 |
SHEET_URL = st.secrets["PRIVATE_SHEET_URL"].strip()
|
| 23 |
|
| 24 |
+
# [๋๋ฒ๊น
] ์ฌ์ด๋๋ฐ์ ์ํ ํ์
|
| 25 |
with st.sidebar:
|
| 26 |
+
st.write("### ๐ง System Status")
|
| 27 |
if GROQ_API_KEY and len(GROQ_API_KEY) > 10:
|
| 28 |
+
st.success(f"๐ข API Key Ready ({GROQ_API_KEY[:4]}...)")
|
| 29 |
else:
|
| 30 |
st.error("๐ด API Key Missing")
|
| 31 |
+
st.info("HF Settings > Secrets ์์ 'GROQ_API_KEY'๋ฅผ ํ์ธํ์ธ์.")
|
| 32 |
|
| 33 |
if SHEET_URL:
|
| 34 |
st.success("๐ข DB Connected")
|
|
|
|
| 44 |
""", unsafe_allow_html=True)
|
| 45 |
|
| 46 |
# ==========================================
|
| 47 |
+
# ๐พ 2. ๋ฐ์ดํฐ ๋ก๋ (๊นกํต ์ ๊ฑฐ + ์์ธ ์ฒ๋ฆฌ)
|
| 48 |
# ==========================================
|
| 49 |
PLACE_DB = {}
|
| 50 |
DUMMY_DATA = {
|
|
|
|
| 58 |
response.encoding = 'utf-8'
|
| 59 |
response.raise_for_status()
|
| 60 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 61 |
+
df = df.fillna("") # undefined ๋ฐฉ์ง
|
| 62 |
df.columns = df.columns.str.strip()
|
| 63 |
+
|
| 64 |
+
# JS ์ค๋ฅ ๋ฐฉ์ง๋ฅผ ์ํ ํ
์คํธ ์ธํ
|
| 65 |
for col in df.select_dtypes(include=['object']).columns:
|
| 66 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 67 |
+
|
| 68 |
if 'Country' in df.columns:
|
| 69 |
df['Country'] = df['Country'].astype(str).str.strip()
|
| 70 |
for country, group in df.groupby('Country'):
|
| 71 |
+
# [๋ณต์] ๊นกํต ๊ตญ๊ฐ ์ ๊ฑฐ ๋ก์ง
|
| 72 |
if country and country.lower() != 'nan' and len(country) > 1:
|
| 73 |
PLACE_DB[country] = group.fillna("").to_dict(orient='records')
|
| 74 |
else:
|
| 75 |
PLACE_DB = DUMMY_DATA
|
| 76 |
+
except Exception:
|
| 77 |
PLACE_DB = DUMMY_DATA
|
| 78 |
|
| 79 |
emily_base64 = ""
|
|
|
|
| 87 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 88 |
|
| 89 |
# ==========================================
|
| 90 |
+
# ๐ฅ๏ธ 3. ํตํฉ ํ๋ก ํธ์๋ (์ ๊ธฐ๋ฅ ๋ณต์ ์๋ฃ)
|
| 91 |
# ==========================================
|
| 92 |
html_template = """
|
| 93 |
<!DOCTYPE html>
|
|
|
|
| 102 |
body { margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }
|
| 103 |
.page { position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }
|
| 104 |
|
| 105 |
+
/* [๋ณต์] ์๋จ ๋ค๋น๊ฒ์ด์
& ์ธ์ด ๋ฒํผ */
|
| 106 |
+
.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); border-bottom: 1px solid #333; }
|
| 107 |
.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); }
|
| 108 |
|
| 109 |
.lang-switcher { display: flex; gap: 8px; }
|
| 110 |
+
.lang-btn { background: rgba(0,0,0,0.6); border: 1px solid #444; color: #888; padding: 5px 10px; border-radius: 20px; cursor: pointer; font-size: 16px; transition: 0.3s; }
|
| 111 |
+
.lang-btn.active { background: var(--gold); color: black; border-color: var(--gold); transform: scale(1.1); font-weight: bold; }
|
| 112 |
|
| 113 |
.type-filter-container { width: 100%; padding: 10px 0; overflow-x: auto; display: flex; gap: 8px; justify-content: center; scrollbar-width: none; }
|
| 114 |
.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; }
|
|
|
|
| 116 |
|
| 117 |
.place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
|
| 118 |
.place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; }
|
| 119 |
+
|
| 120 |
+
/* [๋ณต์] ๋ผ๋ฒจ ๋ฐ ๊ฑฐ๋ฆฌ ํ์ */
|
| 121 |
.pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
| 122 |
.pc-name { font-size: 18px; font-weight: bold; color: var(--gold); flex: 1; }
|
| 123 |
.pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
|
| 124 |
.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; }
|
| 125 |
+
|
| 126 |
.pc-desc { font-size: 13px; color: #aaa; margin: 10px 0; line-height: 1.5; }
|
| 127 |
.btn-action { flex: 1; padding: 12px; border-radius: 10px; border: none; font-weight: bold; cursor: pointer; font-size: 12px; }
|
| 128 |
|
|
|
|
| 155 |
<div class="lang-btn" id="btn-CN" onclick="setLanguage('CN', this)">๐จ๐ณ</div>
|
| 156 |
</div>
|
| 157 |
</div>
|
|
|
|
| 158 |
<div style="text-align:center; padding: 5px 0 15px 0;">
|
| 159 |
<div style="color:var(--gold); font-size: 26px; font-weight: 900; letter-spacing: 4px;">DRUNKEN PLANE</div>
|
| 160 |
<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>
|
|
|
|
| 190 |
const TRANSLATIONS = {
|
| 191 |
"KO": { "ai": "Korean", "greet": "์๋
? ์ค๋์ ์ด๋์ ํ์ํ ๊น?", "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapBtn": "์ง๋", "filters": ["๐ ์ ์ฒด", "๐บ ์ ํต์ฃผ", "๐ฅ ์์คํค", "๐บ ๋งฅ์ฃผ", "๐ท ์์ธ", "๐น ๋ฐ"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
|
| 192 |
"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"] },
|
| 193 |
+
"JP": { "ai": "Japanese", "greet": "ใใใใใใผ. ไฝใซใใ๏ผ", "aiBtn": "AI ใฌใใฅใผ", "mapBtn": "ๅฐๅณ", "filters": ["๐ ๅ
จ้จ", "๐บ ไผ็ตฑ้
", "๐ฅ ใฆใคในใญใผ", "๐บ ใใผใซ", "๐ท ใฏ์ธ", "๐น ใใผ"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
|
| 194 |
"CN": { "ai": "Chinese", "greet": "ไบฒ็ฑ็, ๆณๅ็นไปไน?", "aiBtn": "AI ็น่ฏ", "mapBtn": "ๅฐๅพ", "filters": ["๐ ๅ
จ้จ", "๐บ ไผ ็ป้
", "๐ฅ ๅจๅฃซๅฟ", "๐บ ๅค้
", "๐ท ่ก่้
", "๐น ้
ๅง"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
|
| 195 |
};
|
| 196 |
|
|
|
|
| 228 |
currentLang = l;
|
| 229 |
document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
|
| 230 |
el.classList.add('active');
|
|
|
|
|
|
|
| 231 |
renderFilters();
|
| 232 |
renderList();
|
| 233 |
}
|
|
|
|
| 251 |
|
| 252 |
filtered.forEach(p => {
|
| 253 |
const card = document.createElement('div'); card.className = 'place-card';
|
| 254 |
+
// undefined ๋ฐฉ์ง
|
| 255 |
const displayLabel = p.label || p.category || "";
|
| 256 |
const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
|
| 257 |
+
|
| 258 |
+
// [๋ณต์] ๊ฑฐ๋ฆฌ ๊ณ์ฐ
|
| 259 |
let distHtml = "";
|
| 260 |
if(userLat && userLon && p.lat && p.lon) {
|
| 261 |
const dist = getDistanceFromLatLonInKm(userLat, userLon, p.lat, p.lon);
|
| 262 |
distHtml = `<span class="pc-dist">(๐ ${dist}km)</span>`;
|
| 263 |
}
|
| 264 |
+
|
| 265 |
card.innerHTML = `
|
| 266 |
<div class="pc-header"><div class="pc-name">${p.name} ${distHtml}</div><div class="pc-label">${displayLabel}</div></div>
|
| 267 |
<div class="pc-desc">${desc}</div>
|
|
|
|
| 273 |
});
|
| 274 |
}
|
| 275 |
|
| 276 |
+
// [์ค์] API ํธ์ถ - ์ต์ ๋ชจ๋ธ ์ ์ฉ (llama-3.3-70b-versatile) ๋ฐ 400 ์๋ฌ ๋ฐฉ์ง
|
| 277 |
async function callGroq(msgs) {
|
| 278 |
+
let apiKey = "GROQ_KEY_INJECTED".trim();
|
| 279 |
+
if(!apiKey || apiKey.length < 5) return "Error: API Key is missing. (Code 400)";
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
try {
|
| 282 |
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
| 283 |
method: "POST",
|
| 284 |
headers: { "Content-Type": "application/json", "Authorization": "Bearer " + apiKey },
|
| 285 |
+
// [๋ณ๊ฒฝ] ์ต์ ์์ ๋ชจ๋ธ๋ก ๊ต์ฒด
|
| 286 |
+
body: JSON.stringify({ model: "llama-3.3-70b-versatile", messages: msgs, temperature: 0.7 })
|
| 287 |
});
|
| 288 |
|
| 289 |
if (!r.ok) {
|
| 290 |
+
if(r.status === 400) return "Error 400: Bad Request (Check Model Name/JSON)";
|
| 291 |
if(r.status === 401) return "Error 401: Unauthorized (Check Key)";
|
| 292 |
+
if(r.status === 429) return "Emily is busy (Rate Limit)";
|
|
|
|
| 293 |
return "Emily Error: " + r.status;
|
| 294 |
}
|
| 295 |
const d = await r.json(); return d.choices[0].message.content;
|
|
|
|
| 301 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 302 |
chatHistory.push({ role: "user", content: msg });
|
| 303 |
|
| 304 |
+
// [๋ณต์] ์ค๋งํธ ์ปจํ
์คํธ (๊ฑฐ๋ฆฌ 20km vs ๋์ ์ ์ฒด)
|
| 305 |
let nearbyContext = "";
|
| 306 |
let cityContext = " [DB Cities: " + Object.keys(PLACE_DB).join(", ") + "]";
|
| 307 |
if(userLat && userLon) {
|