Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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": ["π ε
¨ι¨", "πΊ δΌη΅±ι
", "π₯ γ¦γ€γΉ
|
| 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) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
"
|
| 260 |
-
"
|
| 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 |
-
}
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
| 280 |
} catch(e) { continue; }
|
| 281 |
}
|
| 282 |
-
return "Emily is
|
| 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 |
-
|
| 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 += "-
|
| 296 |
}
|
| 297 |
|
| 298 |
-
|
| 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 |
-
[
|
| 321 |
${fullDbContext}
|
| 322 |
|
| 323 |
-
[
|
| 324 |
${gpsContext}
|
| 325 |
|
| 326 |
-
[
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 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 |
|