Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ SHEET_URL = os.environ.get("PRIVATE_SHEET_URL", "")
|
|
| 15 |
|
| 16 |
st.set_page_config(page_title="Drunken Plane", page_icon="โ๏ธ", layout="wide")
|
| 17 |
|
| 18 |
-
# CSS ์ค๊ดํธ๋
|
| 19 |
st.markdown("""
|
| 20 |
<style>
|
| 21 |
.block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
|
|
@@ -35,7 +35,7 @@ try:
|
|
| 35 |
response.raise_for_status()
|
| 36 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 37 |
|
| 38 |
-
# ๋ฌธ์์ด ์ ์ (JS ๋ฌธ๋ฒ ์ถฉ๋ ๋ฐฉ์ง)
|
| 39 |
for col in df.select_dtypes(include=['object']).columns:
|
| 40 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 41 |
|
|
@@ -60,9 +60,8 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
|
|
| 60 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 61 |
|
| 62 |
# ==========================================
|
| 63 |
-
# 3. ํตํฉ ํ๋ก ํธ์๋ (์ค๊ดํธ ์
|
| 64 |
# ==========================================
|
| 65 |
-
# f-string ์์: ์ฌ๊ธฐ์๋ถํฐ ๋ชจ๋ { ๋ {{ ๋ก, } ๋ }} ๋ก ์ฌ์ฉ๋จ
|
| 66 |
html_code = f"""
|
| 67 |
<!DOCTYPE html>
|
| 68 |
<html>
|
|
@@ -172,7 +171,7 @@ html_code = f"""
|
|
| 172 |
const TRANSLATIONS = {{
|
| 173 |
"KO": {{ "ai": "Korean", "greet": "์๋
, ์๊ธฐ? ์ค๋ ์ ๋ง ๊ณ ์ ๋ง์์ด. ์๋ฐ๋ฆฌํํ
๋ญ๋ ๋ฌผ์ด๋ด~" }},
|
| 174 |
"EN": {{ "ai": "English", "greet": "Hey darling, rough day? Let Emily find you a perfect spot to drink." }},
|
| 175 |
-
"JP": {{ "ai": "Japanese", "greet": "ใใใใใใผใไปๆฅใฏใ็ฒใๆง
|
| 176 |
"CN": {{ "ai": "Chinese", "greet": "ไบฒ็ฑ็๏ผไปๅคฉ่พ่ฆไบ. ๆณๅ็นไปไน๏ผ" }}
|
| 177 |
}};
|
| 178 |
|
|
@@ -236,7 +235,7 @@ html_code = f"""
|
|
| 236 |
document.getElementById('chat-page').style.transform = 'translateY(0%)';
|
| 237 |
if(chatHistory.length === 0) {{
|
| 238 |
addChatMessage(TRANSLATIONS[currentLang].greet, "bot");
|
| 239 |
-
chatHistory.push({{ role: "system", content: "You are Emily, a flirtatious blonde bartender. Recommending a place? Wrap name in brackets like [Place Name]." }});
|
| 240 |
}}
|
| 241 |
}}
|
| 242 |
|
|
@@ -246,7 +245,7 @@ html_code = f"""
|
|
| 246 |
if(!msg) return;
|
| 247 |
addChatMessage(msg, 'user');
|
| 248 |
inp.value = "";
|
| 249 |
-
chatHistory.push({{ role: "user", content: msg }});
|
| 250 |
const botMsgDiv = addChatMessage("...", "bot");
|
| 251 |
const res = await callGroq(chatHistory);
|
| 252 |
botMsgDiv.innerText = res;
|
|
@@ -255,7 +254,7 @@ html_code = f"""
|
|
| 255 |
const pName = match[1];
|
| 256 |
botMsgDiv.innerHTML += "<br><button class='reco-btn' onclick=\\"searchAndOpenMap('" + pName.replace(/'/g, "\\\\'") + "')\\">๐ View on Map</button>";
|
| 257 |
}}
|
| 258 |
-
chatHistory.push({{ role: "assistant", content: res }});
|
| 259 |
}}
|
| 260 |
|
| 261 |
function addChatMessage(t, s) {{
|
|
@@ -285,8 +284,8 @@ html_code = f"""
|
|
| 285 |
L.marker([p.lat, p.lon]).addTo(miniMap);
|
| 286 |
}}, 400);
|
| 287 |
const prompt = [
|
| 288 |
-
{{ role: "system", content: "Act as Emily. Write review in " + TRANSLATIONS[currentLang].ai + ". Sections: Vibe, Must Try, Secret Tip." }},
|
| 289 |
-
{{ role: "user", content: "Write review for " + name + " in " + country }}
|
| 290 |
];
|
| 291 |
const res = await callGroq(prompt);
|
| 292 |
document.getElementById('repo-content').innerText = res;
|
|
@@ -299,16 +298,16 @@ html_code = f"""
|
|
| 299 |
method: "POST",
|
| 300 |
headers: {{ "Content-Type": "application/json", "Authorization": "Bearer {GROQ_API_KEY}" }},
|
| 301 |
body: JSON.stringify({{
|
| 302 |
-
model: "llama-3.3-70b-versatile",
|
| 303 |
-
messages: messages,
|
| 304 |
-
temperature: 0.7,
|
| 305 |
-
top_p: 0.85,
|
| 306 |
-
frequency_penalty: 0.7
|
| 307 |
}})
|
| 308 |
}});
|
| 309 |
const d = await r.json();
|
| 310 |
return d.choices[0].message.content;
|
| 311 |
-
} catch(e) {{
|
| 312 |
return "Sweetie, the connection is a bit unstable.";
|
| 313 |
}}
|
| 314 |
}}
|
|
|
|
| 15 |
|
| 16 |
st.set_page_config(page_title="Drunken Plane", page_icon="โ๏ธ", layout="wide")
|
| 17 |
|
| 18 |
+
# CSS ์ค๊ดํธ๋ f-string ํ์ถ์ ์ํด {{ }} ์ฌ์ฉ
|
| 19 |
st.markdown("""
|
| 20 |
<style>
|
| 21 |
.block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
|
|
|
|
| 35 |
response.raise_for_status()
|
| 36 |
df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
|
| 37 |
|
| 38 |
+
# ๋ฌธ์์ด ์ ์ (JS ๋ฌธ๋ฒ ์ถฉ๋ ๋ฐฉ์ง ๋ฐ ํน์๋ฌธ์ ๋ณดํธ)
|
| 39 |
for col in df.select_dtypes(include=['object']).columns:
|
| 40 |
df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
|
| 41 |
|
|
|
|
| 60 |
db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
|
| 61 |
|
| 62 |
# ==========================================
|
| 63 |
+
# 3. ํตํฉ ํ๋ก ํธ์๋ (๋ชจ๋ ์ค๊ดํธ ์๋ฒฝ ์ด์ค์ผ์ดํ)
|
| 64 |
# ==========================================
|
|
|
|
| 65 |
html_code = f"""
|
| 66 |
<!DOCTYPE html>
|
| 67 |
<html>
|
|
|
|
| 171 |
const TRANSLATIONS = {{
|
| 172 |
"KO": {{ "ai": "Korean", "greet": "์๋
, ์๊ธฐ? ์ค๋ ์ ๋ง ๊ณ ์ ๋ง์์ด. ์๋ฐ๋ฆฌํํ
๋ญ๋ ๋ฌผ์ด๋ด~" }},
|
| 173 |
"EN": {{ "ai": "English", "greet": "Hey darling, rough day? Let Emily find you a perfect spot to drink." }},
|
| 174 |
+
"JP": {{ "ai": "Japanese", "greet": "ใใใใใใผใไปๆฅใฏใ็ฒใๆง. ์๋ฐ๋ฆฌใซใชใใงใ่ใใฆ๏ผ" }},
|
| 175 |
"CN": {{ "ai": "Chinese", "greet": "ไบฒ็ฑ็๏ผไปๅคฉ่พ่ฆไบ. ๆณๅ็นไปไน๏ผ" }}
|
| 176 |
}};
|
| 177 |
|
|
|
|
| 235 |
document.getElementById('chat-page').style.transform = 'translateY(0%)';
|
| 236 |
if(chatHistory.length === 0) {{
|
| 237 |
addChatMessage(TRANSLATIONS[currentLang].greet, "bot");
|
| 238 |
+
chatHistory.push({{ "role": "system", "content": "You are Emily, a flirtatious blonde bartender. Recommending a place? Wrap name in brackets like [Place Name]." }});
|
| 239 |
}}
|
| 240 |
}}
|
| 241 |
|
|
|
|
| 245 |
if(!msg) return;
|
| 246 |
addChatMessage(msg, 'user');
|
| 247 |
inp.value = "";
|
| 248 |
+
chatHistory.push({{ "role": "user", "content": msg }});
|
| 249 |
const botMsgDiv = addChatMessage("...", "bot");
|
| 250 |
const res = await callGroq(chatHistory);
|
| 251 |
botMsgDiv.innerText = res;
|
|
|
|
| 254 |
const pName = match[1];
|
| 255 |
botMsgDiv.innerHTML += "<br><button class='reco-btn' onclick=\\"searchAndOpenMap('" + pName.replace(/'/g, "\\\\'") + "')\\">๐ View on Map</button>";
|
| 256 |
}}
|
| 257 |
+
chatHistory.push({{ "role": "assistant", "content": res }});
|
| 258 |
}}
|
| 259 |
|
| 260 |
function addChatMessage(t, s) {{
|
|
|
|
| 284 |
L.marker([p.lat, p.lon]).addTo(miniMap);
|
| 285 |
}}, 400);
|
| 286 |
const prompt = [
|
| 287 |
+
{{ "role": "system", "content": "Act as Emily. Write review in " + TRANSLATIONS[currentLang].ai + ". Sections: Vibe, Must Try, Secret Tip." }},
|
| 288 |
+
{{ "role": "user", "content": "Write review for " + name + " in " + country }}
|
| 289 |
];
|
| 290 |
const res = await callGroq(prompt);
|
| 291 |
document.getElementById('repo-content').innerText = res;
|
|
|
|
| 298 |
method: "POST",
|
| 299 |
headers: {{ "Content-Type": "application/json", "Authorization": "Bearer {GROQ_API_KEY}" }},
|
| 300 |
body: JSON.stringify({{
|
| 301 |
+
"model": "llama-3.3-70b-versatile",
|
| 302 |
+
"messages": messages,
|
| 303 |
+
"temperature": 0.7,
|
| 304 |
+
"top_p": 0.85,
|
| 305 |
+
"frequency_penalty": 0.7
|
| 306 |
}})
|
| 307 |
}});
|
| 308 |
const d = await r.json();
|
| 309 |
return d.choices[0].message.content;
|
| 310 |
+
}} catch(e) {{
|
| 311 |
return "Sweetie, the connection is a bit unstable.";
|
| 312 |
}}
|
| 313 |
}}
|