Streamlit

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.

HTML

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.

  1. starter template
    install streamlit

    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
                    
                
  2. streamlit code run
                    
            streamlit run filename.py
    
                    
  3. import streamlit
        
            # import module
            import streamlit as st
    
    
  4. import sidebar
        
            from streamlit_option_menu import option_menu
    
    
  5. sidebar
        
            # sidebar
    with st.sidebar:
        selected = option_menu('Multiple Disease Prediction', [
            
            'Dashboard',
            'Blogs'
        ],
            icons=['','activity', 'heart', 'person'],
            default_index=0)
    
    
  6. Input and output
        
            # 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)
    
    
  7. title
        
            # Title
            st.title("  ")
    
    
  8. header
        
            # Header
    st.header("   ")
    
    
  9. subheader
                    
            # Subheader
            st.subheader("   ")
    
                    
  10. text
        
            # Text
            st.text("   ")
    
    
  11. Markdown
        
            # Markdown
            st.markdown("### This is a markdown")        
    
    
  12. Success, Info, Warning, Error, Exception

                    
                        # success
                        st.success("   ")                    
                
                

                                         # info
                                            st.info("    ")
                                

                                        # warning
                                            st.warning("    ")
                                

                                        # error
                                            st.error("    ")
                                
  13. Write text
    Write text
    Using write function, we can also display code in coding format. This is not possible using st.text(”).
    
        st.write("  ")
    
    
  14. Writing python inbuilt function range()
        
            st.write(range(   ))
        
        
        
  15. Display Images
    Display Images
    import Image from pillow to open images
    display image using streamlit
    width is used to set the width of an image
            
    from PIL import Image
    img = Image.open("streamlit.png")st.image(img,caption='   ', width=200)
            
            
  16. checkbox
    checkbox
    A checkbox returns a boolean value. When the box is checked, it returns a True value else returns a False value.
                
                    # checkboxif st.checkbox("Show/Hide"):
    st.text("Showing the widget") 
                
                
                
  17. Radio button
                    
                        # radio buttonstatus = st.radio("Select Gender: ", ('Male', 'Female'))if (status == 'Male'):
        st.success("Male")
    else:
        st.success("Female")
                    
                    
                    
  18. Selection Box
                        
    # Selection box
    hobby = st.selectbox("Hobbies: ",['Dancing', 'Reading', 'Sports'])st.write("Your hobby is: ", hobby)
                        
                        
                        
  19. Multi-Selectbox
                            
                                # multi select box
                                hobbies = st.multiselect("Hobbies: ",['Dancing', 'Reading', 'Sports'])
                                 
                                st.write("You selected", len(hobbies), 'hobbies')
                            
                            
  20. Button
                                
                                    # 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!!!")
                                
                                
  21. Text Input
                                    
                                        # Text Input
                                        name = st.text_input("Enter Your name", "Type Here ...")
                                         
                                        if(st.button('Submit')):
                                            result = name.title()
                                            st.success(result)
                                    
                                    
  22. Slider
                                        # slider
                                            level = st.slider("Select the level", 1, 5)
                                            
                                            st.text('Selected: {}'.format(level))