Nebulae000 commited on
Commit
104e098
Β·
verified Β·
1 Parent(s): ad209e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -36
app.py CHANGED
@@ -7,23 +7,24 @@ import pandas as pd
7
  import pydeck as pdk
8
  import gradio as gr
9
 
10
- # ============================================================
11
  # 1. Google Maps API
12
- # ============================================================
13
  API_KEY = os.getenv("GOOGLE_MAPS_API_KEY")
14
  if API_KEY is None:
15
- raise RuntimeError("GOOGLE_MAPS_API_KEY is not set")
16
 
17
  gmaps = googlemaps.Client(key=API_KEY)
18
 
19
- # ============================================================
20
- # 2. Data
21
- # ============================================================
22
  def fetch_places():
23
  query = "Hawaiian pizza in Seoul"
24
  rows = []
25
 
26
  res = gmaps.places(query=query, language="ko")
 
27
  while True:
28
  for r in res["results"]:
29
  rows.append({
@@ -45,25 +46,15 @@ def fetch_places():
45
 
46
  return pd.DataFrame(rows)
47
 
48
- DATA = fetch_places()
49
 
50
- # ============================================================
51
- # 3. Entertainment
52
- # ============================================================
53
- QUOTES = [
54
- "🍍 νŒŒμΈμ• ν”Œμ€ λ…ΌμŸμ μ΄μ§€λ§Œ λ§›μžˆμŠ΅λ‹ˆλ‹€",
55
- "πŸ• μ΄νƒˆλ¦¬μ•„μΈμ—κ²ŒλŠ” λΉ„λ°€λ‘œβ€¦",
56
- "πŸ”₯ ν•˜μ™€μ΄μ•ˆ ν”Όμž μ°¬μ„± 1ν‘œ",
57
- "🀝 λ‹¨μ§ μ˜ ν‰ν™”ν˜‘μ •",
58
- "🧠 미각은 μžμœ μž…λ‹ˆλ‹€",
59
- ]
60
 
61
- # ============================================================
62
- # 4. Deck.gl Map
63
- # ============================================================
64
- def make_deck(df, zoom=11):
65
  if df.empty:
66
- center = [126.9780, 37.5665]
67
  else:
68
  center = [df.lon.mean(), df.lat.mean()]
69
 
@@ -72,7 +63,7 @@ def make_deck(df, zoom=11):
72
  data=df,
73
  get_position="[lon, lat]",
74
  get_radius=120,
75
- get_fill_color="[255, 165, 0, 180]", # pineapple 🍍
76
  pickable=True,
77
  auto_highlight=True,
78
  )
@@ -81,7 +72,6 @@ def make_deck(df, zoom=11):
81
  longitude=center[0],
82
  latitude=center[1],
83
  zoom=zoom,
84
- pitch=0,
85
  )
86
 
87
  tooltip = {
@@ -96,12 +86,20 @@ def make_deck(df, zoom=11):
96
  map_style="mapbox://styles/mapbox/light-v9",
97
  )
98
 
99
- # ============================================================
100
- # 5. UI logic
101
- # ============================================================
 
 
 
 
 
 
 
 
102
  def update(min_rating):
103
  df = DATA[DATA["rating"] >= min_rating]
104
- deck = make_deck(df)
105
 
106
  pct = int(100 * len(df) / len(DATA)) if len(DATA) else 0
107
 
@@ -109,17 +107,15 @@ def update(min_rating):
109
  deck,
110
  f"**{len(df)}개 λ§€μž₯ ν‘œμ‹œ 쀑**",
111
  f"🍍 Pineapple Power: {pct}%",
112
- f"### {random.choice(QUOTES)}",
113
  )
114
 
115
  def random_pick():
116
  row = DATA.sample(1)
117
  r = row.iloc[0]
118
 
119
- deck = make_deck(row, zoom=15)
120
-
121
  return (
122
- deck,
123
  f"""
124
  ### 🎲 였늘의 ν•˜μ™€μ΄μ•ˆ 🍍
125
  **{r.name}**
@@ -128,14 +124,14 @@ def random_pick():
128
  """,
129
  )
130
 
131
- # ============================================================
132
- # 6. Gradio UI
133
- # ============================================================
134
  with gr.Blocks() as demo:
135
  gr.Markdown(
136
  """
137
  ## 🍍 μ„œμšΈ ν•˜μ™€μ΄μ•ˆ ν”Όμž 지도
138
- Google Maps 기반 Β· 이제 μ§„μ§œ μ•ˆμ • 버전
139
  """
140
  )
141
 
 
7
  import pydeck as pdk
8
  import gradio as gr
9
 
10
+ # =====================================================
11
  # 1. Google Maps API
12
+ # =====================================================
13
  API_KEY = os.getenv("GOOGLE_MAPS_API_KEY")
14
  if API_KEY is None:
15
+ raise RuntimeError("GOOGLE_MAPS_API_KEY not set")
16
 
17
  gmaps = googlemaps.Client(key=API_KEY)
18
 
19
+ # =====================================================
20
+ # 2. Data Fetch
21
+ # =====================================================
22
  def fetch_places():
23
  query = "Hawaiian pizza in Seoul"
24
  rows = []
25
 
26
  res = gmaps.places(query=query, language="ko")
27
+
28
  while True:
29
  for r in res["results"]:
30
  rows.append({
 
46
 
47
  return pd.DataFrame(rows)
48
 
 
49
 
50
+ DATA = fetch_places()
 
 
 
 
 
 
 
 
 
51
 
52
+ # =====================================================
53
+ # 3. Deck.gl Map Builder
54
+ # =====================================================
55
+ def build_map(df, zoom=11):
56
  if df.empty:
57
+ center = [126.9780, 37.5665] # Seoul
58
  else:
59
  center = [df.lon.mean(), df.lat.mean()]
60
 
 
63
  data=df,
64
  get_position="[lon, lat]",
65
  get_radius=120,
66
+ get_fill_color="[255, 165, 0, 180]", # 🍍 pineapple color
67
  pickable=True,
68
  auto_highlight=True,
69
  )
 
72
  longitude=center[0],
73
  latitude=center[1],
74
  zoom=zoom,
 
75
  )
76
 
77
  tooltip = {
 
86
  map_style="mapbox://styles/mapbox/light-v9",
87
  )
88
 
89
+ # =====================================================
90
+ # 4. UI Logic
91
+ # =====================================================
92
+ QUOTES = [
93
+ "🍍 νŒŒμΈμ• ν”Œμ€ λ…ΌμŸμ μ΄μ§€λ§Œ λ§›μžˆμŠ΅λ‹ˆλ‹€",
94
+ "πŸ• μ΄νƒˆλ¦¬μ•„μΈμ—κ²ŒλŠ” λΉ„λ°€λ‘œβ€¦",
95
+ "πŸ”₯ ν•˜μ™€μ΄μ•ˆ ν”Όμž μ°¬μ„± 1ν‘œ",
96
+ "🀝 λ‹¨μ§ μ˜ ν‰ν™”ν˜‘μ •",
97
+ "🧠 미각은 μžμœ μž…λ‹ˆλ‹€",
98
+ ]
99
+
100
  def update(min_rating):
101
  df = DATA[DATA["rating"] >= min_rating]
102
+ deck = build_map(df)
103
 
104
  pct = int(100 * len(df) / len(DATA)) if len(DATA) else 0
105
 
 
107
  deck,
108
  f"**{len(df)}개 λ§€μž₯ ν‘œμ‹œ 쀑**",
109
  f"🍍 Pineapple Power: {pct}%",
110
+ random.choice(QUOTES),
111
  )
112
 
113
  def random_pick():
114
  row = DATA.sample(1)
115
  r = row.iloc[0]
116
 
 
 
117
  return (
118
+ build_map(row, zoom=15),
119
  f"""
120
  ### 🎲 였늘의 ν•˜μ™€μ΄μ•ˆ 🍍
121
  **{r.name}**
 
124
  """,
125
  )
126
 
127
+ # =====================================================
128
+ # 5. Gradio UI
129
+ # =====================================================
130
  with gr.Blocks() as demo:
131
  gr.Markdown(
132
  """
133
  ## 🍍 μ„œμšΈ ν•˜μ™€μ΄μ•ˆ ν”Όμž 지도
134
+ **HF Spaces μ•ˆμ • 버전 Β· PyDeck 기반**
135
  """
136
  )
137