I went way down the rabbit hole on this one and ended up with a proof of concept that's probably close enough to be able to wire it up: https://gitlab.com/-/snippets/3745244
I guess it didn't end up too much code, but I'm not entirely sure it's worth it.
(it's after 3 AM? oh no what have I done)
Stable LM looks like it's actually CC-BY-SA, which I think would meet the Open Source Definition.
But none of the Stable Diffusion or Stable Audio models are released under such a license.