Skip to main content

The Streamlit Advantage: Sales Predictions on the Web

 

                                                                                                Image by pikisuperstar on Freepik

Introduction

In the ever-evolving world of data science and technology, the task of translating data insights into interactive and accessible web applications has historically been a daunting challenge. Even with the most potent machine learning models and insightful data visualizations at your disposal, bridging the gap between technical know-how of programming languages and user-friendly web applications often demanded a steep learning curve in web development. 

However, a groundbreaking solution has surfaced, ready to reshape the entire landscape of data science and web application development. The era of viewing these fields as intricate enigmas demanding extensive study, thick textbooks, and years of practice is gradually waning and passing
 

Meet Streamlit, an innovative open-source Python framework poised to transform the very essence of data-driven web application development. Hence whether you're a seasoned data scientist or someone just setting out on this journey, Streamlit offers a compelling promise: to empower you to effortlessly create captivating and interactive web applications using the Python programming language that you already know and love.


In this article, we delved into the fascinating domain of Streamlit, the web UI tool of choice for showcasing our Sales regression prediction model, which you can find here. With Streamlit, we transformed our once dry, boring and plain code into an engaging and visually captivating web application. Our aim is to provide dynamic machine learning model predictions, all within the confines of a user-friendly and interactive platform.Hope you would stay long enough to see how this magic came to be.

What is Streamlit?

Streamlit , at its core, is an open-source Python library and framework that is designed for rapidly creating web applications and interactive data dashboards with minimal effort. It allows data scientists, developers, and other professionals to transform their data scripts or machine learning models into web applications quickly and easily, using Python code.

Streamlit simplifies the process of developing web apps by eliminating the need for extensive knowledge of web development technologies like HTML, CSS, or JavaScript. With Streamlit, you can build web apps using familiar Python scripting and a set of simple commands. It also provides various pre-built widgets and components for creating interactive elements such as buttons, sliders, and plots, making it user-friendly and accessible to a wide range of users.

Key features of Streamlit include its ability to integrate seamlessly with data visualization libraries like Matplotlib, Plotly, and Altair, making it a powerful tool for data-driven applications. It also supports real-time updates, so you can easily see changes as you edit your code.

Streamlit has gained popularity in the data science and machine learning communities due to its simplicity and efficiency, enabling practitioners to share and showcase their work with stakeholders or a broader audience through web interfaces.

Key Features of our Streamlit app

1. Imports

The application commences by importing a series of essential Python libraries and modules. These imports encompass Streamlit, Pandas, Pickle, Pillow for image processing, and OpenCV for image manipulation and conversion.


  • 2. Load Pickle File 

  • A custom function, load_pickle, is introduced to load a previously saved pickle file (streamlit_Basics.pkl). This file contains crucial components and models that will be instrumental in the application's operation.

  • 3. Access Saved Components 

  • The code efficiently calls the `load_pickle` function to retrieve the components stored within the pickle file. Notable among these components are a scaler and a predictive model, which will be pivotal in making accurate sales predictions.

  • 4. Setting Page Configuration

  • The application's user interface and behavior are configured using the `st.set_page_config` function. This function allows for customization of the page title, layout, and menu items, thus shaping the overall appearance and functionality of the Streamlit app.

  • 5. Styling with HTML and CSS

  • To further enhance the application's aesthetics and user experience, we employed the use of an HTML `<style>` block, which embeds custom CSS styles. This CSS code helps personalize the appearance of the app and sidebar, contributing to a unique and visually appealing design.

  • 6. Sidebar

  • The application incorporates a sidebar on the left, crafted using `st.sidebar`. This sidebar acts as a navigational hub, offering users convenient access to different sections of the app, including "Home," "Predict," "Explore," and "About."

  • 7.Page Selection 

  • The code implements `st.sidebar.radio` to facilitate user interaction and page selection. Users can effortlessly choose from a variety of pages, such as "Home," "Predict," "Explore," and "About," based on their interests and intentions.

  • 8. Home Page

  • The `home` function defines the appearance and content of the "Home" page within the application. This section welcomes users with a captivating image, a compelling title, and a concise description of the app's purpose and features.

  • 9. Predict Page 

  • For sales prediction, the `predict_sales` function assumes center stage. In this section, users are presented with a form that allows them to input various factors affecting sales. Upon clicking the "Predict" button, the application promptly calculates and presents the predicted sales figure.

  • 10. Explore Page

  • The "Explore" page, masterminded by the `explore_data` function, provides users with the opportunity to delve into the application's dataset. Users can view the data, gaining valuable insights into the information that underpins the app's predictions.

  • 11. About Page 

  • Under the "About" section, the `about_info` function shares essential information about the application, the project's context, and its purpose. Additionally, it includes a hyperlink that directs users to the project's GitHub repository here, offering further details and resources.

  • 12. Main Function

  • Serving as the application's central entry point, the `main` function orchestrates the seamless operation of the Streamlit app. It effectively directs users to their chosen section based on their page selection. In summary, the Streamlit application we created artfully combines an array of elements, encompassing widgets, data visualization utilities, navigational features, and personalized design. This harmonious blend yields an instinctive, user-focused web application tailored for sales prediction and data exploration.

Advantages of Streamlit:

  • Rapid Development: Streamlit allows you to quickly turn your Python scripts into interactive web applications with minimal code, reducing development time and complexity.
  • Python-Centric: You can build web apps entirely using Python, without the need for additional languages like HTML, CSS, or JavaScript. This makes it accessible to Python developers and data scientists.
  • Pre-Built Widgets: Streamlit provides a set of built-in widgets (e.g., buttons, sliders, text inputs) that simplify the creation of interactive elements in your app.
  • Data Visualization: Streamlit seamlessly integrates with popular data visualization libraries like Matplotlib, Plotly, and Altair, enabling you to embed charts and plots into your apps.
  • Real-Time Updates: Your app updates in real-time as you modify your code, allowing you to instantly see the effects of changes.
  • Easy Deployment: Streamlit apps can be deployed on various hosting platforms, making it simple to share your work with others.
  • Custom Styling: While Streamlit is designed for simplicity, it also offers options for customizing the styling of your app using CSS.
  • Sharing and Collaboration: You can easily share Streamlit apps with colleagues, clients, or a broader audience by sharing the app's URL or deploying it to the web.
  • Interactivity: Streamlit apps support user interaction, enabling dynamic content and user input handling for data exploration and analysis
  • Integration with Machine Learning: Streamlit is commonly used for showcasing machine learning model demos, providing a user-friendly interface for predictions and analysis.
  • Wide Community Support: Streamlit has a growing and active community that contributes to its development, offers support, and shares examples and resources.
  • Open Source: Streamlit is open-source, which means it's free to use, and you can contribute to its development or extend its functionality.

Conclusion

For further information about our project and to access the code and any updates related to our Streamlit application, you can visit our GitHub repository at the following link (GitHub link).This repository contains all the details, code, and any enhancements we've made throughout the project, providing a comprehensive resource for those interested in exploring our streamlit application and its functionality. Thank you.


Reference





















Comments

Popular posts from this blog

Deciphering Ecuadorian Retail Trends: A Time Series Forecasting Approach to Sales Prediction

Diving into Sentiments: Building, Fine-Tuning, and Deploying a COVID-19 Vaccine Tweet Classifier with Hugging Face and User Interface Tools.

 INTRODUCTION Greetings once again!  Today, I am thrilled to share with you an exciting project that has surpassed all my expectations– but hey, I say that every time, right? Throughout my time with Azubi, I have worked on various projects, each one seemingly better than the last. However, this particular project stands out as, introduced me to unstructured datasets, deep learning (specifically natural language processing), and the concept of transfer learning through fine-tuning a model. So, what sets this particular project apart, you might wonder? In our initial four projects, we delved into structured datasets and explored fundamental machine learning algorithms. However, what makes this endeavor truly extraordinary is its jump into unstructured datasets, deep learning (specifically, natural language processing), and the intricate realm of transfer learning – fine-tuning a model for specialized training on unique data. In this project, we had the opportunity to utilize the datas