Spaces:
Sleeping
Sleeping
| 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 = 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) | |
| m.save("/tmp/location_map.html") | |
| # HTMLλ‘ Streamlitμ μκ°ν | |
| with open("/tmp/location_map.html", "r", encoding="utf-8") as f: | |
| map_html = f.read() | |
| st.components.v1.html(map_html, height=500) | |
| # μ§λ λ€μ΄λ‘λ | |
| st.download_button("μμΉ μ§λ λ€μ΄λ‘λ", map_html, file_name="location_map.html") | |