Spaces:
Sleeping
Sleeping
Alealejandrooo
commited on
Commit
•
f65efd3
1
Parent(s):
9d0c835
Delete gradio/app.py
Browse files- gradio/app.py +0 -83
gradio/app.py
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from folium.plugins import HeatMap
|
3 |
-
from ingest import load_data
|
4 |
-
from process import get_lat_lon
|
5 |
-
from gradio_folium import Folium
|
6 |
-
from folium import Map
|
7 |
-
|
8 |
-
|
9 |
-
def update_header(file_info):
|
10 |
-
if file_info is not None:
|
11 |
-
filename = file_info.split('/')[-1] # Access the filename from the file_info dictionary
|
12 |
-
header = f"<h1>Postcodes Map: {filename}</h1>" # Update the Markdown content
|
13 |
-
return header # Continue to pass the file_info to the next function if necessary
|
14 |
-
|
15 |
-
def generate_map(file_path):
|
16 |
-
# Load the postcodes
|
17 |
-
postcode_mapping = load_data('../data/ukpostcodes.csv')
|
18 |
-
# Load the data (this needs to be adapted to work outside Flask)
|
19 |
-
postcodes = load_data(file_path)
|
20 |
-
|
21 |
-
# Get latitude, longitude, and count data for the specified postcodes
|
22 |
-
lat_lon_data = get_lat_lon(postcodes, postcode_mapping)
|
23 |
-
|
24 |
-
# Prepare data for different frequency bands
|
25 |
-
low_freq_data = [
|
26 |
-
[data['latitude'], data['longitude']]
|
27 |
-
for data in lat_lon_data
|
28 |
-
if data['count'] == 1 and data['latitude'] and data['longitude']
|
29 |
-
]
|
30 |
-
med_freq_data = [
|
31 |
-
[data['latitude'], data['longitude']]
|
32 |
-
for data in lat_lon_data
|
33 |
-
if 2 <= data['count'] <= 5 and data['latitude'] and data['longitude']
|
34 |
-
]
|
35 |
-
high_freq_data = [
|
36 |
-
[data['latitude'], data['longitude']]
|
37 |
-
for data in lat_lon_data
|
38 |
-
if data['count'] > 5 and data['latitude'] and data['longitude']
|
39 |
-
]
|
40 |
-
|
41 |
-
# Create your map here using Folium
|
42 |
-
map = Map(location=[51.505303, -0.13902], zoom_start=10)
|
43 |
-
|
44 |
-
# Adding different heatmaps for different frequencies
|
45 |
-
if low_freq_data:
|
46 |
-
HeatMap(low_freq_data, radius=10, blur=10, gradient={0.8: 'blue', 1: 'lime'}).add_to(map)
|
47 |
-
if med_freq_data:
|
48 |
-
HeatMap(med_freq_data, radius=15, blur=10, gradient={0.8: 'orange', 1: 'lime'}).add_to(map)
|
49 |
-
if high_freq_data:
|
50 |
-
HeatMap(high_freq_data, radius=20, blur=10, gradient={0.8: 'red', 1: 'lime'}).add_to(map)
|
51 |
-
|
52 |
-
return map
|
53 |
-
|
54 |
-
# Define a Gradio interface
|
55 |
-
with gr.Blocks() as demo:
|
56 |
-
|
57 |
-
with gr.Row():
|
58 |
-
header = gr.Markdown(("<h1>Postcodes Map</h1>"))
|
59 |
-
|
60 |
-
with gr.Row():
|
61 |
-
map = Folium(value = Map(location=[51.505303, -0.13902], zoom_start=10), height=750)
|
62 |
-
|
63 |
-
|
64 |
-
with gr.Row():
|
65 |
-
file_uploader = gr.UploadButton(
|
66 |
-
label=("Upload"),
|
67 |
-
file_count="single",
|
68 |
-
file_types=[".csv", ".xlsx", '.xls'],
|
69 |
-
interactive=True,
|
70 |
-
scale=1,
|
71 |
-
)
|
72 |
-
|
73 |
-
file_uploader.upload(fn = generate_map,
|
74 |
-
inputs= file_uploader,
|
75 |
-
outputs=map)
|
76 |
-
|
77 |
-
file_uploader.upload(fn=update_header,
|
78 |
-
inputs=file_uploader,
|
79 |
-
outputs=header)
|
80 |
-
|
81 |
-
|
82 |
-
if __name__ == "__main__":
|
83 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|