Stream Lit
Stream Lit
Streamlit is a free and open-source framework to rapidly build and share beautiful machine
learning and data science web apps. It is a Python-based library specifically designed for
machine learning engineers. Data scientists or machine learning engineers are not web
developers and they're not interested in spending weeks learning to use these frameworks
to build web apps. Instead, they want a tool that is easier to learn and to use, as long as it
can display data and collect needed parameters for modeling. Streamlit allows you to
create a stunning-looking application with only a few lines of code.
The local URL can be used from the current machine only
The network URL can be used from any machine to see the output file and the changes will
be reflected by refreshing the page.
Import Streamlit: -
We can import streamlit by the import command.
import streamlit as st
Title: -
We can create a title using the title tag.
st.title(‘Enter your text here’)
Header: -
We can create a header using the header tag.
st.header(‘Enter your text here’)
Subheader: -
We can create a subheader using the subheader tag.
st.subheader(‘Enter your text here’)
Text or paragraph: -
We can create a text using the text tag.
st.text(‘Enter your text here’)
Markdown: -
We can write inside markdown function in the same way we written in jupyter notebook.
Here the number of hashes defines the size of the text. More the number of hashes lesser
the size.
Success: -
We can write any success statement using the success function.
st.success(‘Enter your text here’)
Information: -
We can write any information statement using the info function.
st.info(‘Enter your text here’)
Warning: -
st.warning(‘Enter your text here’)
Error: -
st.error(‘Enter your text here’)
Exception: -
st.exception(‘exception’)
Example –
exp = ZeroDivisionError("Can't divide by 0")
st.exception(exp)
Help: -
The help function is used to see documentation for anything.
st.help(‘write here’)
Write: -
The write function is used to get better formatting for code segment or arithmetic equation
etc.
st.write(‘write here’)
Code: -
The code function is used to write code segments in the webpage.
st.code(‘codeline1\n’
‘codeline2\n’
‘codeline3…’)
Checkbox: -
st.checkbox(‘value1’)
st.checkbox(‘value2’)
st.checkbox(‘value3’)…
Button: -
st.button(‘buttonname’)
Access button click
var = st.button(‘buttonname’)
if(var):
--statement
Slider: -
st.slider(‘heading: ’,start, end, step = no of steps)
Access the slider value by using –
var = st.slider(‘heading: ’,start, end, step = no of steps)
if(var):
---statement
Text Input: -
st.text_input(‘Enter your message’)
The user input value can be accessed by using a variable
var = st.text_input(‘Enter your message’)
if(var):
--statement
Password Input: -
st.text_input(‘Enter your message’, type=‘password’)
Textarea: -
st.text_area(‘Enter your message’)
Input Number: -
st.number_input(‘Enter your message’,start,end)
Input Date: -
st.date_input(‘Enter your message’)
Input Time: -
st.time_input(‘Enter your message’)
Upload video: -
vid = st.file_uploader(‘Enter your message’,type=[‘mkv,‘mp4’,‘mov’])
We can display the uploaded file using the syntax –
if vid is not None:
st.video(vid)
Upload Audio: -
aud = st.file_uploader(‘Enter your message’,type=[‘mp3’])
We can display the uploaded file using the syntax –
if aud is not None:
st.audio(aud)
Line Chart: -
For making line chart first we need to make the dataframe. Let’s make the dataframe using
random values using the numpy random function and pandas.
Now we can make the line chart using the function ‘line_chart’
st.line_chart(datafram ename)
Area Chart: -
Using the same data, we can make it’s area chart using the ‘area_chart’ function.
st.area_chart(dataframename)
Bar Chart: -
Using the same data, we can make it’s bar chart using the ‘bar_chart’ function.
st.bar_chart(dataframename)
• We can set the style and context inside the theme function of seaborn.
sns.set_theme(context=‘contextname’, style=‘stylename’)
Scatter Plot: -
We can make scatter plot by using the scatter function.
Count Plot: -
We can make count plot by using the countplot function under seaborn.
Box Plot: -
We can make box plot by using the boxplot function under seaborn.
from the lang_data.csv we are reading the columns. Then we are selecting the language
from a multiselect dropdown and at the end we are making dataframe from the
selected values.
Interactive Area Chart: -
For the interactive area chart everything will be same as interactive line chart but only the
‘line_chart( )’ function will be replaced as ‘area_chart( )’.
Under “requirements.txt” we have to write the module names with their versions.
Here we’ve used only Streamlit so we will write only the version of streamlit.
• Now fill all these details and click deploy under the fields.
• Now the file is deployed, and we can find the link in the url bar.