benjamin5607 commited on
Commit
b3f157b
Β·
verified Β·
1 Parent(s): 0d23016

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -35
app.py CHANGED
@@ -20,7 +20,7 @@ SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "").strip()
20
  if not SHEET_URL and "PRIVATE_SHEET_URL" in st.secrets:
21
  SHEET_URL = st.secrets["PRIVATE_SHEET_URL"].strip()
22
 
23
- # μƒνƒœ 확인
24
  with st.sidebar:
25
  st.write("### πŸ”§ System Status")
26
  if GROQ_API_KEY and len(GROQ_API_KEY) > 10:
@@ -42,10 +42,9 @@ st.markdown("""
42
  """, unsafe_allow_html=True)
43
 
44
  # ==========================================
45
- # πŸ’Ύ 2. 데이터 λ‘œλ“œ (도쿄 ν…ŒμŠ€νŠΈ 데이터 μΆ”κ°€)
46
  # ==========================================
47
  PLACE_DB = {}
48
- # [ν…ŒμŠ€νŠΈμš©] 도쿄 데이터 좔가함 (둜직 ν™•μΈμš©)
49
  DUMMY_DATA = {
50
  "Korea": [{"name": "Zest", "lat": 37.525, "lon": 127.040, "category": "Bar", "label": "🍸 World Best", "desc_ko": "μ„œμšΈ 졜고의 μΉ΅ν…ŒμΌ λ°”", "address": "μ„œμšΈ 강남ꡬ λ„μ‚°λŒ€λ‘œ55κΈΈ 26"}],
51
  "Malaysia": [{"name": "Bar Trigona", "lat": 3.159, "lon": 101.714, "category": "Bar", "label": "🐝 Sustainable", "desc_ko": "μΏ μ•ŒλΌλ£Έν‘Έλ₯΄μ˜ λŸ­μ…”λ¦¬ λ°”", "address": "Four Seasons Hotel, Kuala Lumpur"}],
@@ -83,7 +82,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
83
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
84
 
85
  # ==========================================
86
- # πŸ–₯️ 3. 톡합 ν”„λ‘ νŠΈμ—”λ“œ (이원화 둜직 μ •λ°€ 적용)
87
  # ==========================================
88
  html_template = """
89
  <!DOCTYPE html>
@@ -182,7 +181,7 @@ html_template = """
182
  const TRANSLATIONS = {
183
  "KO": { "ai": "Korean", "greet": "μ•ˆλ…•? μ˜€λŠ˜μ€ μ–΄λ””μ„œ ν•œμž”ν• κΉŒ?", "aiBtn": "AI 리뷰", "mapBtn": "지도", "filters": ["🌐 전체", "🏺 전톡주", "πŸ₯ƒ μœ„μŠ€ν‚€", "🍺 λ§₯μ£Ό", "🍷 와인", "🍹 λ°”"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
184
  "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"] },
185
- "JP": { "ai": "Japanese", "greet": "あら、ハニー. δ½•γ«γ™γ‚‹οΌŸ", "aiBtn": "AI レビγƒ₯γƒΌ", "mapBtn": "εœ°ε›³", "filters": ["🌐 全部", "🏺 伝硱酒", "πŸ₯ƒ ウむスキー", "🍺 ビール", "🍷 ワ인", "🍹 バー"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
186
  "CN": { "ai": "Chinese", "greet": "δΊ²ηˆ±ηš„, ζƒ³ε–η‚Ήδ»€δΉˆ?", "aiBtn": "AI η‚Ήθ―„", "mapBtn": "εœ°ε›Ύ", "filters": ["🌐 全部", "🏺 δΌ η»Ÿι…’", "πŸ₯ƒ 威士忌", "🍺 ε•€ι…’", "🍷 葑萄酒", "🍹 酒吧"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
187
  };
188
 
@@ -216,7 +215,14 @@ html_template = """
216
  } catch(e) { console.error(e); }
217
  };
218
 
219
- function setLanguage(l, el) { currentLang = l; document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); el.classList.add('active'); renderFilters(); renderList(); }
 
 
 
 
 
 
 
220
  function renderFilters() {
221
  const box = document.getElementById('filter-box'); box.innerHTML = "";
222
  TRANSLATIONS[currentLang].filters.forEach((f, i) => {
@@ -225,6 +231,7 @@ html_template = """
225
  box.appendChild(btn);
226
  });
227
  }
 
228
  function selectCountry(c) { selectedCountry = c; renderList(); }
229
 
230
  function renderList() {
@@ -253,11 +260,12 @@ html_template = """
253
  });
254
  }
255
 
 
256
  const ZOMBIE_MODELS = [
257
- "llama-3.3-70b-versatile",
258
- "llama-3.1-70b-versatile",
259
- "llama3-70b-8192",
260
- "mixtral-8x7b-32768"
261
  ];
262
 
263
  async function callGroq(msgs) {
@@ -274,12 +282,14 @@ html_template = """
274
 
275
  if (r.ok) {
276
  const d = await r.json(); return d.choices[0].message.content;
277
- } else if (r.status === 401) {
278
- return "Error 401: Invalid API Key.";
279
- }
 
 
280
  } catch(e) { continue; }
281
  }
282
- return "Emily is completely unavailable (All models failed).";
283
  }
284
 
285
  async function sendChat() {
@@ -287,16 +297,15 @@ html_template = """
287
  addChatMessage(msg, 'user'); inp.value = "";
288
  chatHistory.push({ role: "user", content: msg });
289
 
290
- // [이원화 둜직 핡심]
291
- // 1. 전체 DB 리슀트 (λ„μ‹œλ³„)
292
- let fullDbContext = "Here is the FULL MENU of places we know globally:\\n";
293
  for(let c in PLACE_DB) {
 
294
  let pNames = PLACE_DB[c].map(p => p.name).join(", ");
295
- fullDbContext += "- City/Country: " + c + " (Contains: " + pNames + ")\\n";
296
  }
297
 
298
- // 2. GPS 기반 20km 이내 리슀트
299
- let gpsContext = "NO GPS DATA available.";
300
  if(userLat && userLon) {
301
  let nearbyPlaces = [];
302
  for(let c in PLACE_DB) {
@@ -307,29 +316,21 @@ html_template = """
307
  }
308
  });
309
  }
310
- if(nearbyPlaces.length > 0) {
311
- gpsContext = "User is physically at " + userLat + "," + userLon + ". Places within 20km: " + nearbyPlaces.join(", ");
312
- } else {
313
- gpsContext = "User is physically at " + userLat + "," + userLon + ". BUT NO PLACES within 20km.";
314
- }
315
  }
316
 
317
- // 3. μ—λ°€λ¦¬μ—κ²Œ λ‚΄λ¦¬λŠ” κ°•λ ₯ν•œ μ§€μΉ¨
318
  const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
319
 
320
- [DATA SOURCE 1: GLOBAL DATABASE]
321
  ${fullDbContext}
322
 
323
- [DATA SOURCE 2: USER'S PHYSICAL LOCATION]
324
  ${gpsContext}
325
 
326
- [CRITICAL INSTRUCTION]
327
- Step 1: Did the user mention a specific city name from [DATA SOURCE 1]?
328
- -> YES: Recommend places ONLY from that city. Ignore [DATA SOURCE 2].
329
- -> NO: Did the user ask for recommendations nearby?
330
- -> YES: Recommend places from [DATA SOURCE 2].
331
-
332
- ALWAYS write place names inside [Brackets] like [Zest].`;
333
 
334
  const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
335
 
 
20
  if not SHEET_URL and "PRIVATE_SHEET_URL" in st.secrets:
21
  SHEET_URL = st.secrets["PRIVATE_SHEET_URL"].strip()
22
 
23
+ # μƒνƒœ ν‘œμ‹œ
24
  with st.sidebar:
25
  st.write("### πŸ”§ System Status")
26
  if GROQ_API_KEY and len(GROQ_API_KEY) > 10:
 
42
  """, unsafe_allow_html=True)
43
 
44
  # ==========================================
45
+ # πŸ’Ύ 2. 데이터 λ‘œλ“œ
46
  # ==========================================
47
  PLACE_DB = {}
 
48
  DUMMY_DATA = {
49
  "Korea": [{"name": "Zest", "lat": 37.525, "lon": 127.040, "category": "Bar", "label": "🍸 World Best", "desc_ko": "μ„œμšΈ 졜고의 μΉ΅ν…ŒμΌ λ°”", "address": "μ„œμšΈ 강남ꡬ λ„μ‚°λŒ€λ‘œ55κΈΈ 26"}],
50
  "Malaysia": [{"name": "Bar Trigona", "lat": 3.159, "lon": 101.714, "category": "Bar", "label": "🐝 Sustainable", "desc_ko": "μΏ μ•ŒλΌλ£Έν‘Έλ₯΄μ˜ λŸ­μ…”λ¦¬ λ°”", "address": "Four Seasons Hotel, Kuala Lumpur"}],
 
82
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
83
 
84
  # ==========================================
85
+ # πŸ–₯️ 3. 톡합 ν”„λ‘ νŠΈμ—”λ“œ (413/400 μ—λŸ¬ 해결을 μœ„ν•œ λͺ¨λΈ ꡐ체)
86
  # ==========================================
87
  html_template = """
88
  <!DOCTYPE html>
 
181
  const TRANSLATIONS = {
182
  "KO": { "ai": "Korean", "greet": "μ•ˆλ…•? μ˜€λŠ˜μ€ μ–΄λ””μ„œ ν•œμž”ν• κΉŒ?", "aiBtn": "AI 리뷰", "mapBtn": "지도", "filters": ["🌐 전체", "🏺 전톡주", "πŸ₯ƒ μœ„μŠ€ν‚€", "🍺 λ§₯μ£Ό", "🍷 와인", "🍹 λ°”"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
183
  "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"] },
184
+ "JP": { "ai": "Japanese", "greet": "あら、ハニー. δ½•γ«γ™γ‚‹οΌŸ", "aiBtn": "AI レビγƒ₯γƒΌ", "mapBtn": "εœ°ε›³", "filters": ["🌐 全部", "🏺 伝硱酒", "πŸ₯ƒ ウむス킀", "🍺 ビール", "🍷 ワむン", "🍹 バー"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] },
185
  "CN": { "ai": "Chinese", "greet": "δΊ²ηˆ±ηš„, ζƒ³ε–η‚Ήδ»€δΉˆ?", "aiBtn": "AI η‚Ήθ―„", "mapBtn": "εœ°ε›Ύ", "filters": ["🌐 全部", "🏺 δΌ η»Ÿι…’", "πŸ₯ƒ 威士忌", "🍺 ε•€ι…’", "🍷 葑萄酒", "🍹 酒吧"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
186
  };
187
 
 
215
  } catch(e) { console.error(e); }
216
  };
217
 
218
+ function setLanguage(l, el) {
219
+ currentLang = l;
220
+ document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
221
+ el.classList.add('active');
222
+ renderFilters();
223
+ renderList();
224
+ }
225
+
226
  function renderFilters() {
227
  const box = document.getElementById('filter-box'); box.innerHTML = "";
228
  TRANSLATIONS[currentLang].filters.forEach((f, i) => {
 
231
  box.appendChild(btn);
232
  });
233
  }
234
+
235
  function selectCountry(c) { selectedCountry = c; renderList(); }
236
 
237
  function renderList() {
 
260
  });
261
  }
262
 
263
+ // [핡심] 413/400 λ°©μ§€μš© μ’€λΉ„ λͺ¨λΈ 리슀트 (μ»¨ν…μŠ€νŠΈκ°€ 큰 μˆœμ„œλŒ€λ‘œ)
264
  const ZOMBIE_MODELS = [
265
+ "llama-3.3-70b-versatile", // 128k context (κ°€μž₯ 큼, 413 λ°©μ§€μš©)
266
+ "llama-3.1-70b-versatile", // 128k context
267
+ "mixtral-8x7b-32768", // 32k context
268
+ "llama-3.1-8b-instant" // 128k context (가볍고 빠름)
269
  ];
270
 
271
  async function callGroq(msgs) {
 
282
 
283
  if (r.ok) {
284
  const d = await r.json(); return d.choices[0].message.content;
285
+ }
286
+ // 413(μš©λŸ‰μ΄ˆκ³Ό), 400(μš”μ²­μ˜€λ₯˜)κ°€ 뜨면 λ‹€μŒ λͺ¨λΈλ‘œ λ„˜μ–΄κ°
287
+ // 401(ν‚€ 였λ₯˜)λ©΄ μ¦‰μ‹œ 멈좀
288
+ if (r.status === 401) return "Error 401: Invalid API Key.";
289
+
290
  } catch(e) { continue; }
291
  }
292
+ return "Emily is overloaded (Too much data). Try fewer requests.";
293
  }
294
 
295
  async function sendChat() {
 
297
  addChatMessage(msg, 'user'); inp.value = "";
298
  chatHistory.push({ role: "user", content: msg });
299
 
300
+ // [이원화 둜직 μœ μ§€]
301
+ let fullDbContext = "Here is the FULL MENU of places:\\n";
 
302
  for(let c in PLACE_DB) {
303
+ // 데이터 양을 쀄이기 μœ„ν•΄ ν•„μš”ν•œ μ •λ³΄λ§Œ μ΅œμ†Œν™”ν•˜μ—¬ 전솑 (413 λ°©μ§€)
304
  let pNames = PLACE_DB[c].map(p => p.name).join(", ");
305
+ fullDbContext += "- " + c + ": " + pNames + "\\n";
306
  }
307
 
308
+ let gpsContext = "NO GPS.";
 
309
  if(userLat && userLon) {
310
  let nearbyPlaces = [];
311
  for(let c in PLACE_DB) {
 
316
  }
317
  });
318
  }
319
+ if(nearbyPlaces.length > 0) gpsContext = "User GPS: " + userLat + "," + userLon + ". Nearby(20km): " + nearbyPlaces.join(", ");
 
 
 
 
320
  }
321
 
 
322
  const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
323
 
324
+ [GLOBAL DATA]
325
  ${fullDbContext}
326
 
327
+ [USER LOCATION]
328
  ${gpsContext}
329
 
330
+ [RULES]
331
+ 1. User asks for specific city? Use [GLOBAL DATA].
332
+ 2. User asks for 'nearby'? Use [USER LOCATION].
333
+ 3. ALWAYS format recommendations as [Place Name].`;
 
 
 
334
 
335
  const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
336