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.
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-
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.
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/
ReplyDeletepython training center in delhi
python training Course in delhi
python training Institute in delhi
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
ReplyDeleteVisit us: https://techmie.com/
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..
ReplyDeletedata science course
This comment has been removed by the author.
ReplyDeleteWow 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.
ReplyDeleteData Science Course in Chennai
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.
ReplyDeletesas training institute in delhi
sas training Course in delhi
Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective.
ReplyDeletePython Training Institute in South Delhi
Thanks for share. I have bookmarked this for future update.
ReplyDeletedata analysis training course london
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
ReplyDeletebest data science course
Thanks for sharing this Information. Data Science Training Course in Gurgaon
ReplyDeleteGood information you shared. keep posting.
ReplyDelete<a href="https://360digitmg.com/india/data-analytics-certification-training-course-in-delhi>data analytics course delhi</a>
Great post, thanks for sharing
ReplyDeleteData Science Online Training
Excellent article for the people who need information about this course.
ReplyDeleteLearn Data Science Online
This comment has been removed by the author.
ReplyDeleteI 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.
ReplyDeleteComplete Python Training Course - No Coding Experience Required
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.
ReplyDeleteBest Consultant for Experience Certificate Providers in Bangalore, India
Excellent article for the people who need information about this course.
ReplyDeleteBest Company for Experience Certificate Providers in Chennai, India
This comment has been removed by the author.
ReplyDeleteExcellent and very cool idea and great content of different kinds of the valuable information’s.
ReplyDeleteGenuine Fake Experience Certificate Providers in Hyderabad, India
Very Nice Blog I like the way you explained these things. data science training delhi
ReplyDeleteNice blog, Thanks for sharing this post with us. Keep sharing some more blogs again soon.
ReplyDeleteData Science Course
Artificial Intelligence Course
ReplyDeleteWow 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.
This post is so helfull and informative.keep updating with more information...
ReplyDeleteData Science Course In Mumbai
Data Science Course In Ahmedabad
Data Science Course In Kochi
Data Science Course In Trivandrum
Data Science Course In Kolkata
This comment has been removed by the author.
ReplyDeleteWant 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.
ReplyDeleteExperience Certificate Provider in Chennai- The Career of Your Life
Experience Certificate Provider in Bangalore- Once Driven, Forever Career
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
ReplyDeletehi
ReplyDeleteExcellent 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
ReplyDeleteData Science Training In Noida
ReplyDeleteThanks for the information about Blogspot very informative for everyone
ReplyDeletedata science course in chennai
This comment has been removed by the author.
ReplyDeleteThanks for sharing the valuable information here. Keep sharing more informative articles. Regards by technokryon
ReplyDeletehire python developer india
best data science companies
professional cloud devops engineer
It is very useful for me. Thanks...
ReplyDeleteAzure Databricks Online Training
Azure Databricks Online Training
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.
ReplyDeleteWow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.
ReplyDeletePython with Data Science Training Course in Delhi, NCR
AutoDesk Training Course with Professional Way
Tally ERP.9 With Prime Tally Training Institute in Delhi
E-Accounting Training Course with Placement Support
I just found this blog and have high hopes for it to continue. I have added to my favorites. python course
ReplyDeleteVery nice blog keep sharing such amazing post. For Best Expert Training under industry expert trainers for best data science certification online Call Now 7070905090
ReplyDeleteData Science Course in Gurgaon
ReplyDeleteData 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.
ReplyDeleteCaching & Data Streaming Platform (Genex data base)
ReplyDeleteCaching 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.
Data Science Course in Noida
ReplyDeleteThis is very nice article for us. Please check here.
ReplyDeleteThank you for an excellent article.
ReplyDeleteData science Training
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.
ReplyDeleteThank 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.
ReplyDeletevisit: Environmental Data Analytics for Sustainability: A Pathway to a Greener Future
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