Spaces:
Sleeping
Sleeping
File size: 2,202 Bytes
a5b25f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import streamlit as st
from geopy.geocoders import Nominatim
import pandas as pd
import folium
from folium.plugins import HeatMap
from geopy.distance import geodesic
import numpy as np
import warnings
# κ²½κ³ λ©μμ§λ₯Ό 무μνκΈ°
warnings.filterwarnings("ignore", category=UserWarning, module="geopy")
# Geolocator μ€μ
geolocator = Nominatim(user_agent="hwaseong_locator")
# μλμ κ²½λλ₯Ό μ£Όμλ‘ λ³ννλ ν¨μ
def get_location_name(lat, lon):
location = geolocator.reverse((lat, lon), language='ko')
return location.address if location else "μ£Όμλ₯Ό μ°Ύμ μ μμ"
# μνλ λΆλ₯ ν¨μ
def classify_risk(score):
if score >= 2:
return "λ§€μ° μμ "
elif 1 <= score < 2:
return "μμ "
elif 0 <= score < 1:
return "보ν΅"
elif -1 < score < 0:
return "μν"
else:
return "λ§€μ° μν"
# νμ±μ μ€μ¬ μ’ν
hwaseong_center = [37.198, 127.034]
# μ¬μ©μ μ
λ ₯μ λ°κΈ°
st.title("νμ±μ μμΉ μνλ λΆμκΈ°")
lat_input = st.number_input("μλ (Latitude)", value=37.198, format="%.6f")
lon_input = st.number_input("κ²½λ (Longitude)", value=127.034, format="%.6f")
# μ€μ μ£Όμ νμΈ
location_name = get_location_name(lat_input, lon_input)
st.write(f"μμΉ: {location_name}")
# μμ λ°μ΄ν° (κ°λ¨ν μ ν΄λ μμμ
λλ€. μ€μ λ‘λ μ΄ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ κ³μ°ν©λλ€.)
sample_scores = {
(37.198, 127.034): 3, # μμ μμ μ§μ
(37.198, 127.035): -2, # μμ μν μ§μ
}
# ν΄λΉ μμΉμ λν μ μ μ°ΎκΈ°
def get_score_for_location(lat, lon):
closest_location = min(sample_scores.keys(), key=lambda x: geodesic((lat, lon), x).meters)
return sample_scores[closest_location]
score = get_score_for_location(lat_input, lon_input)
risk_category = classify_risk(score)
st.write(f"μνλ: {risk_category}")
# μ§λ νμ
m = folium.Map(location=[lat_input, lon_input], zoom_start=16)
folium.Marker([lat_input, lon_input], popup=location_name).add_to(m)
# κ²°κ³Όλ₯Ό HTMLλ‘ μ μ₯
m.save("location_map.html")
# λ€μ΄λ‘λ λ§ν¬
st.download_button("μμΉ μ§λ λ€μ΄λ‘λ", "location_map.html")
|