interactive-crime commited on
Commit
b5eee74
1 Parent(s): c6b286b

Delete pages/4_Test.py

Browse files
Files changed (1) hide show
  1. pages/4_Test.py +0 -143
pages/4_Test.py DELETED
@@ -1,143 +0,0 @@
1
- import streamlit as st
2
- import leafmap.foliumap as leafmap
3
- import json
4
- import requests
5
-
6
- # Functions to dynamically fetch columns
7
- def get_columns_from_geojson(geojson_data):
8
- """Retrieve column names from a GeoJSON data."""
9
- if "features" in geojson_data:
10
- properties = geojson_data["features"][0]["properties"]
11
- return list(properties.keys())
12
- return []
13
-
14
- def get_columns_from_url(url):
15
- """Retrieve column names from a GeoJSON URL."""
16
- response = requests.get(url)
17
- geojson_data = response.json()
18
- return get_columns_from_geojson(geojson_data)
19
-
20
- st.set_page_config(layout="wide")
21
-
22
- # Sidebar Information
23
- st.sidebar.info(
24
- '''
25
- - Web App URL: <https://interactive-crime-map.hf.space/>
26
- - HuggingFace repository: <https://huggingface.co/spaces/interactive-crime/map/tree/main>
27
- '''
28
- )
29
-
30
- st.sidebar.title("Contact")
31
- st.sidebar.info(
32
- '''
33
- 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)
34
- '''
35
- )
36
-
37
- # Title and Description
38
- st.title("Interactive Analysis of Hate Metrics in London & Custom Dataset Visualization")
39
-
40
- st.markdown(
41
- '''
42
- 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.
43
-
44
- 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.
45
- '''
46
- )
47
-
48
- # File Uploader
49
- uploaded_file = st.file_uploader("Upload a GeoJSON file", type=["geojson"])
50
- uploaded_geojson = None
51
-
52
- # Map URLs
53
- map_1 = "https://raw.githubusercontent.com/yunusserhat/data/main/data/boroughs_count_df_2022_dec.geojson"
54
- map_2 = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps_hate_2022_dec_count.geojson"
55
- map_3 = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps2022dec_count.geojson"
56
-
57
- if uploaded_file:
58
- try:
59
- uploaded_geojson = json.load(uploaded_file)
60
- if "features" not in uploaded_geojson:
61
- st.warning("The uploaded file does not seem to be a valid GeoJSON format.")
62
- uploaded_geojson = None
63
- else:
64
- st.success("GeoJSON file uploaded successfully!")
65
- except json.JSONDecodeError:
66
- st.error("Failed to decode the uploaded file. Please ensure it's a valid GeoJSON format.")
67
-
68
- # Map Selection
69
- map_choices = ["Hate Tweets", "MPS Hate Crime Data", "MPS All Crime Data"]
70
- if uploaded_geojson:
71
- map_choices.append("Uploaded GeoJSON")
72
-
73
- selected_map_1 = st.selectbox("Select data for Map 1", map_choices)
74
-
75
- # Determine the columns based on the selected dataset for Map 1
76
- if selected_map_1 == "Uploaded GeoJSON" and uploaded_geojson:
77
- available_columns_1 = get_columns_from_geojson(uploaded_geojson)
78
- elif selected_map_1 == "Hate Tweets":
79
- available_columns_1 = get_columns_from_url(map_1)
80
- elif selected_map_1 == "MPS Hate Crime Data":
81
- available_columns_1 = get_columns_from_url(map_2)
82
- elif selected_map_1 == "MPS All Crime Data":
83
- available_columns_1 = get_columns_from_url(map_3)
84
-
85
- selected_column_1 = st.selectbox("Select column for Map 1 visualization", available_columns_1)
86
-
87
- selected_map_2 = st.selectbox("Select data for Map 2", map_choices)
88
-
89
- # Determine the columns based on the selected dataset for Map 2
90
- if selected_map_2 == "Uploaded GeoJSON" and uploaded_geojson:
91
- available_columns_2 = get_columns_from_geojson(uploaded_geojson)
92
- elif selected_map_2 == "Hate Tweets":
93
- available_columns_2 = get_columns_from_url(map_1)
94
- elif selected_map_2 == "MPS Hate Crime Data":
95
- available_columns_2 = get_columns_from_url(map_2)
96
- elif selected_map_2 == "MPS All Crime Data":
97
- available_columns_2 = get_columns_from_url(map_3)
98
-
99
- selected_column_2 = st.selectbox("Select column for Map 2 visualization", available_columns_2)
100
-
101
- # Display Maps
102
- row1_col1, row1_col2 = st.columns([1, 1])
103
-
104
- with row1_col1:
105
- m1 = leafmap.Map(center=[51.50, -0.1], zoom=10)
106
- if selected_map_1 == "Uploaded GeoJSON":
107
- m1.add_data(uploaded_geojson, column=selected_column_1)
108
- elif selected_map_1 == "Hate Tweets":
109
- m1.add_data(map_1, column=selected_column_1)
110
- elif selected_map_1 == "MPS Hate Crime Data":
111
- m1.add_data(map_2, column=selected_column_1)
112
- else:
113
- m1.add_data(map_3, column=selected_column_1)
114
-
115
- with row1_col2:
116
- m2 = leafmap.Map(center=[51.50, -0.1], zoom=10)
117
- if selected_map_2 == "Uploaded GeoJSON":
118
- m2.add_data(uploaded_geojson, column=selected_column_2)
119
- elif selected_map_2 == "Hate Tweets":
120
- m2.add_data(map_1, column=selected_column_2)
121
- elif selected_map_2 == "MPS Hate Crime Data":
122
- m2.add_data(map_2, column=selected_column_2)
123
- else:
124
- m2.add_data(map_3, column=selected_column_2)
125
-
126
- # Zoom
127
- longitude = -0.1
128
- latitude = 51.50
129
- zoomlevel = st.number_input("Zoom", 0, 20, 10)
130
-
131
- row2_col1, row2_col2 = st.columns([1, 1])
132
-
133
- with row2_col1:
134
- m1.set_center(longitude, latitude, zoomlevel)
135
- with row2_col2:
136
- m2.set_center(longitude, latitude, zoomlevel)
137
-
138
- row3_col1, row3_col2 = st.columns([1, 1])
139
-
140
- with row3_col1:
141
- m1.to_streamlit()
142
- with row3_col2:
143
- m2.to_streamlit()