Adrien Treuille, Thiago Teixeira, and Amanda Kelly created “Streamlit”. Now using streamlit you can deploy any machine learning model and any python project with ease and without worrying about the frontend. Streamlit is very user-friendly.
The trend of Data Science and Analytics is increasing day by day. From the data science pipeline, one of the most important steps is model deployment. We have a lot of options in python for deploying our model.
Some popular
frameworks are Flask and Django.
But the issue with using these frameworks is that we should have some knowledge of HTML, CSS, and JavaScript. Keeping these prerequisites in mind, Adrien Treuille, Thiago Teixeira, and Amanda
Kelly created “Streamlit”.
Now using streamlit you can deploy any machine learning model and any python project with ease and without worrying about the frontend. Streamlit is very user-friendly.
Streamlit is an open source app framework in python language. It helps us create beautiful web-apps for data science and machine learning in a little time. It is compatible with major python libraries such as scikit-learn,
keras, pytorch, latex, numpy, pandas, matplotlib, etc.. Syntax for installing this library is shown below.
Advantages:
1. It embraces python-scripting.
2. Less code is needed to create amazing web-apps.
3. No callbacks are needed since widgets are treated as variables.
4. Data caching simplifies and speeds up computation pipelines.
Disadvantages:
1. Streamlit’s Data caching cannot keep track of changes to the data happening outside the function body.
Once Streamlit is installed successfully, run the given python code and if you do not get an error, then streamlit is successfully installed and you can now work with streamlit.
pip install streamlit
streamlit run filename.py
# import module
import streamlit as st
from streamlit_option_menu import option_menu
# sidebar
with st.sidebar:
selected = option_menu('Multiple Disease Prediction', [
'Dashboard',
'Blogs'
],
icons=['','activity', 'heart', 'person'],
default_index=0)
# Diabetes prediction page
if selected == 'Diabetes prediction': # pagetitle
st.title("Diabetes disease prediction")
image = Image.open('d3.jpg')
st.image(image, caption='diabetes disease prediction')
# columns
# no inputs from the user
name = st.text_input("Name:")
col1, col2, col3 = st.columns(3)
with col1:
Pregnancies = st.number_input("Number of Pregnencies")
with col2:
Glucose = st.number_input("Glucose level")
with col3:
BloodPressure = st.number_input("Blood pressure value")
# code for prediction
diabetes_dig = ''
# button
if st.button("Diabetes test result"):
diabetes_prediction=[[]]
diabetes_prediction = diabetes_model.predict(
[[Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreefunction, Age]])
# after the prediction is done if the value in the list at index is 0 is 1 then the person is diabetic
if diabetes_prediction[0] == 1:
diabetes_dig = "we are really sorry to say but it seems like you are Diabetic."
image = Image.open('positive.jpg')
st.image(image, caption='')
else:
diabetes_dig = 'Congratulation,You are not diabetic'
image = Image.open('negative.jpg')
st.image(image, caption='')
st.success(name+' , ' + diabetes_dig)
# Title
st.title(" ")
# Header
st.header(" ")
# Subheader
st.subheader(" ")
# Text
st.text(" ")
# Markdown
st.markdown("### This is a markdown")
# success
st.success(" ")
# info
st.info(" ")
# warning
st.warning(" ")
# error
st.error(" ")
st.write(" ")
st.write(range( ))
from PIL import Image
img = Image.open("streamlit.png")st.image(img,caption=' ', width=200)
# checkboxif st.checkbox("Show/Hide"):
st.text("Showing the widget")
# radio buttonstatus = st.radio("Select Gender: ", ('Male', 'Female'))if (status == 'Male'):
st.success("Male")
else:
st.success("Female")
# Selection box
hobby = st.selectbox("Hobbies: ",['Dancing', 'Reading', 'Sports'])st.write("Your hobby is: ", hobby)
# multi select box
hobbies = st.multiselect("Hobbies: ",['Dancing', 'Reading', 'Sports'])
st.write("You selected", len(hobbies), 'hobbies')
# Create a simple button that does nothing
st.button("Click me for no reason")
# Create a button, that when clicked, shows a text
if(st.button("About")):
st.text("Welcome To GeeksForGeeks!!!")
# Text Input
name = st.text_input("Enter Your name", "Type Here ...")
if(st.button('Submit')):
result = name.title()
st.success(result)
# slider
level = st.slider("Select the level", 1, 5)
st.text('Selected: {}'.format(level))