benjamin5607 commited on
Commit
b0d20fa
ยท
verified ยท
1 Parent(s): 4379084

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -27
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
- # ํ‚ค ๊ฐ€์ ธ์˜ค๊ธฐ (๊ณต๋ฐฑ ์ œ๊ฑฐ .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,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 Check")
27
  if GROQ_API_KEY and len(GROQ_API_KEY) > 10:
28
- st.success(f"๐ŸŸข API Key Loaded ({GROQ_API_KEY[:4]}...)")
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 12px; border-radius: 20px; cursor: pointer; font-size: 14px; font-weight: bold; transition: 0.3s; }
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": ["๐ŸŒ ๅ…จ้ƒจ", "๐Ÿบ ไผ็ตฑ้…’", "๐Ÿฅƒ ใ‚ฆใ‚คใ‚นใ‚ญใƒผ", "๐Ÿบ ใƒ“ใƒผใƒซ", "๐Ÿท ใƒฏใ‚คใƒณ", "๐Ÿน ใƒใƒผ"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
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 ํ˜ธ์ถœ - ๋ชจ๋ธ๋ช…์„ ์ตœ์‹  ํ‘œ์ค€ํ˜•(llama3-70b-8192)์œผ๋กœ ๋ณ€๊ฒฝ + ํŠธ๋ฆผ ์ ์šฉ
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: "llama3-70b-8192", messages: msgs, temperature: 0.7 })
281
  });
282
 
283
  if (!r.ok) {
 
284
  if(r.status === 401) return "Error 401: Unauthorized (Check Key)";
285
- if(r.status === 400) return "Error 400: Bad Request (Model or Key format)";
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) {