AI Deploy - Tutoriel - Déployer une app de classification audio grâce à Streamlit (EN)
AI Deploy is covered by OVHcloud Public Cloud Special Conditions.
Objective
The purpose of this tutorial is to deploy an application to classify sounds from a pre-trained model.
The use case is marine mammal sounds, a topic already covered in a previous tutorial.
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.
Overview of the app:

Requirements
- Access to the OVHcloud Control Panel;
- An AI Deploy project created inside a Public Cloud project in your OVHcloud account;
- A user for AI Deploy;
- Docker installed on your local computer;
- Some knowledge about building image and Dockerfile;
- You also should have followed the steps of the marine mammal sounds classification notebook from the GitHub repository. You will be able to obtain your
data.csvfile and save your model.
Instructions
You are going to follow different steps to build your Streamlit application.
- More information about Streamlit capabilities can be found here.
- Direct link to the full python file can be found here here.
Write the Streamlit application
Create a Python file named app.py.
Inside that file, import your required modules.
Create the function that allows to save the uploaded sounds in an Object Container.
Create the function that allows to transform each sound into a csv file.
Define the function that classifies the sounds from the previously trained model.
To learn more about how you can save a model with TensorFlow, please refer to the step 8 "Save the model for future inference" of the notebook.
Here you will use your trained model, then save it in an Object Container. Click here to learn more about Object Storage.
In the sidebar, if you have chosen Prediction, you will access the choice_prediction function.
It allows you to upload a sound file, convert it to a csv file and obtain the classification result by calling the functions defined previously.
All that remains is to define the main, where the sidebar and the home page are created.
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.
Here we will mainly discuss how to write the app.py code, the requirements.txt file and the Dockerfile. If you want to see the whole code, please refer to the GitHub repository.
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 the python:3.8 image:
Create the home directory and add your files to it:
Install the requirements.txt file which contains your needed Python modules using a pip install ... command:
Define your default launching command to start the application:
Give correct access rights to ovhcloud user (42420:42420):
Build the Docker image from the Dockerfile
From the directory containing your Dockerfile, run one of the following commands 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
The dot . argument indicates that your build context (place of the Dockerfile and other needed files) is the current directory.
The -t argument allows you to choose the identifier to give to your image. Usually image identifiers are composed of a name and a version tag <name>:<version>. For this example we chose streamlit_app:latest.
Test it locally (optional)
Launch the following Docker command to launch your application locally on your computer:
The -p 8501:8501 argument indicates that you want to execute a port redirection from the port 8501 of your local machine into the port 8501 of the Docker container. The port 8501 is the default port used by Streamlit applications.
Don't forget the --user=42420:42420 argument if you want to simulate the exact same behaviour that will occur on AI Deploy apps. It executes the Docker container as the specific OVHcloud user (user 42420:42420).
Once started, your application should be available on http://localhost:8501.
Push the image into the shared registry
The shared registry should only be used for testing purposes. Please consider creating and attaching your own 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 on 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:
--default-http-port 8501 indicates that the port to reach on the app URL is the 8501.
--cpu 1 indicates that we request 1 CPU for that app.
To launch your Streamlit app, you need to attach 3 volumes to your app.
The first volume contains the csv files from the transformation of the sound files. By launching the app, this Object Container contains only the data.csv file created from step 4 "Data preprocessing" of the notebook.
--volume <my_csv_files>@<region>/:/workspace/csv_files:RW is the first volume attached for storing csv files. This volume is read/write (RW) because new csv files will be created and saved each time a new sound is uploaded.
The second volume contains the sound files that you will upload directly from the Streamlit app. By running the app, this Object Container is empty. It will fill up as the sound files are uploaded.
--volume <my_audio_files>@<region>/:/workspace/audio_files:RW is the second volume attached for storing audio files. This volume is read/write (RW) attached because new audio files will be saved there.
The third container contains the model that you trained before in step 8 "Save the model for future inference" of the notebook.
--volume <my_saved_model>@<region>/:/workspace/saved_model:RO is the third volume attached for using your pretrained model. This volume is read-only (RO) because you just need to use the model and not make any changes to this Object Container.
If you want your notebook to be accessible without the need to authenticate, specify it as follows.
Consider adding the --unsecure-http attribute if you want your application to be reachable without any authentication.
Go further
- You can imagine deploying an AI model with an other tool: Gradio. Refer to this tutorial.
- Another way to create an AI Deploy app is to use Flask! Here it is.
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