benjamin5607 commited on
Commit
992e384
ยท
verified ยท
1 Parent(s): af566dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
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
  }}