dltmdgus commited on
Commit
be817c3
Β·
verified Β·
1 Parent(s): 9a50110

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -7,18 +7,14 @@ from geopy.distance import geodesic
7
  import numpy as np
8
  import warnings
9
 
10
- # κ²½κ³  λ©”μ‹œμ§€λ₯Ό λ¬΄μ‹œν•˜κΈ°
11
  warnings.filterwarnings("ignore", category=UserWarning, module="geopy")
12
 
13
- # Geolocator μ„€μ •
14
  geolocator = Nominatim(user_agent="hwaseong_locator")
15
 
16
- # μœ„λ„μ™€ 경도λ₯Ό μ£Όμ†Œλ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜
17
  def get_location_name(lat, lon):
18
  location = geolocator.reverse((lat, lon), language='ko')
19
  return location.address if location else "μ£Όμ†Œλ₯Ό 찾을 수 μ—†μŒ"
20
 
21
- # μœ„ν—˜λ„ λΆ„λ₯˜ ν•¨μˆ˜
22
  def classify_risk(score):
23
  if score >= 2:
24
  return "맀우 μ•ˆμ „"
@@ -31,26 +27,21 @@ def classify_risk(score):
31
  else:
32
  return "맀우 μœ„ν—˜"
33
 
34
- # ν™”μ„±μ‹œ 쀑심 μ’Œν‘œ
35
  hwaseong_center = [37.198, 127.034]
36
 
37
- # μ‚¬μš©μž μž…λ ₯을 λ°›κΈ°
38
  st.title("ν™”μ„±μ‹œ μœ„μΉ˜ μœ„ν—˜λ„ 뢄석기")
39
 
40
  lat_input = st.number_input("μœ„λ„ (Latitude)", value=37.198, format="%.6f")
41
  lon_input = st.number_input("경도 (Longitude)", value=127.034, format="%.6f")
42
 
43
- # μ‹€μ œ μ£Όμ†Œ 확인
44
  location_name = get_location_name(lat_input, lon_input)
45
  st.write(f"μœ„μΉ˜: {location_name}")
46
 
47
- # μ˜ˆμ‹œ 데이터 (κ°„λ‹¨νžˆ μ •ν•΄λ‘” μ˜ˆμ‹œμž…λ‹ˆλ‹€. μ‹€μ œλ‘œλŠ” 이 데이터λ₯Ό 기반으둜 κ³„μ‚°ν•©λ‹ˆλ‹€.)
48
  sample_scores = {
49
- (37.198, 127.034): 3, # μ˜ˆμ‹œ μ•ˆμ „ μ§€μ—­
50
- (37.198, 127.035): -2, # μ˜ˆμ‹œ μœ„ν—˜ μ§€μ—­
51
  }
52
 
53
- # ν•΄λ‹Ή μœ„μΉ˜μ— λŒ€ν•œ 점수 μ°ΎκΈ°
54
  def get_score_for_location(lat, lon):
55
  closest_location = min(sample_scores.keys(), key=lambda x: geodesic((lat, lon), x).meters)
56
  return sample_scores[closest_location]
@@ -60,12 +51,15 @@ risk_category = classify_risk(score)
60
 
61
  st.write(f"μœ„ν—˜λ„: {risk_category}")
62
 
63
- # 지도 ν‘œμ‹œ
64
  m = folium.Map(location=[lat_input, lon_input], zoom_start=16)
65
  folium.Marker([lat_input, lon_input], popup=location_name).add_to(m)
 
66
 
67
- # κ²°κ³Όλ₯Ό HTML둜 μ €μž₯
68
- m.save("location_map.html")
 
 
69
 
70
- # λ‹€μš΄λ‘œλ“œ 링크
71
- st.download_button("μœ„μΉ˜ 지도 λ‹€μš΄λ‘œλ“œ", "location_map.html")
 
7
  import numpy as np
8
  import warnings
9
 
 
10
  warnings.filterwarnings("ignore", category=UserWarning, module="geopy")
11
 
 
12
  geolocator = Nominatim(user_agent="hwaseong_locator")
13
 
 
14
  def get_location_name(lat, lon):
15
  location = geolocator.reverse((lat, lon), language='ko')
16
  return location.address if location else "μ£Όμ†Œλ₯Ό 찾을 수 μ—†μŒ"
17
 
 
18
  def classify_risk(score):
19
  if score >= 2:
20
  return "맀우 μ•ˆμ „"
 
27
  else:
28
  return "맀우 μœ„ν—˜"
29
 
 
30
  hwaseong_center = [37.198, 127.034]
31
 
 
32
  st.title("ν™”μ„±μ‹œ μœ„μΉ˜ μœ„ν—˜λ„ 뢄석기")
33
 
34
  lat_input = st.number_input("μœ„λ„ (Latitude)", value=37.198, format="%.6f")
35
  lon_input = st.number_input("경도 (Longitude)", value=127.034, format="%.6f")
36
 
 
37
  location_name = get_location_name(lat_input, lon_input)
38
  st.write(f"μœ„μΉ˜: {location_name}")
39
 
 
40
  sample_scores = {
41
+ (37.198, 127.034): 3,
42
+ (37.198, 127.035): -2,
43
  }
44
 
 
45
  def get_score_for_location(lat, lon):
46
  closest_location = min(sample_scores.keys(), key=lambda x: geodesic((lat, lon), x).meters)
47
  return sample_scores[closest_location]
 
51
 
52
  st.write(f"μœ„ν—˜λ„: {risk_category}")
53
 
54
+ # 지도 생성 및 μ €μž₯
55
  m = folium.Map(location=[lat_input, lon_input], zoom_start=16)
56
  folium.Marker([lat_input, lon_input], popup=location_name).add_to(m)
57
+ m.save("/tmp/location_map.html")
58
 
59
+ # HTML둜 Streamlit에 μ‹œκ°ν™”
60
+ with open("/tmp/location_map.html", "r", encoding="utf-8") as f:
61
+ map_html = f.read()
62
+ st.components.v1.html(map_html, height=500)
63
 
64
+ # 지도 λ‹€μš΄λ‘œλ“œ
65
+ st.download_button("μœ„μΉ˜ 지도 λ‹€μš΄λ‘œλ“œ", map_html, file_name="location_map.html")