from @levelsio | by @levelsio



over 1 year ago

ā€¢View on Twitter

Here's how I built from scratch in 5 days:

It's all handwritten vanilla HTML, with vanilla CSS (in the same page), vanilla JS with jQuery, it sends jQuery ajax() requests to the server which runs PHP to upload your photo, and then PHP talks to Python to generate the pics with Stable Diffusion!

The difficulty for me was here: - it takes anywhere from 3 to 30 seconds to generate an image (mostly depending on SD step count) - client clicks [ GENERATE ], it sends ajax(), server then needs to start generating the pic, and send it back

- this WOULD keep a PHP process running for those 3 to 30 seconds, which worked if it was just me, but if it was 100-300 people on the site (like yday) at 120 generated per minute, it'd break quickly So...

As I like to do things manually, I built my own mini queue system: 1) when client clicks [ generate ], server puts the job in db (SQLite) 2) a PHP script that runs constantly (I call it a worker) checks the db for new jobs, takes one, sets it as processing, and starts gen img

3) I set 10-20 of the same PHP worker script to run in parallel, it's just a while(1) loop and loops forever, until the script is changed or after 24h to reset 4) a cron starts it every 1 minute, if it's already running it doesn't start

5) meanwhile the client polls server for result (is the image done yet?), it does this by opening a JSON file with the image id, this is because if it'd hit PHP every time it'd be heavy, just hitting static JSON file only hits NGINX which is fine

6) the JSON file has the images generated, in this case only 1, but before I'd gen 4, anyway the JSON file not 404'ing means the image is ready and the JS then loads the image

This queue system was fastest for me to build instead of learning new stuff with WebSockets and parallel stuff which long term I can/will switch to IF the product idea is validated and makes money!

The other challenge was getting the interiors to look well, Stable Diffusion has lots of parameters to tweak like cfg_scale, steps count, image strength, actually funnily enough I learnt LESS steps not more is better for me and also cheaper

Some things I am working on next: - improving that AI doesn't change the walls of the room - adding object detection and product links (not sure if I can but try) - adding an eraser tool so you can brush out stuff you don't like from your room or the render and re-generate

I got lots of inspiration in the design esp from by @dannypostmaa and by @Suhail and from (esp the image boxes for styles) and @faceapp_ai with the face styles in the bottom!

Thanks @stabilityai and @EMostaque for building Stable Diffusion and helping me find init_image in the API

Oh and forgot I had to buy the domain too which wasn't cheap for $2899

And forgot next step is of course: - add Stripe Checkout and sell Pro memberships

It was quite an intense 5 days, I skipped gym the last 3 days, was coding like crazy, but went again today, really fun to dive in to new project though <3

More from @levelsioReply on Twitter

Page created with TweetHunter

Write your own