Spaces:
Sleeping
Sleeping
Yunus Serhat Bıçakçı
commited on
Commit
·
8ec69ab
1
Parent(s):
1f3e989
update
Browse files- pages/3_📋_Types.py +84 -0
pages/3_📋_Types.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import os
|
| 3 |
+
import pathlib
|
| 4 |
+
import requests
|
| 5 |
+
import zipfile
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pydeck as pdk
|
| 8 |
+
import geopandas as gpd
|
| 9 |
+
import streamlit as st
|
| 10 |
+
import leafmap.colormaps as cm
|
| 11 |
+
from leafmap.common import hex_to_rgb
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
st.set_page_config(layout="wide")
|
| 15 |
+
|
| 16 |
+
st.sidebar.info(
|
| 17 |
+
"""
|
| 18 |
+
- Web App URL: <https://interactive-crime-map.hf.space/>
|
| 19 |
+
- HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
|
| 20 |
+
"""
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
st.sidebar.title("Contact")
|
| 24 |
+
st.sidebar.info(
|
| 25 |
+
"""
|
| 26 |
+
Yunus Serhat Bıçakçı at [yunusserhat.com](https://yunusserhat.com) | [GitHub](https://github.com/yunusserhat) | [Twitter](https://twitter.com/yunusserhat) | [LinkedIn](https://www.linkedin.com/in/yunusserhat)
|
| 27 |
+
"""
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
st.title("Heatmap")
|
| 31 |
+
|
| 32 |
+
tweets = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/testimport.csv'
|
| 33 |
+
borough = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/londonborough.geojson'
|
| 34 |
+
|
| 35 |
+
def get_data_dict(name):
|
| 36 |
+
in_csv = tweets
|
| 37 |
+
df = pd.read_csv(in_csv)
|
| 38 |
+
label = list(df[df["hate_pred"] == name]["Borough"])[0]
|
| 39 |
+
desc = list(df[df["hate_pred"] == name]["Borough"])[0]
|
| 40 |
+
return label, desc
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def app():
|
| 44 |
+
st.title("Crime Types")
|
| 45 |
+
st.markdown(
|
| 46 |
+
"""
|
| 47 |
+
This page shows the crime types in London. You can select a crime type from the sidebar and see the heatmap of that crime type.
|
| 48 |
+
"""
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
row1_col1, row1_col2 = st.columns([3, 1.3])
|
| 52 |
+
width = 800
|
| 53 |
+
height = 600
|
| 54 |
+
layers = None
|
| 55 |
+
|
| 56 |
+
with row1_col2:
|
| 57 |
+
show_desc = st.checkbox("Show attribute description")
|
| 58 |
+
if show_desc:
|
| 59 |
+
try:
|
| 60 |
+
label, desc = get_data_dict()
|
| 61 |
+
markdown = f"""
|
| 62 |
+
**{label}**: {desc}
|
| 63 |
+
"""
|
| 64 |
+
st.markdown(markdown)
|
| 65 |
+
except:
|
| 66 |
+
st.warning("No description available for selected attribute")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
with row1_col1:
|
| 70 |
+
m = leafmap.Map(center=(51.50, -0.1]), zoom=10)
|
| 71 |
+
m.add_geojson(borough, layer_name='London Boroughs')
|
| 72 |
+
# if layers is not None:
|
| 73 |
+
# for layer in layers:
|
| 74 |
+
# m.add_wms_layer(
|
| 75 |
+
# url, layers=layer, name=layer, attribution=" ", transparent=True
|
| 76 |
+
# )
|
| 77 |
+
# if add_legend and legend_text:
|
| 78 |
+
# legend_dict = ast.literal_eval(legend_text)
|
| 79 |
+
# m.add_legend(legend_dict=legend_dict)
|
| 80 |
+
|
| 81 |
+
m.to_streamlit(height=height)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
app()
|