Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
1 |
---
|
2 |
+
title: Gradio Maps Latitude Longitude
|
3 |
+
emoji: 5-Map🌖
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: green
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.16.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
US.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
app.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
dataset = load_dataset('text', data_files={'train': ['NPI_2023_01_17-05.10.57.PM.csv'], 'test': 'NPI_2023_01_17-05.10.57.PM.csv'})
|
7 |
+
#1.6GB NPI file with MH therapy taxonomy provider codes (NUCC based) with human friendly replacement labels (e.g. Counselor rather than code)
|
8 |
+
datasetNYC = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
|
9 |
+
df = datasetNYC.to_pandas()
|
10 |
+
|
11 |
+
def MatchText(pddf, name):
|
12 |
+
pd.set_option("display.max_rows", None)
|
13 |
+
data = pddf
|
14 |
+
swith=data.loc[data['text'].str.contains(name, case=False, na=False)]
|
15 |
+
return swith
|
16 |
+
|
17 |
+
def getDatasetFind(findString):
|
18 |
+
#finder = dataset.filter(lambda example: example['text'].find(findString))
|
19 |
+
finder = dataset['train'].filter(lambda example: example['text'].find(findString))
|
20 |
+
finder = finder = finder.to_pandas()
|
21 |
+
g1=MatchText(finder, findString)
|
22 |
+
return g1
|
23 |
+
|
24 |
+
def filter_map(min_price, max_price, boroughs):
|
25 |
+
filtered_df = df[(df['neighbourhood_group'].isin(boroughs)) & (df['price'] > min_price) & (df['price'] < max_price)]
|
26 |
+
names = filtered_df["name"].tolist()
|
27 |
+
prices = filtered_df["price"].tolist()
|
28 |
+
text_list = [(names[i], prices[i]) for i in range(0, len(names))]
|
29 |
+
|
30 |
+
fig = go.Figure(go.Scattermapbox(
|
31 |
+
customdata=text_list,
|
32 |
+
lat=filtered_df['latitude'].tolist(),
|
33 |
+
lon=filtered_df['longitude'].tolist(),
|
34 |
+
mode='markers',
|
35 |
+
marker=go.scattermapbox.Marker(
|
36 |
+
size=6
|
37 |
+
),
|
38 |
+
hoverinfo="text",
|
39 |
+
hovertemplate='Name: %{customdata[0]}Price: $%{customdata[1]}'
|
40 |
+
))
|
41 |
+
|
42 |
+
fig.update_layout(
|
43 |
+
mapbox_style="open-street-map",
|
44 |
+
hovermode='closest',
|
45 |
+
mapbox=dict(
|
46 |
+
bearing=0,
|
47 |
+
center=go.layout.mapbox.Center(
|
48 |
+
lat=40.67,
|
49 |
+
lon=-73.90
|
50 |
+
),
|
51 |
+
pitch=0,
|
52 |
+
zoom=9
|
53 |
+
),
|
54 |
+
)
|
55 |
+
return fig
|
56 |
+
|
57 |
+
def centerMap(min_price, max_price, boroughs):
|
58 |
+
filtered_df = df[(df['neighbourhood_group'].isin(boroughs)) & (df['price'] > min_price) & (df['price'] < max_price)]
|
59 |
+
names = filtered_df["name"].tolist()
|
60 |
+
prices = filtered_df["price"].tolist()
|
61 |
+
text_list = [(names[i], prices[i]) for i in range(0, len(names))]
|
62 |
+
|
63 |
+
latitude = 44.9382
|
64 |
+
longitude = -93.6561
|
65 |
+
|
66 |
+
fig = go.Figure(go.Scattermapbox(
|
67 |
+
customdata=text_list,
|
68 |
+
lat=filtered_df['latitude'].tolist(),
|
69 |
+
lon=filtered_df['longitude'].tolist(), mode='markers',
|
70 |
+
marker=go.scattermapbox.Marker(
|
71 |
+
size=6
|
72 |
+
),
|
73 |
+
hoverinfo="text",
|
74 |
+
#hovertemplate='Lat: %{lat} Long:%{lng} City: %{cityNm}'
|
75 |
+
))
|
76 |
+
|
77 |
+
fig.update_layout(
|
78 |
+
mapbox_style="open-street-map",
|
79 |
+
hovermode='closest',
|
80 |
+
mapbox=dict(
|
81 |
+
bearing=0,
|
82 |
+
center=go.layout.mapbox.Center(
|
83 |
+
lat=latitude,
|
84 |
+
lon=longitude
|
85 |
+
),
|
86 |
+
pitch=0,
|
87 |
+
zoom=9
|
88 |
+
),
|
89 |
+
)
|
90 |
+
return fig
|
91 |
+
|
92 |
+
|
93 |
+
with gr.Blocks() as demo:
|
94 |
+
with gr.Column():
|
95 |
+
|
96 |
+
# Price/Boroughs/Map/Filter for AirBnB
|
97 |
+
with gr.Row():
|
98 |
+
min_price = gr.Number(value=250, label="Minimum Price")
|
99 |
+
max_price = gr.Number(value=1000, label="Maximum Price")
|
100 |
+
boroughs = gr.CheckboxGroup(choices=["Queens", "Brooklyn", "Manhattan", "Bronx", "Staten Island"], value=["Queens", "Brooklyn"], label="Select Boroughs:")
|
101 |
+
btn = gr.Button(value="Update Filter")
|
102 |
+
map = gr.Plot().style()
|
103 |
+
|
104 |
+
# Mental Health Provider Finder
|
105 |
+
with gr.Row():
|
106 |
+
df20 = gr.Textbox(lines=4, default="", label="Find Mental Health Provider e.g. City/State/Name/License:")
|
107 |
+
btn2 = gr.Button(value="Find")
|
108 |
+
with gr.Row():
|
109 |
+
df4 = gr.Dataframe(wrap=True, max_rows=10000, overflow_row_behaviour= "paginate")
|
110 |
+
|
111 |
+
# City Map
|
112 |
+
with gr.Row():
|
113 |
+
df2 = gr.Textbox(lines=1, default="Mound", label="Find City:")
|
114 |
+
latitudeUI = gr.Textbox(lines=1, default="44.9382", label="Latitude:")
|
115 |
+
longitudeUI = gr.Textbox(lines=1, default="-93.6561", label="Longitude:")
|
116 |
+
btn3 = gr.Button(value="Lat-Long")
|
117 |
+
|
118 |
+
demo.load(filter_map, [min_price, max_price, boroughs], map)
|
119 |
+
|
120 |
+
btn.click(filter_map, [min_price, max_price, boroughs], map)
|
121 |
+
btn2.click(getDatasetFind,df20,df4 )
|
122 |
+
# Lookup on US once you have city to get lat/long
|
123 |
+
# US 55364 Mound Minnesota MN Hennepin 053 44.9382 -93.6561 4
|
124 |
+
#latitude = 44.9382
|
125 |
+
#longitude = -93.6561
|
126 |
+
#btn3.click(centerMap, map)
|
127 |
+
|
128 |
+
btn3.click(centerMap, [min_price, max_price, boroughs], map)
|
129 |
+
|
130 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
plotly
|