Spaces:
Sleeping
Sleeping
File size: 2,922 Bytes
6ffda89 5fcce91 6ffda89 457899a 6ffda89 457899a 6ffda89 be45a30 234c0d6 be45a30 6ffda89 3738059 6821c41 06a4cf3 a1e11d4 6821c41 3738059 df7b64e 3738059 6b8b268 5fcce91 2a9fc45 b278765 6821c41 6ffda89 370b5d8 6ffda89 3738059 6ffda89 3738059 6ffda89 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import numpy as np
import gradio as gr
import os
import pandas as pd
from datasets import load_dataset
import geopandas
import plotly.express as px
import plotly.graph_objects as go
Secret_token = os.getenv('token')
dataset_s = load_dataset("FDSRashid/taraf_by_year", token = Secret_token,split="train")
dataset = load_dataset("FDSRashid/edge_geo", token = Secret_token,split="train")
taraf_s = dataset_s.to_pandas()
merged_geo = dataset.to_pandas()
merged_geo["Coordinates"] = geopandas.GeoSeries.from_wkt(merged_geo["full_geom"])
geodf = geopandas.GeoDataFrame(merged_geo, geometry= 'Coordinates')
taraf_s = taraf_s.sort_values(['City', 'Year'], ascending=True)
cities = taraf_s['City'].unique().tolist()
min_year = int(taraf_s['Year'].min())
max_year = int(taraf_s['Year'].max())
def plot_taraf_map(yaxis,min_year = 0, max_year = 400, heat=False):
if min_year > max_year:
raise gr.Error('Minimum Year cannot be bigger than final ear!')
filtered = geodf[(geodf['Year'] >= min_year) & (geodf['Year'] <= max_year)]
temp = filtered[['City', yaxis]].groupby('City').sum().join(filtered[['City', 'Coordinates']].set_index('City'))
temp[f'{yaxis}_CubeRoot'] = temp[yaxis].apply(np.cbrt)
filtered = geopandas.GeoDataFrame(temp, geometry= 'Coordinates').reset_index()
if heat:
fig = px.density_mapbox(data_frame = filtered, lat = filtered.geometry.y, lon = filtered.geometry.x,z = yaxis, title = f'Map of {yaxis}', opacity = .5, hover_data = 'City',center=dict(lat=21.4241, lon=39.826168), radius=17, zoom=2)
else:
fig = px.scatter_mapbox(data_frame = filtered, lat = filtered.geometry.y, lon = filtered.geometry.x,size = f'{yaxis}_CubeRoot',color = yaxis, title = f'Map of {yaxis}', opacity = .5, hover_data = 'City',center=dict(lat=21.4241, lon=39.826168), zoom=2 )
fig.update_layout(title_font_color = 'red',margin=dict(l=0, r=0, b=0), title_x = .5, mapbox_style="white-bg", mapbox_layers=[
{
"below": 'traces',
"sourcetype": "raster",
"sourceattribution": "United States Geological Survey",
"source": [
"https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
]
}
])
return fig
with gr.Blocks() as demo:
Yaxis = gr.Dropdown(choices = ['Taraf', 'Hadith', 'Isnad'], value = 'Taraf', label = 'Variable to Display', info = 'Choose the variable to visualize.')
First_Year = gr.Slider(min_year, max_year, value = 0, label = 'Begining', info = 'Choose the first year to display Tarafs')
Last_Year = gr.Slider(min_year, max_year, value = 400, label = 'End', info = 'Choose the last year to display Tarafs')
heat = gr.Checkbox(label="Heat Map", info="View as Heat Map")
btn = gr.Button('Submit')
btn.click(fn = plot_taraf_map, inputs = [Yaxis, First_Year, Last_Year, heat], outputs = gr.Plot())
demo.launch() |