Exstracting frame from video and sen it to GCS bucket

Hi,

I try to extract frames from an uploaded video (frame by frame), then I want to save the frames in google cloud storage, actually, I couldn’t manage this process.

This is what I have done:

import streamlit as st
import cv2 as cv
import tempfile
import cv2
import os
from skimage import io
from skimage.metrics import structural_similarity as compare_ssim
from PIL import Image
import numpy as np
from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.models import Model
from google.oauth2 import service_account
from google.cloud import storage

credentials = service_account.Credentials.from_service_account_info(
    st.secrets["XXX"]
)
client = storage.Client(credentials=credentials)

bucket_name = "XXXX"

upload_file=st.file_uploader("Choose a video file", type="mp4")


if upload_file is not None:
    st.video(upload_file)

    tfile = tempfile.NamedTemporaryFile(delete=False) 
    tfile.write(upload_file.read())

    vf = cv.VideoCapture(tfile.name)

    stframe = st.empty()
    sec = 0
    count=0
    while vf.isOpened():
        vf.set(cv2.CAP_PROP_POS_MSEC, sec*1000)
        ret, frame = vf.read()
        sec = sec + ret
        sec = round(sec, 2)
      
        # if frame is read correctly ret is True
        if not ret:
            print("Can't receive frame (stream end?). Exiting ...")
            break
        else:
            blob = bucket_name.blob('ImageTest/Example1.jpg')
            #here iwant to upload te images

Any suggestion? thank you.