Skip to main content

Learn the fastest way to build data apps

Another post starts with you beautiful people!
I hope you have enjoyed and learned something new from my previous three posts about machine learning model deployment. In one post we have learned How to deploy a model as FastAPI? In the second post, we have learned How to deploy a deep learning model as RestAPI? and in the third post, we have also learned How to scale your deep learning model API? If you are following my blog posts, you have seen how easily you have transit yourselves from aspiring to a mature data scientist. In this new post, I am going to share a new framework- Streamlit which will help you to easily create a beautiful app with Python only. I will show here how had I used the Streamlit framework to create an app for my YOLOv3 custom model.

What is Streamlit?
Streamlit’s open-source app framework is the easiest way for data scientists and machine learning engineers to create beautiful, performant apps in only a few hours!  All in pure Python. All for free. With this framework, building an app with ML/DL/NLP model is as easy as writing Python scripts.

Installing Streamlit?
To install Streamlit, open your activated virtual env in Anaconda Prompt, or if you have not one then create it. Then run the following command to install the Streamlit framework: pip install --upgrade streamlit
In my case, I have created a virtual env 'stream' in Anaconda Prompt with Python 3.7 and it looks like below-
Once the installation is done we can verify it by running its inbuilt help app with below command-
As soon as you run the above command, it will ask you to enter your email. Fill up your email and press enter. After this, a welcome screen will appear as well as in the next few seconds the sample app will open in a new tab in your default browser. The welcome console will look like below-

And the default app in the browser will look like below-

Click on the 'Choose a demo' dropdown. You will see their sample demo options-

Now click on any of the options. I selected the last option and it looks like below after the selection-
How beautiful it is, right! This demo app demonstrates a Pandas Dataframe representing the gross agricultural production for some years. Now scroll down a little bit and you will see the code used to build this beautiful app. See the complete code is in Python. The dataset 'agri.csv.gz' is imported from AWS S3 bucket location like we usually do while importing the data in csv format and rest in few lines the UI logic is written as per Streamlit framework-

Now I will jump to the actual demo of my app. Here I will show you how had I created an app for my object detection and recognition neural networks model. This YOLOv3 based model I created to detect wine bottles and recognized their names from the image. With Pycharm IDE I have created a project, then I created an empty folder 'model' . There I copied my model weights and configuration files. Next, I created the app.py file where I will write my code of image uploading, image preprocessing, passing the image to the model, and showing results in Streamlit UI.

Here, I show you my project structure in Pycharm IDE-
I have saves some sample images inside the images folder. the model folder contains weights and configuration files of my object detection and recognition models I trained on YOLOv3. app.py is my main file which will act as Streamlit application and contains logic to display bounding boxes and brand names in the image. brand_recognition.py is another file which contains logic to recognize the brand names. Based on your machine learning or deep learning model you can maintain this structure as you want. Here the main thing is to see how app.py is using Streamlit related features. Let's understand app.py structure-
In above code snippet, after importing required libraries I have defined the app layout containing title, header, and a slider. The 'st' object of Streamlit has many useful functions for UI which you can easily check in Pycharm IDE as soon as you type dot(.) after st object like below screenshot-
For details inbuilt functions please refer this official link. Next, I have defined a function to read the image. For this purpose I used OpenCV. Since OpenCV loads the image in BGR format I converted the image in RGB format otherwise your image will show in blue color-
Above this function, I used a cache decorator. The Streamlit cache allows our app to execute quickly even when loading data from the web, manipulating large datasets, or performing expensive computations. Based on your need you can add/remove this. After this, I have defined a function that contains YOLOv3 related logic- loading the weights and configuration files, getting the output layer, identifying the best bounding boxes, and recognized the brand names to the detected bottles. Here you can call or write your logic of your ML/DL model-
Inside the above yolo_v3() function in the last, I used the following Streamlit functions to display my final output image-

Next, for showing some sample images options in the left sidebar of the app I used st.sidebar.selectbox() function and passed some options there. You can think of this as a dropdown value. In the end, I read the given image using my read_img() function and then called the yolo_v3() function to show the output-

That's it we have our simple app is ready to test. For running the Streamlit server run following command: streamlit run app.py
Your default browser window open as soon the above command runs and you will see following look like screen-
Looks amazing right! With very few Python-like syntaxes of Streamlit, we have easily created an app for our model. No need of UI or JavaScript knowledge to create an app now. As a Data Scientist with Python knowledge now you can give more focus on your model performance and in less time without any help you can create an app also. That's the power of the Streamlit framework.

Let's move ahead and what if you want to give the user an option of uploading the image instead of static images? For this, we need only a few changes in our app.py file. Using Streamlit's .file_uploader() function, we can provide image uploading option to the user. We need to make the following changes in our app.py file to achieve this functionality-
Here I am going to open the uploaded image using PIL's Image module that's why we don't need to again open the image using cv2.imread() function and also we don't need to convert the image in RGB format. Next change is the comment the left sidebar sections and put the image upload option of Streamlit-


That's it. Our app is now ready. Restart the Streamlit server and you will see upload image option in the app like below screen-

 Click on the browse files link and upload an image to test your model. After uploading an image following look like screen will appear-

See, now our app is ready to test any new image user wants to check. With the Streamlit framework, we can now easily create an app with our ML/DL model. In this post, I shared you the basics of this amazing and powerful framework. The easiest way to master in using Streamlit is to try things out yourself. I know you have many ML/DL models to test and after reading this post you are very excited to create many apps for all of your models. So don't stop yourself! Use this post as reference, start creating your app, do more experiments with it's UI, and deploy your app in Heroku. Till then Go chase your dreams, have an awesome day, make every second count, and see you later in my next post.

Comments

  1. Post is really supportive to all of us. Eager that these kind of information you post in future also. Otherwise if anyone want to Learn Python, Data Science, Machine Learning Course Visit here- http://pythontrainingdelhi.com/

    python training center in delhi
    python training Course in delhi
    python training Institute in delhi

    ReplyDelete
  2. Here lot of valuable information is available, it is very useful information. We are technology/news/smartphone company, If you want to read such useful news then
    Visit us: https://techmie.com/

    ReplyDelete
  3. This is additionally a generally excellent post which I truly delighted in perusing. It isn't each day that I have the likelihood to see something like this..
    data science course

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    Data Science Course in Chennai

    ReplyDelete
  6. This is most useful and also this post most user Friendly and super Navigation to all posts... Thanks for Sharing a Valuable Information for Us... Keep going.

    sas training institute in delhi
    sas training Course in delhi

    ReplyDelete
  7. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective.

    Python Training Institute in South Delhi

    ReplyDelete
  8. Thanks for share. I have bookmarked this for future update.

    data analysis training course london

    ReplyDelete
  9. Excellence blog! Thanks For Sharing, The information provided by you is really a worthy. I read this blog and I got the more information about
    best data science course

    ReplyDelete
  10. Good information you shared. keep posting.
    <a href="https://360digitmg.com/india/data-analytics-certification-training-course-in-delhi>data analytics course delhi</a>

    ReplyDelete
  11. Excellent article for the people who need information about this course.
    Learn Data Science Online

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Very useful post for everyone,thanks for sharing.

    For Online MBA check below.

    Innomatics Research Labs is collaborated with JAIN (Deemed-to-be University) and offering the Online MBA in Business Intelligence,Business Analytics Program. This two-year program from JAIN (deemed-to-be) University offers foundation courses, core courses, Specialization courses, and a comprehensive master thesis intermediary, apart from an option to pursue a cross-functional and open elective.
    Online MBA in Business Analytics
    Online MBA in Business Intelligence

    ReplyDelete
  14. I want to leave a little comment to support and wish you the best of luck. We wish you the best of luck in all your blogging endeavors. Otherwise if any One Want to Learn Complete Python Training Course - No Coding Experience Required So Contact Us.

    Complete Python Training Course - No Coding Experience Required

    ReplyDelete
  15. Post is really supportive to all of us. Eager that these kind of information you post in future also. Otherwise if any One Want Experience Certificate for Fill your Career Gap So Contact Us-9599119376 Or Visit Website.

    Best Consultant for Experience Certificate Providers in Bangalore, India

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Excellent and very cool idea and great content of different kinds of the valuable information’s.

    Genuine Fake Experience Certificate Providers in Hyderabad, India

    ReplyDelete
  18. Very Nice Blog I like the way you explained these things. data science training delhi

    ReplyDelete
  19. Nice blog, Thanks for sharing this post with us. Keep sharing some more blogs again soon.
    Data Science Course
    Artificial Intelligence Course

    ReplyDelete

  20. Wow such an amazing content keep it up. I have bookmarked your page

    SASVBA Provides Best MERN STACK INSTITUTE IN DELHI
    with Latest Development Environment and Frameworks. We keep Our Courses Up to Date with the Latest industrial trends. SASVBA Is One of the best training. MERN Stack Institute in Delhi/NCR Which Helps Students to Crack Interviews in Tech Giants. We train college students as well as school students.

    ReplyDelete
  21. Want to Fill Your IT Career GAP? If you looking for the Best Certified and Trustable Experience Certificate Provider in Chennai, India So There are Lots of Consultancy Here But Dreamsoft Consultancy is The Best Consultancy.

    Experience Certificate Provider in Chennai- The Career of Your Life
    Experience Certificate Provider in Bangalore- Once Driven, Forever Career

    ReplyDelete
  22. Gone through your blog it is very knowledgeable and have very interesting fact.Dreamsoft is the 20 years old consultancy providing fake experience certificate in Noida To get fake experience certificate in Noida you can call at 9599119376 or can the visit https://experiencecertificates.com/experience-certificate-provider-in-Noida.html

    ReplyDelete
  23. Excellent NO doubt data science is an easy to learn and very powerful programming . Very information and Nicely explained. I would like to know more about it

    ReplyDelete
  24. Thanks for the information about Blogspot very informative for everyone
    data science course in chennai

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. Thanks for sharing the valuable information here. Keep sharing more informative articles. Regards by technokryon

    hire python developer india
    best data science companies
    professional cloud devops engineer

    ReplyDelete
  27. Data Science is very trending topic among students. I found this blog very much helpful for students to decide why to choose Data Science Training Course as a career.

    ReplyDelete
  28. I just found this blog and have high hopes for it to continue. I have added to my favorites. python course

    ReplyDelete
  29. Very nice blog keep sharing such amazing post. For Best Expert Training under industry expert trainers for best data science certification online Call Now 7070905090

    ReplyDelete
  30. Data science is most trending technology now-a-days for students. Thanks for sharing this informative blog. Learn more about Data Science from Data Science training institute in Delhi that provides training through certified trainers.

    ReplyDelete
  31. Caching & Data Streaming Platform (Genex data base)

    Caching for a long term memory to retrieve back and streaming on smooth service platform, all you need is Genex DB, which also is a all time king that deals and safe gaurds your data on a premium level and you don't have to worry about it.Remote Database Support


    We utilize industry best enterprise technologies to help create a content delivery network that accelerates content delivery. Now deliver multimedia content on multiple devices seamlessly. monitored by our professional technicians 24/7. Eliminate bottleneck for data access & processing to gain predictable latency & fast response time as your reach grows.
    We help your applications perform dramatically faster & cost significantly less to scale. Our range of support services for all leading caching systems will help you reduce complexity & cut technical and business risks, efficiently. Be assured that Our engineers work side-by-side with your development, DevOps, Ops, and management teams to assist with design, optimization, upgrades, audits, monitoring, training, and troubleshooting.

    ReplyDelete
  32. Well Written. Streamlit is open source and fee framework to built web apps of data science and machine learning. Python course in Greater Noida is the best learning place where students can learn also about streamlit.

    ReplyDelete
  33. Thank you for sharing this insightful content. I always appreciate coming across such superb material filled with valuable information. The ideas presented are truly excellent and captivating, which makes the post thoroughly enjoyable. Keep up the fantastic work, and please continue to share your valuable insights with us.
    visit: Environmental Data Analytics for Sustainability: A Pathway to a Greener Future

    ReplyDelete
  34. Extremely Wow this information very useful for me It help me for my college Presentation."Gratitude flows as smoothly as data through Python! 🐍✨ The world of Data Science, powered by Python, opens doors to insights, solutions, and possibilities. It's where magic meets analytics, and I'm eternally thankful for this incredible journey.Full stack course is also a part of this It industry and wanted to more about please visit my article also.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to deploy your ML model as Fast API?

Another post starts with you beautiful people! Thank you all for showing so much interests in my last posts about object detection and recognition using YOLOv4. I was very happy to see many aspiring data scientists have learnt from my past three posts about using YOLOv4. Today I am going to share you all a new skill to learn. Most of you have seen my post about  deploying and consuming ML models as Flask API   where we have learnt to deploy and consume a keras model with Flask API  . In this post you are going to learn a new framework-  FastAPI to deploy your model as Rest API. After completing this post you will have a new industry standard skill. What is FastAPI? FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. It is easy to learn, fast to code and ready for production . Yes, you heard it right! Flask is not meant to be used in production but with FastAPI you can use your model in production wi

How to install and compile YOLO v4 with GPU enable settings in Windows 10?

Another post starts with you beautiful people! Last year I had shared a post about  installing and compiling Darknet YOLOv3   in your Windows machine and also how to detect an object using  YOLOv3 with Keras . This year on April' 2020 the fourth generation of YOLO has arrived and since then I was curious to use this as soon as possible. Due to my project (built on YOLOv3 :)) work I could not find a chance to check this latest release. Today I got some relief and successfully able to install and compile YOLOv4 in my machine. In this post I am going to share a single shot way to do the same in your Windows 10 machine. If your machine does not have GPU then you can follow my  previous post  by just replacing YOLOv3 related files with YOLOv4 files. For GPU having Windows machine, follow my steps to avoid any issue while building the Darknet repository. My machine has following configurations: Windows 10 64 bit Intel Core i7 16 GB RAM NVIDIA GeForce GTX 1660 Ti Version 445.87

How to use opencv-python with Darknet's YOLOv4?

Another post starts with you beautiful people 😊 Thank you all for messaging me your doubts about Darknet's YOLOv4. I am very happy to see in a very short amount of time my lovely aspiring data scientists have learned a state of the art object detection and recognition technique. If you are new to my blog and to computer vision then please check my following blog posts one by one- Setup Darknet's YOLOv4 Train custom dataset with YOLOv4 Create production-ready API of YOLOv4 model Create a web app for your YOLOv4 model Since now we have learned to use YOLOv4 built on Darknet's framework. In this post, I am going to share with you how can you use your trained YOLOv4 model with another awesome computer vision and machine learning software library-  OpenCV  and of course with Python 🐍. Yes, the Python wrapper of OpenCV library has just released it's latest version with support of YOLOv4 which you can install in your system using below command- pip install opencv-python --up