vcdemy/2022_space_apps
0
1import pandas as pd2import folium3import gradio as gr4 5df_sw = pd.read_csv('tundra_swan.csv', parse_dates=['TimeStamp'])6df_co2 = pd.read_csv('co2.csv', parse_dates=['start_date','end_date'])7 8df_sw = df_sw.set_index('TimeStamp')9df_co2 = df_co2.set_index('start_date')10 11months = []12for i in range(2008, 2013):13 for j in range(1, 13):14 if i==2008:15 if j < 7:16 continue17 elif i==2012:18 if j > 7:19 break20 months.append(f"{i}-{j:02}")21 22def map(odate):23 m = folium.Map([50, -120], zoom_start=3)24 for index, row in df_sw[odate].iterrows():25 folium.CircleMarker([row['latitude'], row['longitude']],26 popup=row['description'], 27 radius=10, 28 fill=True,29 color=row['color'], 30 fill_color=row['color'],31 fill_opacity=0.5,32 opacity=0.5).add_to(m)33 for index, row in df_co2[odate].iterrows():34 folium.Marker([row['latitude'],row['longitude']], popup=f"Temp:{row['tair_int']}\nNee:{row['nee']}").add_to(m)35 # html = m.get_root().render()36 html = m._repr_html_()37 html = (38 ""39 + html40 + ""41 )42 return html43 44with gr.Blocks() as app:45 gr.Markdown("# Overseer")46 gr.Markdown("### Overseeing Bird Migration")47 gr.Markdown("Choose Year-Month from dropdown list, and wait patiently for the result to show on the map!")48 dropdown = gr.Dropdown(months, label="Choose Year-Month")49 html = gr.HTML()50 dropdown.change(map, dropdown, html)51 52app.launch()