Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import folium | |
import streamlit as st | |
import pandas as pd | |
from streamlit_folium import st_folium | |
import time | |
st.set_page_config(layout="wide") | |
if "sleep_time" not in st.session_state: | |
st.session_state.sleep_time = 2 | |
if "auto_refresh" not in st.session_state: | |
st.session_state.auto_refresh = True | |
auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh) | |
if auto_refresh: | |
number = st.sidebar.number_input("Refresh rate in seconds", value=st.session_state.sleep_time) | |
st.session_state.sleep_time = number | |
st.title("Nt3awnu kamlin نتعاونو كاملين") | |
st.markdown("Help us report more people in need by filling this form: https://forms.gle/nZNCUVog9ka2Vdqu6") | |
def parse_gg_sheet(url): | |
url = url.replace("edit#gid=", "export?format=csv&gid=") | |
df = pd.read_csv(url) | |
# parse latlng (column 4) to [lat, lng] | |
def parse_latlng(latlng): | |
if type(latlng) == str and "," in latlng: | |
lat, lng = latlng.split(",") | |
return [float(lat), float(lng)] | |
else: | |
return None | |
return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng)) | |
df = parse_gg_sheet( | |
"https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708" | |
) | |
def display_tab(input): | |
m = folium.Map(location=[31.628674, -7.992047], zoom_start=7.5) | |
filtered_df = df[df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"] == input] | |
for index, row in filtered_df.iterrows(): | |
if row["latlng"] is None: | |
continue | |
folium.Marker( | |
location=row["latlng"], | |
tooltip=row["العنوان أو اسم القرية"] if not pd.isna(row["العنوان أو اسم القرية"]) else None, | |
popup=row["رقم الهاتف (اختياري)"] if not pd.isna(row["رقم الهاتف (اختياري)"]) else None, | |
).add_to(m) | |
st_data = st_folium(m, use_container_width=True) | |
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Rescue/إغاثة", "Medical Assistance/مساعدة طبية", "Shelter/مأوى", "Food & Water/طعام وماء", "Danger/مخاطر"]) | |
with tab1: | |
st.header("Rescue/إغاثة") | |
display_tab("إغاثة") | |
with tab2: | |
st.header("Medical Assistance/مساعدة طبية") | |
display_tab("مساعدة طبية") | |
with tab3: | |
st.header("Shelter/مأوى") | |
display_tab("مأوى") | |
with tab4: | |
st.header("Food & Water/طعام وماء") | |
display_tab("طعام وماء") | |
with TabError: | |
st.header("Danger/مخاطر (تسرب الغاز، تلف في الخدمات العامة...)") | |
display_tab("مخاطر (تسرب الغاز، تلف في الخدمات العامة...)") | |
# Google Sheet Table | |
st.markdown( | |
""" | |
<iframe src="https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/" width="100%" height="600px"></iframe> | |
""", | |
unsafe_allow_html=True, | |
) | |
# Google Form | |
# st.markdown( | |
# """ | |
# <iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfNrFHUScot5jQyRUJmor7kWYgwkkME6WqRgQG_L4Eze4RdHA/viewform?embedded=true" width="640" height="2877" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe> | |
# """, | |
# unsafe_allow_html=True, | |
# ) | |
if auto_refresh: | |
time.sleep(number) | |
st.experimental_rerun() | |