Yunus Serhat Bıçakçı commited on
Commit
5a7b734
1 Parent(s): 17daa05
Files changed (2) hide show
  1. pages/2_↔️_Comparision.py +108 -55
  2. pages/4_Test.py +1 -1
pages/2_↔️_Comparision.py CHANGED
@@ -1,93 +1,146 @@
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, Hate Crime Rates and Total 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 (MPS) data as of December 2022.
25
 
26
- In the first map shows the representation of hate tweets according to Twitter data, while the second and third maps shows the representation of rates of hate and all crimes according to MPS data.
27
- """
28
  )
29
 
30
- row1_col1, row1_col2, row1_col3 = st.columns([1, 1, 1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # Twitter Hate Tweets Map
33
  with row1_col1:
34
- twitter = "https://raw.githubusercontent.com/yunusserhat/data/main/data/boroughs_count_df_2022_dec.geojson"
35
  m1 = leafmap.Map(center=[51.50, -0.1], zoom=10)
36
- m1.add_data(
37
- twitter,
38
- column="count",
39
- scheme='Quantiles',
40
- cmap='YlOrRd',
41
- legend_title='Total Hate Tweet Number'
42
- )
43
-
44
- # MPS Hate Crimes Map
45
  with row1_col2:
46
- mps_hate = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps_hate_2022_dec_count.geojson"
47
  m2 = leafmap.Map(center=[51.50, -0.1], zoom=10)
48
- m2.add_data(
49
- mps_hate,
50
- column="Hate_Crime_Number",
51
- scheme='Quantiles',
52
- cmap='YlOrRd',
53
- legend_title='Hate Crime Number'
54
- )
55
-
56
- # MPS Total Crimes Map
57
- with row1_col3:
58
- mps_total = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps2022dec_count.geojson"
59
- m3 = leafmap.Map(center=[51.50, -0.1], zoom=10)
60
- m3.add_data(
61
- mps_total,
62
- column="Crime_Number",
63
- scheme='Quantiles',
64
- cmap='YlOrRd',
65
- legend_title='Total Crime Number'
66
- )
67
-
68
- row2_col1, row2_col2, row2_col3 = st.columns([1, 1, 1])
69
-
70
- # Setting the zoom and center for each map
71
  longitude = -0.1
72
  latitude = 51.50
73
  zoomlevel = st.number_input("Zoom", 0, 20, 10)
74
 
 
 
75
  with row2_col1:
76
  m1.set_center(longitude, latitude, zoomlevel)
77
-
78
  with row2_col2:
79
  m2.set_center(longitude, latitude, zoomlevel)
80
 
81
- with row2_col3:
82
- m3.set_center(longitude, latitude, zoomlevel)
83
-
84
- row3_col1, row3_col2, row3_col3 = st.columns([1, 1, 1])
85
 
86
  with row3_col1:
87
  m1.to_streamlit()
88
-
89
  with row3_col2:
90
  m2.to_streamlit()
91
-
92
- with row3_col3:
93
- m3.to_streamlit()
 
1
  import streamlit as st
2
  import leafmap.foliumap as leafmap
3
+ import json
4
+ import requests
5
+
6
+
7
+ # Functions to dynamically fetch columns
8
+ def get_columns_from_geojson(geojson_data):
9
+ """Retrieve column names from a GeoJSON data."""
10
+ if "features" in geojson_data:
11
+ properties = geojson_data["features"][0]["properties"]
12
+ return list(properties.keys())
13
+ return []
14
+
15
+
16
+ def get_columns_from_url(url):
17
+ """Retrieve column names from a GeoJSON URL."""
18
+ response = requests.get(url)
19
+ geojson_data = response.json()
20
+ return get_columns_from_geojson(geojson_data)
21
+
22
 
23
  st.set_page_config(layout="wide")
24
 
25
+ # Sidebar Information
26
  st.sidebar.info(
27
+ '''
28
  - Web App URL: <https://interactive-crime-map.hf.space/>
29
  - HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
30
+ '''
31
  )
32
 
33
  st.sidebar.title("Contact")
34
  st.sidebar.info(
35
+ '''
36
  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)
37
+ '''
38
  )
39
 
40
+ # Title and Description
41
+ st.title("Interactive Analysis of Hate Metrics in London & Custom Dataset Visualization")
42
+
43
  st.markdown(
44
+ '''
45
+ Dive into an interactive analysis of hate metrics in London, exploring the disparities and correlations between hate-related tweets and reported crimes in boroughs. This platform offers a comparative visualization based on data from X and the London Metropolitan Police Service as of December 2022.
46
 
47
+ Additionally, users can upload and visualize their own GeoJSON datasets, facilitating personalized analysis and insights. Delve deeper into the patterns of hate sentiment, understand how online behavior might mirror real-world incidents, or uncover patterns in your own data.
48
+ '''
49
  )
50
 
51
+ # File Uploader
52
+ uploaded_file = st.file_uploader("Upload a GeoJSON file", type=["geojson"])
53
+ uploaded_geojson = None
54
+
55
+ # Map URLs
56
+ map_1 = "https://raw.githubusercontent.com/yunusserhat/data/main/data/boroughs_count_df_2022_dec.geojson"
57
+ map_2 = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps_hate_2022_dec_count.geojson"
58
+ map_3 = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps2022dec_count.geojson"
59
+
60
+ if uploaded_file:
61
+ try:
62
+ uploaded_geojson = json.load(uploaded_file)
63
+ if "features" not in uploaded_geojson:
64
+ st.warning("The uploaded file does not seem to be a valid GeoJSON format.")
65
+ uploaded_geojson = None
66
+ else:
67
+ st.success("GeoJSON file uploaded successfully!")
68
+ except json.JSONDecodeError:
69
+ st.error("Failed to decode the uploaded file. Please ensure it's a valid GeoJSON format.")
70
+
71
+ # Map Selection
72
+ map_choices = ["Hate Tweets", "MPS Hate Crime Data", "MPS All Crime Data"]
73
+ if uploaded_geojson:
74
+ map_choices.append("Uploaded GeoJSON")
75
+
76
+ selected_map_1 = st.selectbox("Select data for Map 1", map_choices)
77
+
78
+ # Determine the columns based on the selected dataset for Map 1
79
+ if selected_map_1 == "Uploaded GeoJSON" and uploaded_geojson:
80
+ available_columns_1 = get_columns_from_geojson(uploaded_geojson)
81
+ elif selected_map_1 == "Hate Tweets":
82
+ available_columns_1 = get_columns_from_url(map_1)
83
+ elif selected_map_1 == "MPS Hate Crime Data":
84
+ available_columns_1 = get_columns_from_url(map_2)
85
+ elif selected_map_1 == "MPS All Crime Data":
86
+ available_columns_1 = get_columns_from_url(map_3)
87
+
88
+ selected_column_1 = st.selectbox("Select column for Map 1 visualization", available_columns_1)
89
+
90
+ selected_map_2 = st.selectbox("Select data for Map 2", map_choices)
91
+
92
+ # Determine the columns based on the selected dataset for Map 2
93
+ if selected_map_2 == "Uploaded GeoJSON" and uploaded_geojson:
94
+ available_columns_2 = get_columns_from_geojson(uploaded_geojson)
95
+ elif selected_map_2 == "Hate Tweets":
96
+ available_columns_2 = get_columns_from_url(map_1)
97
+ elif selected_map_2 == "MPS Hate Crime Data":
98
+ available_columns_2 = get_columns_from_url(map_2)
99
+ elif selected_map_2 == "MPS All Crime Data":
100
+ available_columns_2 = get_columns_from_url(map_3)
101
+
102
+ selected_column_2 = st.selectbox("Select column for Map 2 visualization", available_columns_2)
103
+
104
+ # Display Maps
105
+ row1_col1, row1_col2 = st.columns([1, 1])
106
 
 
107
  with row1_col1:
 
108
  m1 = leafmap.Map(center=[51.50, -0.1], zoom=10)
109
+ if selected_map_1 == "Uploaded GeoJSON":
110
+ m1.add_data(uploaded_geojson, column=selected_column_1)
111
+ elif selected_map_1 == "Hate Tweets":
112
+ m1.add_data(map_1, column=selected_column_1)
113
+ elif selected_map_1 == "MPS Hate Crime Data":
114
+ m1.add_data(map_2, column=selected_column_1)
115
+ else:
116
+ m1.add_data(map_3, column=selected_column_1)
117
+
118
  with row1_col2:
 
119
  m2 = leafmap.Map(center=[51.50, -0.1], zoom=10)
120
+ if selected_map_2 == "Uploaded GeoJSON":
121
+ m2.add_data(uploaded_geojson, column=selected_column_2)
122
+ elif selected_map_2 == "Hate Tweets":
123
+ m2.add_data(map_1, column=selected_column_2)
124
+ elif selected_map_2 == "MPS Hate Crime Data":
125
+ m2.add_data(map_2, column=selected_column_2)
126
+ else:
127
+ m2.add_data(map_3, column=selected_column_2)
128
+
129
+ # Zoom
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  longitude = -0.1
131
  latitude = 51.50
132
  zoomlevel = st.number_input("Zoom", 0, 20, 10)
133
 
134
+ row2_col1, row2_col2 = st.columns([1, 1])
135
+
136
  with row2_col1:
137
  m1.set_center(longitude, latitude, zoomlevel)
 
138
  with row2_col2:
139
  m2.set_center(longitude, latitude, zoomlevel)
140
 
141
+ row3_col1, row3_col2 = st.columns([1, 1])
 
 
 
142
 
143
  with row3_col1:
144
  m1.to_streamlit()
 
145
  with row3_col2:
146
  m2.to_streamlit()
 
 
 
pages/4_Test.py CHANGED
@@ -35,7 +35,7 @@ st.sidebar.info(
35
  )
36
 
37
  # Title and Description
38
- st.title("Interactive Analysis of Hate Metrics in London and & Custom Dataset Visualization")
39
 
40
  st.markdown(
41
  '''
 
35
  )
36
 
37
  # Title and Description
38
+ st.title("Interactive Analysis of Hate Metrics in London & Custom Dataset Visualization")
39
 
40
  st.markdown(
41
  '''