Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
import pandas as pd
|
5 |
+
from datasets import load_dataset
|
6 |
+
import geopandas
|
7 |
+
import plotly.express as px
|
8 |
+
|
9 |
+
Secret_token = os.getenv('token')
|
10 |
+
dataset = load_dataset("FDSRashid/taraf_geo", token = Secret_token,split="train")
|
11 |
+
dataset_s = load_dataset("FDSRashid/taraf_by_year", token = Secret_token,split="train")
|
12 |
+
|
13 |
+
taraf_s = dataset_s.to_pandas()
|
14 |
+
merged_geo = dataset.to_pandas()
|
15 |
+
merged_geo = merged_geo.drop(['Unnamed: 0'], axis = 1)
|
16 |
+
merged_geo["Coordinates"] = geopandas.GeoSeries.from_wkt(merged_geo["geometry"])
|
17 |
+
geodf = geopandas.GeoDataFrame(merged_geo, geometry= 'Coordinates').drop(['geometry'], axis = 1)
|
18 |
+
|
19 |
+
|
20 |
+
taraf_s = taraf_s.sort_values(['City', 'Year'], ascending=True)
|
21 |
+
cities = taraf_s['City'].unique().tolist()
|
22 |
+
min_year = int(taraf_s['Year'].min())
|
23 |
+
max_year = int(taraf_s['Year'].max())
|
24 |
+
|
25 |
+
|
26 |
+
def plot_taraf_map(min_year = 0, max_year = 400):
|
27 |
+
filtered = geodf[(geodf['Year'] >= min_year) & (geodf['Year'] <= max_year)]
|
28 |
+
temp = filtered[['City', 'Taraf']].groupby('City').sum().join(filtered[['City', 'Coordinates']].set_index('City'))
|
29 |
+
filtered = geopandas.GeoDataFrame(temp, geometry= 'Coordinates').reset_index()
|
30 |
+
fig = px.density_mapbox(data_frame = filtered, lat = filtered.geometry.y, lon = filtered.geometry.x,z = filtered.Taraf, title = 'Number of Tarafs in Place', opacity = .7)
|
31 |
+
fig.update_layout(title_font_color = 'red', title_x = .5, mapbox_style="stamen-terrain")
|
32 |
+
return fig
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
with gr.Blocks() as demo:
|
38 |
+
First_Year = gr.Slider(min_year, max_year, value = 0, label = 'Begining', info = 'Choose the first year to display Tarafs')
|
39 |
+
Last_Year = gr.Slider(min_year, max_year, value = 400, label = 'End', info = 'Choose the last year to display Tarafs')
|
40 |
+
btn = gr.Button('Submit')
|
41 |
+
btn.click(fn = plot_taraf_map, inputs = [First_Year, Last_Year], outputs = gr.Plot())
|
42 |
+
demo.launch()
|