Assigning different physical groups to different color in gmsh and mark them as different material in fenics

Oh that was my bad. I had not read the previous answers. As @dokken mentioned in a previous reply, since you don’t have any facet regions with a physical tag:

mvc = MeshValueCollection("size_t", mesh, 1) 
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "line")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

This part of the code would not be required as it is basically reading the tagged boundaries into the object mf using the MeshValueCollection and MeshFunction functions.
Please remove these lines and try again.