How to Deploy StreamlitApp?
Tags: streamlitdeployment, streamlit, pipreqs, gitbook
Published: 2020-10-25 17:42:02

---

![Flow.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603644112660/2dCKPmTfO.png)

- **Prerequisites**
    - Requirements.txt file
    - Github account
    - Access to [share.streamlit.io](http://share.streamlit.io/)

- **Detailed Procedure**
    1. Run the command **'pip freeze > requirements.txt'** (Traditional way - Not recommended due to other packages)
    **Alternate(Recommended)** way install the package
        a) pip install pipreqs
        b) open the command prompt and run pipreqs 'path of the python file'
           Eg:- pipreqs C:\projects\streamlit or 'pipreqs .\'
    2. Commit the [app.py](http://app.py/)(code) files in to git hub repository. Refer the sample code in the Application section.
        - **Application**
            - **Convert Image to Pencil Sketch Image**
                ```python
                # Image to Pencil sketch app
                import streamlit as st
                import numpy as np
                from PIL import Image
                import cv2                st.set_option('deprecation.showfileUploaderEncoding', False)
                def dodgeV2(x, y):
                    return cv2.divide(x, 255 - y, scale=256)
                def pencilsketch(inp_img):
                    img_gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
                    img_invert = cv2.bitwise_not(img_gray)
                    img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)
                    final_img = dodgeV2(img_gray, img_smoothing)
                    return(final_img)

                st.title("PencilSketcher App")
                st.write("This Web App is to help convert your photos to realistic Pencil Sketches")

                file_image = st.sidebar.file_uploader("Upload your Photos", type=['jpeg','jpg','png'])

                if file_image is None:
                    st.write("You haven't uploaded any image file")
                else:
                    input_img = Image.open(file_image)
                    final_sketch = pencilsketch(np.array(input_img))
                    st.write("**Input Photo**")
                    st.image(input_img, use_column_width=True)
                    st.write("**Output Pencil Sketch**")
                    st.image(final_sketch, use_column_width=True)
                ```

            - **Simple App**

                ```python
                import streamlit as st
                def main():
                        st.title('App Deployment')
                	st.subheader("Welcome to simple streamlit app")
                	st.text("Simple example")
                	st.balloons()

                if __name__ == '__main__':    
                    main()
                ```
3.Login to [https://share.streamlit.io/](https://share.streamlit.io/) and Select the github project and file location as shown in the steps below,
       - Login to [https://share.streamlit.io/](https://share.streamlit.io/) using github credentials and click on **'New app'**![Untitled.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603644252727/dqIkSlLhX.png)
       - Enter the github repository, branch and file name (app.py) and click on **'Deploy'**![Untitled 1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603644288287/h6hEsE5_6.png)                
       - Once deployment is successful it will generate the url [**https://share.streamlit.io/githubuser/projectname/application.py](https://share.streamlit.io/surendraredd/mlstreamlitapp/app.py)  or [https://share.streamlit.io/](https://share.streamlit.io/)[user name]/[repo name]**
       - Click on **'vertical dots' or 'manageapp'** to show the details of the application log.![Untitled 2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603644404808/o-hMKrPLZ.png)
![Untitled 3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603644421791/Cztj4yQe_.png)
                

- **References**    [https://docs.streamlit.io/en/stable/deploy_streamlit_app.html](https://docs.streamlit.io/en/stable/deploy_streamlit_app.html)


- **GitHub & Documentation Details**
    - [Source Code](https://github.com/SurendraRedd/MLStreamlitApp)
    - [Github url](https://surendraredd.github.io/MLStreamlitApp/)
    - [Gitbook url](https://app.gitbook.com/@surendraelectronics/s/ups/streamlitapp-deployment)
    - [Notion url](https://www.notion.so/learn2020/Deployment-StreamlitApp-3c380e67d98b4ccbbaf23c9812ea0b9e)