Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import requests
|
|
| 8 |
import io
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
-
# π οΈ 1. μ€μ λ° μν¬λ¦Ώ
|
| 12 |
# ==========================================
|
| 13 |
st.set_page_config(page_title="Drunken Plane", page_icon="βοΈ", layout="wide")
|
| 14 |
|
|
@@ -42,7 +42,7 @@ st.markdown("""
|
|
| 42 |
""", unsafe_allow_html=True)
|
| 43 |
|
| 44 |
# ==========================================
|
| 45 |
-
# πΎ 2. λ°μ΄ν° λ‘λ
|
| 46 |
# ==========================================
|
| 47 |
PLACE_DB = {}
|
| 48 |
DUMMY_DATA = {
|
|
@@ -82,7 +82,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>
|
|
@@ -181,7 +181,7 @@ html_template = """
|
|
| 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": ["π ε
¨ι¨", "πΊ δΌη΅±ι
", "π₯ γ¦γ€γΉγγΌ", "πΊ γγΌγ«", "π· γ―
|
| 185 |
"CN": { "ai": "Chinese", "greet": "δΊ²η±η, ζ³εηΉδ»δΉ?", "aiBtn": "AI ηΉθ―", "mapBtn": "ε°εΎ", "filters": ["π ε
¨ι¨", "πΊ δΌ η»ι
", "π₯ ε¨ε£«εΏ", "πΊ ε€ι
", "π· θ‘θι
", "πΉ ι
ε§"], "types": ["All", "Traditional", "Whiskey", "Beer", "Wine", "Bar"] }
|
| 186 |
};
|
| 187 |
|
|
@@ -283,7 +283,6 @@ html_template = """
|
|
| 283 |
const d = await r.json(); return d.choices[0].message.content;
|
| 284 |
}
|
| 285 |
if (r.status === 401) return "Error 401: Invalid API Key.";
|
| 286 |
-
// 413, 400 λ±μ λ€μ λͺ¨λΈ μλ
|
| 287 |
} catch(e) { continue; }
|
| 288 |
}
|
| 289 |
return "Emily is sleeping (Network Issue). Please try again.";
|
|
@@ -294,19 +293,15 @@ html_template = """
|
|
| 294 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 295 |
chatHistory.push({ role: "user", content: msg });
|
| 296 |
|
| 297 |
-
// [ν¨μΉ] λν κΈ°μ΅ λ¨κΈ°ν (μ΅κ·Ό 4κ°λ§ μ μ§) - 413 μλ¬ λ°©μ§
|
| 298 |
const recentHistory = chatHistory.slice(-4);
|
| 299 |
|
| 300 |
-
// [ν¨μΉ] λ°μ΄ν° μμΆ (νμν μ λ³΄λ§ λ¬Έμμ΄λ‘ μ°κ²°) - 413 μλ¬ λ°©μ§
|
| 301 |
let fullDbContext = "CITIES:\\n";
|
| 302 |
let placeCounts = 0;
|
| 303 |
for(let c in PLACE_DB) {
|
| 304 |
-
// μ΄λ¦λ§ μ½€λ§λ‘ μ°κ²°ν΄μ 보λ
|
| 305 |
let pNames = PLACE_DB[c].map(p => p.name).join(",");
|
| 306 |
fullDbContext += c + ": " + pNames + "\\n";
|
| 307 |
placeCounts += PLACE_DB[c].length;
|
| 308 |
}
|
| 309 |
-
// [ν¨μΉ] 물리μ κΈΈμ΄ μ ν (15000μ) - 413 μλ¬ μμ² λ΄μ
|
| 310 |
if(fullDbContext.length > 15000) fullDbContext = fullDbContext.substring(0, 15000) + "...(truncated)";
|
| 311 |
|
| 312 |
let gpsContext = "No GPS.";
|
|
@@ -323,6 +318,7 @@ html_template = """
|
|
| 323 |
if(nearbyPlaces.length > 0) gpsContext = "GPS Nearby(20km): " + nearbyPlaces.join(", ");
|
| 324 |
}
|
| 325 |
|
|
|
|
| 326 |
const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
|
| 327 |
|
| 328 |
[DB]
|
|
@@ -334,9 +330,8 @@ html_template = """
|
|
| 334 |
[RULES]
|
| 335 |
1. User asks specific city? Use [DB].
|
| 336 |
2. User asks nearby? Use [USER GPS].
|
| 337 |
-
3.
|
| 338 |
|
| 339 |
-
// μμΆλ ν둬ννΈμ μ§§μ λν κΈ°λ‘ μ μ‘
|
| 340 |
const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...recentHistory]);
|
| 341 |
|
| 342 |
let finalHtml = botMsg;
|
|
|
|
| 8 |
import io
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
+
# π οΈ 1. μ€μ λ° μν¬λ¦Ώ (μ μ§)
|
| 12 |
# ==========================================
|
| 13 |
st.set_page_config(page_title="Drunken Plane", page_icon="βοΈ", layout="wide")
|
| 14 |
|
|
|
|
| 42 |
""", unsafe_allow_html=True)
|
| 43 |
|
| 44 |
# ==========================================
|
| 45 |
+
# πΎ 2. λ°μ΄ν° λ‘λ (μ μ§)
|
| 46 |
# ==========================================
|
| 47 |
PLACE_DB = {}
|
| 48 |
DUMMY_DATA = {
|
|
|
|
| 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>
|
|
|
|
| 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 |
|
|
|
|
| 283 |
const d = await r.json(); return d.choices[0].message.content;
|
| 284 |
}
|
| 285 |
if (r.status === 401) return "Error 401: Invalid API Key.";
|
|
|
|
| 286 |
} catch(e) { continue; }
|
| 287 |
}
|
| 288 |
return "Emily is sleeping (Network Issue). Please try again.";
|
|
|
|
| 293 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 294 |
chatHistory.push({ role: "user", content: msg });
|
| 295 |
|
|
|
|
| 296 |
const recentHistory = chatHistory.slice(-4);
|
| 297 |
|
|
|
|
| 298 |
let fullDbContext = "CITIES:\\n";
|
| 299 |
let placeCounts = 0;
|
| 300 |
for(let c in PLACE_DB) {
|
|
|
|
| 301 |
let pNames = PLACE_DB[c].map(p => p.name).join(",");
|
| 302 |
fullDbContext += c + ": " + pNames + "\\n";
|
| 303 |
placeCounts += PLACE_DB[c].length;
|
| 304 |
}
|
|
|
|
| 305 |
if(fullDbContext.length > 15000) fullDbContext = fullDbContext.substring(0, 15000) + "...(truncated)";
|
| 306 |
|
| 307 |
let gpsContext = "No GPS.";
|
|
|
|
| 318 |
if(nearbyPlaces.length > 0) gpsContext = "GPS Nearby(20km): " + nearbyPlaces.join(", ");
|
| 319 |
}
|
| 320 |
|
| 321 |
+
// [μμ λ ν둬ννΈ] λ§ν¬ μμ±μ μν κ°λ ₯ν μ§μΉ¨ μΆκ°
|
| 322 |
const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
|
| 323 |
|
| 324 |
[DB]
|
|
|
|
| 330 |
[RULES]
|
| 331 |
1. User asks specific city? Use [DB].
|
| 332 |
2. User asks nearby? Use [USER GPS].
|
| 333 |
+
3. CRITICAL: You MUST wrap EXACT place names in [square brackets] to create links. Example: "You should visit [Zest]."`;
|
| 334 |
|
|
|
|
| 335 |
const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...recentHistory]);
|
| 336 |
|
| 337 |
let finalHtml = botMsg;
|