Building an AI Image Generation App with Flux in Bubble
In an earlier video, we demonstrated how you can build an AI image generation app using Flux in Bubble, and we explained how you can use a webhook to inform your app when an API has completed the process you've requested it to do. This is particularly useful if you are doing something with an API that will take an indefinable amount of time or a long amount of time. Because rather than just your Bubble app waiting for the steps to complete, in which case it may timeout, it's simply saying when you're ready, when you've completed generating the image, send a notification with some id details so I know which image it is to this backend workflow. And so we're saying use this as a webhook. And then if I go into the backend workflows, I have changed this app slightly.
Saving Images to the Database
This is just my demo app, but it would be this workflow here that I would then go ahead and save the image to the database. Go and check out our original Flux video on how to do that. But we've had a comment that points out something that I'll admit I overlooked, which is you need to make the webhook dynamic because this webhook is specific to the version test.
Making Webhooks Dynamic
So what do we do? Well, we can simply take it like this. I'm going to copy that to my clipboard, I'm going to add in some dynamic values, I'll say Webhook and then it's not private. And then I'll go to my page where the user generates their image, go to my workflow, and now I can dynamically fill the webhook in here. So we want to make this as dynamic as possible.
Using Dynamic Data for Webhooks
I would consider doing it like this. I'm just going to drag some text onto the page to give an example, which is we can say app or that's home homepage URL. And so we can use this dynamic data. And if I click preview, we get the specific app homepage for this version. And also note that this is using the primary domain, the domain that is set, or rather isn't set because this is the temporary domain the app lives on.
Ensuring Webhook Flexibility
And so we want to make it as dynamic as possible because when you update the domain or even move domains, we don't want you to have to. It's just something that's going to go wrong if you have to go back and rewrite the webhook address. So we know that we can say this app's homepage will print this. Notice it ends in a slash so we can use that to form part of our dynamic data here.
Constructing the Dynamic Webhook URL
So we can say this app's homepage. And then I'm going to paste in the full webhook and just cut out the bits that I no longer need. That's just a little bit fiddly in here. Maybe I should have used arbitrary text. But look, there we go. So we know it ends in a slash. So I can take it all the way back. This is there we go back to there.
Finalizing the Dynamic Webhook
So this is now going to print the homepage slash version test. No, no. In fact we take, of course, of course we take out version test. So you want it to be the homepage slash API 1.1 workflows image webhook. So this is similar. If you have seen our videos on AssemblyAI, this is exactly the same process. In fact, I think we include this step in our AssemblyAI videos for speech to text transcription. But here you go.
Conclusion and Next Steps
This is kind of catching up. It's an add on for our video about Flask. And if you're watching this video, it's probably because you've got an idea and you wanted to build it with no code. Build it in Bubble, click the link down in the description to get access to our community. And we've got tons of resources for people just like you.