AI Deploy - Tutorial - Create an application to play rock paper scissors with YoloV8
Objective
The purpose of this tutorial is to explain how to deploy an application to play the game "rock paper scissors" using the YOLOv8 model.
In order to do this, you will use Streamlit, a Python framework that turns scripts into a shareable web application. You will also learn how to build and use a custom Docker image for a Streamlit application.
Requirements
- You have created an AI Deploy project inside a Public Cloud project.
- You have created a user for AI Deploy.
- You have Docker installed on your machine.
- You have knowledge about building images with Dockerfile.
- You have weights obtained from training the YOLOv8 model on the Rock Paper Scissors Dataset. You can use the tutorial Train YOLOv8 to play rock paper scissors to generate these weights.
Instructions
You are going to follow different steps to build your Streamlit application.
- More information about Streamlit capabilities can be found here.
- All source files can be found on GitHub.
Write the Streamlit application
Create a Python file named app.py and paste the following code:
Write the requirements.txt file for the application
The requirements.txt file will allow us to write all the modules needed to make our application work. This file will be useful when writing the Dockerfile.
Write the Dockerfile for the application
Your Dockerfile should start with the FROM instruction indicating the parent image to use. In our case we choose to start from a python:3.8 image:
Build the Docker image from the Dockerfile
Launch one of the following commands from the Dockerfile directory to build your application image:
-
The first command builds the image using your system’s default architecture. This may work if your machine already uses the
linux/amd64architecture, which is required to run containers with our AI products. However, on systems with a different architecture (e.g.ARM64onApple Silicon), the resulting image will not be compatible and cannot be deployed. -
The second command explicitly targets the
linux/AMD64architecture to ensure compatibility with our AI services. This requiresbuildx, which is not installed by default. If you haven’t usedbuildxbefore, you can install it by running:docker buildx install
Push the image into the shared registry
Warning The shared registry of AI Deploy should only be used for testing purpose. Please consider attaching your own Docker registry. More information about this can be found here. The images pushed to this registry are for AI Tools workloads only, and will not be accessible for external uses.
Find the address of your shared registry by launching this command:
Log in to the shared registry with your usual AI Platform user credentials:
Push the compiled image into the shared registry:
Launch the AI Deploy app
The following command starts a new app running your Streamlit application:
Notes
-
--default-http-port 8501indicates that the port to reach on the app URL is8501. -
--cpu 1indicates that we request only one CPU for that app. -
Consider adding the
--unsecure-httpattribute if you want your application to be reachable without any authentication.
Go further
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.
Feedback
Please send us your questions, feedback and suggestions to improve the service:
- On the OVHcloud Discord server