Nebulae000 commited on
Commit
9cbf765
Β·
verified Β·
1 Parent(s): ece9315

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -16
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import time
 
3
  import googlemaps
4
  import pandas as pd
5
  import folium
@@ -16,7 +17,7 @@ if API_KEY is None:
16
  gmaps = googlemaps.Client(key=API_KEY)
17
 
18
  # ===============================
19
- # 2. Data fetch (cached in memory)
20
  # ===============================
21
  def fetch_places():
22
  query = "Hawaiian pizza in Seoul"
@@ -47,14 +48,23 @@ def fetch_places():
47
  DATA = fetch_places()
48
 
49
  # ===============================
50
- # 3. Map rendering (iframe)
51
  # ===============================
52
- def render_map(min_rating):
53
- df = DATA[DATA["rating"] >= min_rating]
 
 
 
 
 
54
 
 
 
 
 
55
  m = folium.Map(
56
  location=[37.5665, 126.9780],
57
- zoom_start=11,
58
  tiles="CartoDB positron"
59
  )
60
 
@@ -65,7 +75,9 @@ def render_map(min_rating):
65
  <div style="font-size:13px">
66
  <b>{r.name}</b><br>
67
  ⭐ {r.rating}<br>
68
- {r.address}
 
 
69
  </div>
70
  """
71
  ).add_to(m)
@@ -80,7 +92,41 @@ def render_map(min_rating):
80
  """
81
 
82
  # ===============================
83
- # 4. UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  # ===============================
85
  CSS = """
86
  #map {
@@ -102,6 +148,20 @@ CSS = """
102
  color: #666;
103
  margin-bottom: 1.5em;
104
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  """
106
 
107
  with gr.Blocks(css=CSS) as demo:
@@ -109,7 +169,9 @@ with gr.Blocks(css=CSS) as demo:
109
  gr.Markdown(
110
  """
111
  <div id="title">🍍 μ„œμšΈ ν•˜μ™€μ΄μ•ˆ ν”Όμž 지도</div>
112
- <div id="subtitle">Google Maps 기반 Β· 평점 필터링</div>
 
 
113
  """
114
  )
115
 
@@ -128,28 +190,34 @@ with gr.Blocks(css=CSS) as demo:
128
  )
129
 
130
  count = gr.Markdown()
 
 
 
 
 
131
 
132
  # ---------- Right panel ----------
133
  with gr.Column(scale=3):
134
  with gr.Group(elem_classes="card"):
135
  map_html = gr.HTML(elem_id="map")
136
 
137
- # ---------- Logic ----------
138
- def update(min_rating):
139
- html = render_map(min_rating)
140
- n = (DATA["rating"] >= min_rating).sum()
141
- return html, f"**{n}개 λ§€μž₯ ν‘œμ‹œ 쀑**"
142
-
143
  rating.change(
144
  fn=update,
145
  inputs=rating,
146
- outputs=[map_html, count]
 
 
 
 
 
 
147
  )
148
 
149
  demo.load(
150
  fn=update,
151
  inputs=rating,
152
- outputs=[map_html, count]
153
  )
154
 
155
  demo.launch()
 
1
  import os
2
  import time
3
+ import random
4
  import googlemaps
5
  import pandas as pd
6
  import folium
 
17
  gmaps = googlemaps.Client(key=API_KEY)
18
 
19
  # ===============================
20
+ # 2. Data fetch (cache in memory)
21
  # ===============================
22
  def fetch_places():
23
  query = "Hawaiian pizza in Seoul"
 
48
  DATA = fetch_places()
49
 
50
  # ===============================
51
+ # 3. Pineapple quotes 🍍
52
  # ===============================
53
+ PINEAPPLE_QUOTES = [
54
+ "🍍 νŒŒμΈμ• ν”Œμ€ λ…ΌμŸμ μ΄μ§€λ§Œ λ§›μžˆμŠ΅λ‹ˆλ‹€",
55
+ "πŸ• μ΄νƒˆλ¦¬μ•„μΈμ—κ²ŒλŠ” λΉ„λ°€λ‘œβ€¦",
56
+ "πŸ”₯ ν•˜μ™€μ΄μ•ˆ ν”Όμž μ°¬μ„± 1ν‘œ μΆ”κ°€",
57
+ "🀝 λ‹¨μ§ μ˜ ν‰ν™”ν˜‘μ •",
58
+ "🧠 미각은 μžμœ μž…λ‹ˆλ‹€",
59
+ ]
60
 
61
+ # ===============================
62
+ # 4. Map rendering (iframe)
63
+ # ===============================
64
+ def render_map(df, zoom=11):
65
  m = folium.Map(
66
  location=[37.5665, 126.9780],
67
+ zoom_start=zoom,
68
  tiles="CartoDB positron"
69
  )
70
 
 
75
  <div style="font-size:13px">
76
  <b>{r.name}</b><br>
77
  ⭐ {r.rating}<br>
78
+ {r.address}<br>
79
+ <span class="pineapple">🍍</span>
80
+ <span class="pineapple">πŸ•</span>
81
  </div>
82
  """
83
  ).add_to(m)
 
92
  """
93
 
94
  # ===============================
95
+ # 5. UI logic
96
+ # ===============================
97
+ def update(min_rating):
98
+ df = DATA[DATA["rating"] >= min_rating]
99
+ html = render_map(df)
100
+
101
+ n = len(df)
102
+ total = len(DATA)
103
+ pct = int(100 * n / total) if total > 0 else 0
104
+ quote = random.choice(PINEAPPLE_QUOTES)
105
+
106
+ return (
107
+ html,
108
+ f"**{n}개 λ§€μž₯ ν‘œμ‹œ 쀑**",
109
+ f"🍍 **Pineapple Power:** {pct}%",
110
+ f"### {quote}"
111
+ )
112
+
113
+ def random_pick():
114
+ row = DATA.sample(1).iloc[0]
115
+ df = DATA.loc[[row.name]]
116
+
117
+ html = render_map(pd.DataFrame([row]), zoom=15)
118
+
119
+ text = f"""
120
+ ### 🎲 였늘의 ν•˜μ™€μ΄μ•ˆ 🍍
121
+ **{row.name}**
122
+ ⭐ {row.rating}
123
+ πŸ“ {row.address}
124
+ """
125
+
126
+ return html, text
127
+
128
+ # ===============================
129
+ # 6. UI & CSS
130
  # ===============================
131
  CSS = """
132
  #map {
 
148
  color: #666;
149
  margin-bottom: 1.5em;
150
  }
151
+
152
+ /* Pineapple animation */
153
+ .pineapple {
154
+ display: inline-block;
155
+ cursor: pointer;
156
+ }
157
+ .pineapple:active {
158
+ animation: pop 0.6s ease-out;
159
+ }
160
+ @keyframes pop {
161
+ 0% { transform: scale(1) translateY(0); opacity: 1; }
162
+ 50% { transform: scale(1.8) translateY(-10px); }
163
+ 100% { transform: scale(1) translateY(0); opacity: 0.8; }
164
+ }
165
  """
166
 
167
  with gr.Blocks(css=CSS) as demo:
 
169
  gr.Markdown(
170
  """
171
  <div id="title">🍍 μ„œμšΈ ν•˜μ™€μ΄μ•ˆ ν”Όμž 지도</div>
172
+ <div id="subtitle">
173
+ Google Maps 기반 Β· νŒŒμΈμ• ν”Œμ€ μžμœ μž…λ‹ˆλ‹€
174
+ </div>
175
  """
176
  )
177
 
 
190
  )
191
 
192
  count = gr.Markdown()
193
+ pineapple_power = gr.Markdown()
194
+ quote = gr.Markdown()
195
+
196
+ random_btn = gr.Button("🍍 였늘의 ν•˜μ™€μ΄μ•ˆ", variant="primary")
197
+ recommendation = gr.Markdown()
198
 
199
  # ---------- Right panel ----------
200
  with gr.Column(scale=3):
201
  with gr.Group(elem_classes="card"):
202
  map_html = gr.HTML(elem_id="map")
203
 
204
+ # ---------- Events ----------
 
 
 
 
 
205
  rating.change(
206
  fn=update,
207
  inputs=rating,
208
+ outputs=[map_html, count, pineapple_power, quote]
209
+ )
210
+
211
+ random_btn.click(
212
+ fn=random_pick,
213
+ inputs=None,
214
+ outputs=[map_html, recommendation]
215
  )
216
 
217
  demo.load(
218
  fn=update,
219
  inputs=rating,
220
+ outputs=[map_html, count, pineapple_power, quote]
221
  )
222
 
223
  demo.launch()