Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from geopy.geocoders import Nominatim
3
+ import pandas as pd
4
+ import folium
5
+ from folium.plugins import HeatMap
6
+ 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 "맀우 μ•ˆμ „"
25
+ elif 1 <= score < 2:
26
+ return "μ•ˆμ „"
27
+ elif 0 <= score < 1:
28
+ return "보톡"
29
+ elif -1 < score < 0:
30
+ return "μœ„ν—˜"
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]
57
+
58
+ score = get_score_for_location(lat_input, lon_input)
59
+ 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")