✨ Yesterday, I made a tweet that converted all the replies into images, using Stable Diffusion.
It blew up, with +2k people coming together to generate all kinds of art, memes, and play around with ML.
Here's how I built it, how much it cost me, and how you can try it out! 👇
I'm a big fan of @midjourney's (another AI image tool) approach to launching:
They made a Discord, where everyone can generate images in public. If you see someone making something cool, you can see their prompt, tweak it, and put your own spin into it.
It makes AI multiplayer!
Stable Diffusion is revolutionary, because it's fully open-source, and built to be run on people's computers.
You can generate amazing images in your pc/mac, in seconds, even without an internet connection! 🤯
But I really felt like it was missing that "multiplayer" experience.
🧑💻 I started by writing a script that'd poll the tweet for replies every minute.
Twitter only returns the latest 100 replies, so I decided to persist them to a db, along with the prompt.
When a new record got added to the db, it dispatched a new job to generate the image. 🖼
To generate the prompts, I used @replicatehq, a service that allows you to run open-source models on the cloud. ☁️
It allowed me to run SD with an API request, and have them hit me back once the model had finished (or failed).
It's also insanely cheap, but more on that later 👀
Once I got the response, I'd save the image URL and dispatch another job to reply.
The job was in charge of two things: uploading the image to Twitter, and creating the reply. 🚀
Making it a job made it really easy to retry it something went wrong instead of just erroring out.
Initially, everything was working smoothly, but then things started to fail.
It turns out, Twitter has pretty strict rate-limits, with the endpoint you use to upload images clocking out at 429 images per hour (this is nowhere in the docs!) 🥲
Thankfully, using a job queue for this made the fix really easy.
If any jobs hit the rate limit, I just released them back into the queue automatically.
This meant a hard limit on how many images can be generated every hour, but it'd auto-retry the rest on the next hour. 🔄
With all this in place, I wrote a short thread explaining how things worked (no NSFW, need to follow me for it to work, etc.), and people started playing around with it!
If you haven't had the chance to play with AI-generated images yet, I'd highly recommend to try it out! 👇
twitter.com/m1guelpf/status/1569487042345861121?s=20&t=WLnu3xNuoxYPaNfAGddFeA
📊 So, how did it go?
At the time of writing, it has generated 2120 images, including deleted replies (see queue pic below).
At ~$0.012 per image on Replicate, that's a cost of $22.53 for probably my most engaged-with tweet ever (and a really cool experiment). 🤩
I definitely want to do more of these experiments in the future (there's a SD fork fine-tuned for anime bet I really wanna play with 👀).
So that's something you'd like to see, drop a follow to make sure you don't miss it!
(> '')> @m1guelpf <(''<)