I don't know the UI library you mentioned, but I've used a pattern like this for similar tasks:
def make_ui_thing(from: bs4.Tag, into: ???):
new_ui_thing = ???
for child_tag in from.find_all(True, recursive=False):
new_ui_thing.add(make_ui_thing(from=child_tag, into=new_ui_thing))
where a function creates some "thing" for a tag, then calls itself recursively to create and insert the children "things" into that "thing".
- Chris