Spaces:
Sleeping
Sleeping
Create app.py
#1
by
dltmdgus
- opened
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")
|