Spaces:
Sleeping
Sleeping
Yunus Serhat Bıçakçı
commited on
Commit
·
6c0b6f0
1
Parent(s):
dce107a
update
Browse files- Application.py +3 -3
- pages/1_🔥_Heatmap.py +0 -34
- pages/2_↔️_Comparision.py +78 -0
- pages/2_🔲_ChatBot.py +0 -72
- pages/3_📋_Types.py +0 -85
- pages/4_Choropleth.py +4 -3
Application.py
CHANGED
@@ -39,14 +39,14 @@ st.markdown(
|
|
39 |
)
|
40 |
|
41 |
m = leafmap.Map(center=[51.50, -0.1], zoom=10)
|
42 |
-
tweets = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/
|
43 |
borough = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/londonborough.geojson'
|
44 |
|
45 |
m.add_geojson(borough, layer_name='London Boroughs')
|
46 |
m.add_points_from_xy(
|
47 |
tweets,
|
48 |
-
x="
|
49 |
-
y="
|
50 |
# ,
|
51 |
# color_column='hate_pred',
|
52 |
# icon_names=['gear', 'map', 'leaf', 'globe'],
|
|
|
39 |
)
|
40 |
|
41 |
m = leafmap.Map(center=[51.50, -0.1], zoom=10)
|
42 |
+
tweets = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/London2022DecHateTweetsLatLong.csv'
|
43 |
borough = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/londonborough.geojson'
|
44 |
|
45 |
m.add_geojson(borough, layer_name='London Boroughs')
|
46 |
m.add_points_from_xy(
|
47 |
tweets,
|
48 |
+
x="Longitude",
|
49 |
+
y="Latitude"
|
50 |
# ,
|
51 |
# color_column='hate_pred',
|
52 |
# icon_names=['gear', 'map', 'leaf', 'globe'],
|
pages/1_🔥_Heatmap.py
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import leafmap.foliumap as leafmap
|
3 |
-
|
4 |
-
st.set_page_config(layout="wide")
|
5 |
-
|
6 |
-
st.sidebar.info(
|
7 |
-
"""
|
8 |
-
- Web App URL: <https://interactive-crime-map.hf.space/>
|
9 |
-
- HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
|
10 |
-
"""
|
11 |
-
)
|
12 |
-
|
13 |
-
st.sidebar.title("Contact")
|
14 |
-
st.sidebar.info(
|
15 |
-
"""
|
16 |
-
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)
|
17 |
-
"""
|
18 |
-
)
|
19 |
-
|
20 |
-
st.title("Heatmap")
|
21 |
-
|
22 |
-
with st.expander("See source code"):
|
23 |
-
with st.echo():
|
24 |
-
tweets = "https://raw.githubusercontent.com/yunusserhat/Github/main/data/boroughs_count_df_2023.csv"
|
25 |
-
m = leafmap.Map(center=[51.50, -0.1], zoom=10, tiles="stamentoner")
|
26 |
-
m.add_heatmap(
|
27 |
-
tweets,
|
28 |
-
latitude="latitude",
|
29 |
-
longitude="longitude",
|
30 |
-
value="count",
|
31 |
-
name="Heat map",
|
32 |
-
radius=20,
|
33 |
-
)
|
34 |
-
m.to_streamlit(height=700)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/2_↔️_Comparision.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import leafmap.foliumap as leafmap
|
3 |
+
import leafmap.colormaps as cm
|
4 |
+
|
5 |
+
st.set_page_config(layout="wide")
|
6 |
+
|
7 |
+
st.sidebar.info(
|
8 |
+
"""
|
9 |
+
- Web App URL: <https://interactive-crime-map.hf.space/>
|
10 |
+
- HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
|
11 |
+
"""
|
12 |
+
)
|
13 |
+
|
14 |
+
st.sidebar.title("Contact")
|
15 |
+
st.sidebar.info(
|
16 |
+
"""
|
17 |
+
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)
|
18 |
+
"""
|
19 |
+
)
|
20 |
+
|
21 |
+
st.title("Comparision of Hate Tweets and Crime Rates")
|
22 |
+
st.markdown(
|
23 |
+
"""
|
24 |
+
These interactive maps illustrate a comparison of overall borough-level rates based on Twitter and London Metropolitan Police Service data as of December 2022.
|
25 |
+
|
26 |
+
The interactive map in the first column displays the representation of hate tweets, while the interactive map in the second column represents the rates of all crimes.
|
27 |
+
|
28 |
+
"""
|
29 |
+
)
|
30 |
+
|
31 |
+
|
32 |
+
row1_col1, row1_col2 = st.columns([1, 1])
|
33 |
+
|
34 |
+
with row1_col1:
|
35 |
+
|
36 |
+
twitter = "https://raw.githubusercontent.com/yunusserhat/Github/main/data/boroughs_count_df_2022_dec.geojson"
|
37 |
+
|
38 |
+
m = leafmap.Map(center=[51.50, -0.1], zoom=10)
|
39 |
+
m.add_data(
|
40 |
+
twitter,
|
41 |
+
column="count",
|
42 |
+
scheme='Quantiles',
|
43 |
+
cmap='Blues',
|
44 |
+
legend_title='Hate Tweets'
|
45 |
+
)
|
46 |
+
|
47 |
+
|
48 |
+
with row1_col2:
|
49 |
+
|
50 |
+
mps = "https://raw.githubusercontent.com/yunusserhat/Github/main/data/mps2022dec_count.geojson"
|
51 |
+
|
52 |
+
m2 = leafmap.Map(center=[51.50, -0.1], zoom=10)
|
53 |
+
m2.add_data(
|
54 |
+
mps,
|
55 |
+
column="Crime_Number",
|
56 |
+
scheme='Quantiles',
|
57 |
+
cmap='Blues',
|
58 |
+
legend_title='Crime Rates'
|
59 |
+
)
|
60 |
+
|
61 |
+
row2_col1, row2_col2 = st.columns([1, 1])
|
62 |
+
|
63 |
+
with row2_col1:
|
64 |
+
longitude = st.number_input("Longitude", -180.0, 180.0, -0.1)
|
65 |
+
latitude = st.number_input("Latitude", -90.0, 90.0, 51.50)
|
66 |
+
zoomlevel = st.number_input("Zoom", 0, 20, 10)
|
67 |
+
m.set_center(longitude, latitude, zoomlevel)
|
68 |
+
|
69 |
+
with row2_col2:
|
70 |
+
m2.set_center(longitude, latitude, zoomlevel)
|
71 |
+
|
72 |
+
row3_col1, row3_col2 = st.columns([1, 1])
|
73 |
+
|
74 |
+
with row3_col1:
|
75 |
+
m.to_streamlit(height=700)
|
76 |
+
|
77 |
+
with row3_col2:
|
78 |
+
m2.to_streamlit(height=700)
|
pages/2_🔲_ChatBot.py
DELETED
@@ -1,72 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from streamlit_chat import message
|
3 |
-
from streamlit_extras.colored_header import colored_header
|
4 |
-
from streamlit_extras.add_vertical_space import add_vertical_space
|
5 |
-
from hugchat import hugchat
|
6 |
-
|
7 |
-
st.set_page_config(layout="wide")
|
8 |
-
|
9 |
-
|
10 |
-
st.sidebar.info(
|
11 |
-
"""
|
12 |
-
- Web App URL: <https://interactive-crime-map.hf.space/>
|
13 |
-
- HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
|
14 |
-
"""
|
15 |
-
)
|
16 |
-
|
17 |
-
st.sidebar.title("Contact")
|
18 |
-
st.sidebar.info(
|
19 |
-
"""
|
20 |
-
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)
|
21 |
-
"""
|
22 |
-
)
|
23 |
-
|
24 |
-
st.title("Crime ChatBot")
|
25 |
-
|
26 |
-
|
27 |
-
# Generate empty lists for generated and past.
|
28 |
-
## generated stores AI generated responses
|
29 |
-
if 'generated' not in st.session_state:
|
30 |
-
st.session_state['generated'] = ["I'm Crime ChatBot, How may I help you?"]
|
31 |
-
|
32 |
-
## past stores User's questions
|
33 |
-
if 'past' not in st.session_state:
|
34 |
-
st.session_state['past'] = ['Hello!']
|
35 |
-
|
36 |
-
# Layout of input/response containers
|
37 |
-
input_container = st.container()
|
38 |
-
colored_header(label='', description='', color_name='blue-30')
|
39 |
-
response_container = st.container()
|
40 |
-
|
41 |
-
|
42 |
-
# User input
|
43 |
-
## Function for taking user provided prompt as input
|
44 |
-
def get_text():
|
45 |
-
input_text = st.text_input("You: ", "", key="input")
|
46 |
-
return input_text
|
47 |
-
|
48 |
-
|
49 |
-
## Applying the user input box
|
50 |
-
with input_container:
|
51 |
-
user_input = get_text()
|
52 |
-
|
53 |
-
|
54 |
-
# Response output
|
55 |
-
## Function for taking user prompt as input followed by producing AI generated responses
|
56 |
-
def generate_response(prompt):
|
57 |
-
chatbot = hugchat.ChatBot()
|
58 |
-
response = chatbot.chat(prompt)
|
59 |
-
return response
|
60 |
-
|
61 |
-
|
62 |
-
## Conditional display of AI generated responses as a function of user provided prompts
|
63 |
-
with response_container:
|
64 |
-
if user_input:
|
65 |
-
response = generate_response(user_input)
|
66 |
-
st.session_state.past.append(user_input)
|
67 |
-
st.session_state.generated.append(response)
|
68 |
-
|
69 |
-
if st.session_state['generated']:
|
70 |
-
for i in range(len(st.session_state['generated'])):
|
71 |
-
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
72 |
-
message(st.session_state["generated"][i], key=str(i))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/3_📋_Types.py
DELETED
@@ -1,85 +0,0 @@
|
|
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 |
-
import leafmap.foliumap as leafmap
|
13 |
-
|
14 |
-
|
15 |
-
st.set_page_config(layout="wide")
|
16 |
-
|
17 |
-
st.sidebar.info(
|
18 |
-
"""
|
19 |
-
- Web App URL: <https://interactive-crime-map.hf.space/>
|
20 |
-
- HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
|
21 |
-
"""
|
22 |
-
)
|
23 |
-
|
24 |
-
st.sidebar.title("Contact")
|
25 |
-
st.sidebar.info(
|
26 |
-
"""
|
27 |
-
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)
|
28 |
-
"""
|
29 |
-
)
|
30 |
-
|
31 |
-
st.title("Heatmap")
|
32 |
-
|
33 |
-
tweets = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/testimport.csv'
|
34 |
-
borough = 'https://raw.githubusercontent.com/yunusserhat/Github/main/data/londonborough.geojson'
|
35 |
-
|
36 |
-
def get_data_dict(name):
|
37 |
-
in_csv = tweets
|
38 |
-
df = pd.read_csv(in_csv)
|
39 |
-
label = list(df[df["hate_pred"] == name]["Borough"])[0]
|
40 |
-
desc = list(df[df["hate_pred"] == name]["Borough"])[0]
|
41 |
-
return label, desc
|
42 |
-
|
43 |
-
|
44 |
-
def app():
|
45 |
-
st.title("Crime Types")
|
46 |
-
st.markdown(
|
47 |
-
"""
|
48 |
-
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.
|
49 |
-
"""
|
50 |
-
)
|
51 |
-
|
52 |
-
row1_col1, row1_col2 = st.columns([3, 1.3])
|
53 |
-
width = 800
|
54 |
-
height = 600
|
55 |
-
layers = None
|
56 |
-
|
57 |
-
with row1_col2:
|
58 |
-
show_desc = st.checkbox("Show attribute description")
|
59 |
-
if show_desc:
|
60 |
-
try:
|
61 |
-
label, desc = get_data_dict()
|
62 |
-
markdown = f"""
|
63 |
-
**{label}**: {desc}
|
64 |
-
"""
|
65 |
-
st.markdown(markdown)
|
66 |
-
except:
|
67 |
-
st.warning("No description available for selected attribute")
|
68 |
-
|
69 |
-
|
70 |
-
with row1_col1:
|
71 |
-
m = leafmap.Map(center=(51.50, -0.1), zoom=10)
|
72 |
-
m.add_geojson(borough, layer_name='London Boroughs')
|
73 |
-
# if layers is not None:
|
74 |
-
# for layer in layers:
|
75 |
-
# m.add_wms_layer(
|
76 |
-
# url, layers=layer, name=layer, attribution=" ", transparent=True
|
77 |
-
# )
|
78 |
-
# if add_legend and legend_text:
|
79 |
-
# legend_dict = ast.literal_eval(legend_text)
|
80 |
-
# m.add_legend(legend_dict=legend_dict)
|
81 |
-
|
82 |
-
m.to_streamlit(height=height)
|
83 |
-
|
84 |
-
|
85 |
-
app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/4_Choropleth.py
CHANGED
@@ -21,14 +21,15 @@ st.title("Choropleth")
|
|
21 |
|
22 |
with st.expander("See source code"):
|
23 |
with st.echo():
|
24 |
-
data = "https://raw.githubusercontent.com/yunusserhat/Github/main/data/
|
|
|
25 |
m = leafmap.Map(center=[51.50, -0.1], zoom=10)
|
26 |
m.add_data(
|
27 |
data,
|
28 |
column = "count",
|
29 |
-
scheme='
|
30 |
cmap='Blues',
|
31 |
-
legend_title='
|
32 |
)
|
33 |
|
34 |
m.to_streamlit(height=700)
|
|
|
21 |
|
22 |
with st.expander("See source code"):
|
23 |
with st.echo():
|
24 |
+
data = "https://raw.githubusercontent.com/yunusserhat/Github/main/data/boroughs_count_df_2022_dec.geojson"
|
25 |
+
|
26 |
m = leafmap.Map(center=[51.50, -0.1], zoom=10)
|
27 |
m.add_data(
|
28 |
data,
|
29 |
column = "count",
|
30 |
+
scheme='Quantiles',
|
31 |
cmap='Blues',
|
32 |
+
legend_title='Hate Tweets'
|
33 |
)
|
34 |
|
35 |
m.to_streamlit(height=700)
|