Skip to content

Instantly share code, notes, and snippets.

@nikkisharma536
nikkisharma536 / animated_map.py
Created June 11, 2020 09:37
Streamlit animated map
## MAP
# Variable for date picker, default to Jan 1st 2020
date = datetime.date(2020,1,1)
# Set viewport for the deckgl map
view = pdk.ViewState(latitude=0, longitude=0, zoom=0.2,)
# Create the scatter plot layer
covidLayer = pdk.Layer(
"ScatterplotLayer",
data=df,
@nikkisharma536
nikkisharma536 / line_charts.py
Created June 11, 2020 09:36
Streamlit altair / line charts
## linechart
st.subheader('Comparision of infection growth')
total_cases_graph =alt.Chart(subset_data).transform_filter(
alt.datum.total_cases > 0
).mark_line().encode(
x=alt.X('date', type='nominal', title='Date'),
y=alt.Y('sum(total_cases):Q', title='Confirmed cases'),
color='Country',
tooltip = 'sum(total_cases)',
@nikkisharma536
nikkisharma536 / bar_graph.py
Created June 11, 2020 09:35
Streamlit bar graph
filter_data = df[df['Date'] >='2020-04-01'].set_index("Date") 
st.markdown(str(','.join(country_name_input)) + " daily Death cases from 1st April 2020")
# bar chart
st.bar_chart(filter_data[['Deaths']])
@nikkisharma536
nikkisharma536 / select_box_widget.py
Created June 11, 2020 09:34
Streamlit select box widget
metrics =['total_cases','new_cases','total_deaths','new_deaths','total_cases_per_million','new_cases_per_million','total_deaths_per_million','new_deaths_per_million','total_tests','new_tests','total_tests_per_thousand','new_tests_per_thousand']
cols = st.selectbox('Covid metric to view', metrics)
# let's ask the user which column should be used as Index
if cols in metrics:
metric_to_show_in_covid_Layer = cols
@nikkisharma536
nikkisharma536 / multi_select_widget.py
Created June 11, 2020 09:33
Multi select widget with streamlit
# Filters UI
subset_data = df
country_name_input = st.sidebar.multiselect(
'Country name',
df.groupby('Country/Region').count().reset_index()['Country/Region'].tolist())
# by country name
if len(country_name_input) > 0:
subset_data = df[df['Country/Region'].isin(country_name_input)]
@nikkisharma536
nikkisharma536 / load_data.py
Last active June 11, 2020 11:41
Load data with streamlit
DATA_URL = ('covid.csv')
@st.cache
def load_data():
data = pd.read_csv(DATA_URL)
data['Date'] = pd.to_datetime(data['Date']).dt.strftime('%Y-%m-%d')
return data
df = load_data()
# show data on streamlit
st.write(df)
from math import nan
words = list(set(data["word"].values))
n_words = len(words)
tags = []
for tag in set(data["tag"].values):
if tag is nan or isinstance(tag, float):
tags.append('unk')
else:
from math import nan
words = list(set(data["word"].values))
n_words = len(words)
tags = []
for tag in set(data["tag"].values):
if tag is nan or isinstance(tag, float):
tags.append('unk')
else:
from keras.callbacks import ModelCheckpoint
import matplotlib.pyplot as plt
#Optimiser
adam = k.optimizers.Adam(lr=0.0005, beta_1=0.9, beta_2=0.999)
# Compile model
model.compile(optimizer=adam, loss=crf.loss_function, metrics=[crf.accuracy, 'accuracy'])
model.summary()
from keras.models import Model, Input
from keras.layers import LSTM, Embedding, Dense, TimeDistributed, Dropout, Bidirectional
import keras as k
from keras_contrib.layers import CRF
input = Input(shape=(672,))
word_embedding_size = 150
# Embedding Layer
model = Embedding(input_dim=n_words, output_dim=word_embedding_size, input_length=672)(input)