There are many examples of reading in boundary conditions from file across the forum.
See for instance: Want to import already defined physical groups of Microstructure in Gmsh to FEnics - #23 by dokken
Defining subdomains for different materials — FEniCSx tutorial
1 Like