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. ํตํฉ ํ๋ก ํธ์๋ (413
|
| 86 |
# ==========================================
|
| 87 |
html_template = """
|
| 88 |
<!DOCTYPE html>
|
|
@@ -260,12 +260,12 @@ html_template = """
|
|
| 260 |
});
|
| 261 |
}
|
| 262 |
|
| 263 |
-
//
|
| 264 |
const ZOMBIE_MODELS = [
|
| 265 |
-
"llama-3.3-70b-versatile",
|
| 266 |
-
"llama-3.1-70b-versatile",
|
| 267 |
-
"mixtral-8x7b-32768",
|
| 268 |
-
"llama-3.1-8b-instant"
|
| 269 |
];
|
| 270 |
|
| 271 |
async function callGroq(msgs) {
|
|
@@ -283,13 +283,11 @@ html_template = """
|
|
| 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
|
| 293 |
}
|
| 294 |
|
| 295 |
async function sendChat() {
|
|
@@ -297,10 +295,13 @@ html_template = """
|
|
| 297 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 298 |
chatHistory.push({ role: "user", content: msg });
|
| 299 |
|
| 300 |
-
// [
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
| 302 |
for(let c in PLACE_DB) {
|
| 303 |
-
// ๋ฐ์ดํฐ ์์ ์ค์ด๊ธฐ ์ํด ํ์ํ ์ ๋ณด๋ง ์ต์ํ
|
| 304 |
let pNames = PLACE_DB[c].map(p => p.name).join(", ");
|
| 305 |
fullDbContext += "- " + c + ": " + pNames + "\\n";
|
| 306 |
}
|
|
@@ -316,7 +317,7 @@ html_template = """
|
|
| 316 |
}
|
| 317 |
});
|
| 318 |
}
|
| 319 |
-
if(nearbyPlaces.length > 0) gpsContext = "User
|
| 320 |
}
|
| 321 |
|
| 322 |
const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
|
|
@@ -324,15 +325,16 @@ html_template = """
|
|
| 324 |
[GLOBAL DATA]
|
| 325 |
${fullDbContext}
|
| 326 |
|
| 327 |
-
[USER
|
| 328 |
${gpsContext}
|
| 329 |
|
| 330 |
[RULES]
|
| 331 |
1. User asks for specific city? Use [GLOBAL DATA].
|
| 332 |
-
2. User asks for 'nearby'? Use [USER
|
| 333 |
3. ALWAYS format recommendations as [Place Name].`;
|
| 334 |
|
| 335 |
-
|
|
|
|
| 336 |
|
| 337 |
let finalHtml = botMsg;
|
| 338 |
const regex = /\[(.*?)\]/g;
|
|
|
|
| 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. ํตํฉ ํ๋ก ํธ์๋ (413 ์๋ฌ ํจ์น ์ ์ฉ)
|
| 86 |
# ==========================================
|
| 87 |
html_template = """
|
| 88 |
<!DOCTYPE html>
|
|
|
|
| 260 |
});
|
| 261 |
}
|
| 262 |
|
| 263 |
+
// 413 ์๋ฌ ๋ฐฉ์ง์ฉ ์ข๋น ๋ชจ๋ธ (์ปจํ
์คํธ ํฐ ์์)
|
| 264 |
const ZOMBIE_MODELS = [
|
| 265 |
+
"llama-3.3-70b-versatile",
|
| 266 |
+
"llama-3.1-70b-versatile",
|
| 267 |
+
"mixtral-8x7b-32768",
|
| 268 |
+
"llama-3.1-8b-instant"
|
| 269 |
];
|
| 270 |
|
| 271 |
async function callGroq(msgs) {
|
|
|
|
| 283 |
if (r.ok) {
|
| 284 |
const d = await r.json(); return d.choices[0].message.content;
|
| 285 |
}
|
|
|
|
|
|
|
| 286 |
if (r.status === 401) return "Error 401: Invalid API Key.";
|
| 287 |
+
// 413, 400 ๋ฑ์ ๋ค์ ๋ชจ๋ธ ์๋
|
| 288 |
} catch(e) { continue; }
|
| 289 |
}
|
| 290 |
+
return "Emily is unavailable (Server overload). Try again later.";
|
| 291 |
}
|
| 292 |
|
| 293 |
async function sendChat() {
|
|
|
|
| 295 |
addChatMessage(msg, 'user'); inp.value = "";
|
| 296 |
chatHistory.push({ role: "user", content: msg });
|
| 297 |
|
| 298 |
+
// [ํต์ฌ ํจ์น] 413 ์๋ฌ ๋ฐฉ์ง: ๋ํ ๊ธฐ๋ก์ด ๋๋ฌด ๊ธธ์ด์ง๋ฉด ์ต๊ทผ 6๊ฐ(3ํด)๋ง ์๋ฅธ๋ค.
|
| 299 |
+
const MAX_HISTORY = 6;
|
| 300 |
+
const recentHistory = chatHistory.slice(-MAX_HISTORY);
|
| 301 |
+
|
| 302 |
+
let fullDbContext = "MENU:\\n";
|
| 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 |
}
|
|
|
|
| 317 |
}
|
| 318 |
});
|
| 319 |
}
|
| 320 |
+
if(nearbyPlaces.length > 0) gpsContext = "GPS User Loc: " + userLat + "," + userLon + ". Nearby(20km): " + nearbyPlaces.join(", ");
|
| 321 |
}
|
| 322 |
|
| 323 |
const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
|
|
|
|
| 325 |
[GLOBAL DATA]
|
| 326 |
${fullDbContext}
|
| 327 |
|
| 328 |
+
[USER GPS]
|
| 329 |
${gpsContext}
|
| 330 |
|
| 331 |
[RULES]
|
| 332 |
1. User asks for specific city? Use [GLOBAL DATA].
|
| 333 |
+
2. User asks for 'nearby'? Use [USER GPS].
|
| 334 |
3. ALWAYS format recommendations as [Place Name].`;
|
| 335 |
|
| 336 |
+
// [ํจ์น] ์ ์ฒด ๊ธฐ๋ก ๋์ ์ต๊ทผ ๊ธฐ๋ก๋ง ์ ์ก
|
| 337 |
+
const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...recentHistory]);
|
| 338 |
|
| 339 |
let finalHtml = botMsg;
|
| 340 |
const regex = /\[(.*?)\]/g;
|