Spaces:
Runtime error
Runtime error
import pandas as pd | |
import folium | |
from folium import IFrame | |
import plotly.graph_objects as go | |
from APIs.geolocation import get_geolocation, get_risques | |
from APIs.meteo import get_info_meteo | |
def get_and_plot_meteo(lat, lon): | |
df = get_info_meteo(lat, lon) | |
fig = go.Figure() | |
fig.add_trace(go.Scatter(x=df['date'], y=df['daily_temperature_2m_max_C'], | |
name="Température °C", mode="lines+markers")) | |
fig.add_trace(go.Scatter(x=df['date'], y=df['avg_hourly_relative_humidity_2m_%'], | |
name="Humidité moyenne en %", mode="lines+markers", yaxis="y2")) | |
fig.update_layout( | |
title="Température maximale et humidité moyenne journalière", | |
xaxis_title="Date", | |
yaxis_title="Température (°C)", | |
yaxis2=dict( | |
title="Humidity (%)", | |
overlaying="y", | |
side="right" | |
) | |
) | |
return fig | |
def show_map(lat, lon, address): | |
if address: | |
lat_tmp, lon_tmp, code_insee = get_geolocation(address, None, None) | |
risques = get_risques(code_insee=code_insee) | |
if lat_tmp or lon_tmp: | |
lat, lon = lat_tmp, lon_tmp | |
else: | |
return "Adress not found. Please enter a valid address", "" | |
if lat and lon: | |
lat_tmp, lon_tmp, code_insee = get_geolocation(None, lat, lon) | |
risques = get_risques(code_insee=code_insee) | |
# Create a map centered at the input coordinates | |
location_map = folium.Map(location=[lat, lon], zoom_start=14) | |
folium.Marker([lat, lon], popup=risques).add_to(location_map) | |
map_html = location_map._repr_html_() | |
fig = get_and_plot_meteo(lat, lon) | |
return map_html, fig | |