Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 68 |
-
|
|
|
|
|
|
|
| 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")
|