Just debugged random things! If I use the tflite prediction without any external function directly then it works fine.
def generate_frames(frame):
    image = cv2.resize(frame,(256,256))

    #converting into float32
    image = tf.image.convert_image_dtype((image/255.0), dtype=tf.float32).numpy()
    
    #prediction
    -----------------
    interpreter = tf.lite.Interpreter(model_path="quant_model.tflite")
    interpreter.allocate_tensors()
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()

    interpreter.set_tensor(input_details[0]['index'], np.expand_dims(image[:,:,:3], axis=0))
    interpreter.invoke()
    image = interpreter.get_tensor(output_details[0]['index'])[0]
    -----------------
    
    final_result = (image*255).astype(np.uint8)
        
    ret,buffer=cv2.imencode('.jpg',final_result)

    frame=buffer.tobytes()

    return frame

isn’t it too memory-consuming and a bad way to use a model prediction?