Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7505

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T04:28:07+00:00 2024-11-28T04:28:07+00:00

Building a Drowsiness Detection Web App from scratch – pt3

  • 60k

In the final leg of this Tutorial, we start to build a webpage using Streamlit that can perform three things:

  1. Give some description of the Application
  2. Take an image input
  3. Provide predictions/output on #2

Streamlit is an open-source app framework for Machine Learning and Data Science teams. It is a Python-based library specifically designed for machine learning engineers that does this well and given all the resources from our previous work, we can set to build this service – all in python.

Create a Simple Description of our service

Here we will interact with the markdown functions of Streamlit library, first, create an app.py script in your local directory and paste the following.

## Import the Neccessary Libraries ### Don't forget to update your --requirements.txt file import streamlit as st from PIL import Image import numpy as np import torch import io import os  ## Put some description of the service st.title("DROWSINESS DETECTION") st.subheader("An implementation of Machine Learning to determine when user might be feeling a little drowsy.") st.markdown("---") 
Enter fullscreen mode Exit fullscreen mode

Next, in the same script we load our saved model – and yes! it has to be your folder directory. The following loads the trainned model as well as the torch hub that holds the YOLOv5 pre-trained model, then we evaluate with model.eval().

## Load Model #e.g run_model_path = './last_drowsy_v4.pt' run_model_path = './model_name.pt' model = torch.hub.load('ultralytics/yolov5', 'custom', path=run_model_path) model.eval() 
Enter fullscreen mode Exit fullscreen mode

Great!, next, we create a function that takes our model and the input image to output the prediction as a bounding box, below is how the predict_img

def predict_img(img):     ## Flatten out the image     image = np.array(Image.open(img))      ## predict     result = model(image)      ## Output     output = io.BytesIO()     out_image = np.squeeze(result.render())     output_img = Image.fromarray(out_image)     output_img.save(output, format='JPEG')     result_img = output.getvalue()      return st.image(result_img) 
Enter fullscreen mode Exit fullscreen mode

Take an image input & Provide predictions/output

Phew, now, let's handle the dial for handling image uploads using the file_uploader on the sidebar of our app:

img_file_buffer = st.sidebar.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])     if img_file_buffer is not None:         UPLOADED_IMAGE = img_file_buffer         predict_img(UPLOADED_IMAGE) 
Enter fullscreen mode Exit fullscreen mode

Notice how we declared the various image formats our app can accept as well as how we handled for if there are no Uploaded files.

That-is-it! Easy right?

Navigate to your terminal and run:

streamlit run app.py

On the Top-Right corner, you should see an option to “Deploy App”, please fire away and share how it turns out. The Author did and you can find the repository and deployed application.

Drowsiness Detection

Yay! We made it to the finish line. Now take this approach and create your own web-services powered by ML.

beginnerscomputervisionstreamlitwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.