Dias’s Newsletter (Substack), published 2023-05-04
Architecture
ParallaxAI makes personalised avatars in Kazakh traditional style: the MVP takes a user's photos and payment, trains a model, generates avatars and emails a link. The frontend uploads photos to S3 from the browser and asks the backend for a job, which is stored in a database. A cron calls a job processor endpoint once a minute to advance each job, using Replicate's API for training and generation. It runs on Vercel with Next.js.
Section: MVP Architecture | Section: Development Stack | Section: Why it worked this time?
Components
Component
Role
Where
Web Frontend
Stores the user's photos in S3 directly from the browser and sends the backend a request for a new job.
Near: Web Frontend stores photos to S3 directly
Backend
Stores the incoming job in the database.
Near: Backend stores job in DB
Cron
Calls a job processor endpoint once a minute, which moves a job to its next state: requesting model creation, polling for it, requesting avatar generation, polling for it, and emailing the photos.
Near: Cron calls a job processor endpoint once
Figures, as the source states them
Figure
As stated
Note
Where
Cost to train one model with LoRA on Replicate
1 US dollars
Less than; per model
Near: costs less than 1$ to train a model
Time to train one model with LoRA on Replicate
8 minutes
Less than
Near: for less than 8 minutes of time
Cost to train one model with DreamBooth on Replicate
2.5 US dollars
Per model; the option not used
Near: it costed 2.5$ to train one model
Time to train one model with DreamBooth on Replicate
20 minutes
More than; depending on the training set; the option not used
Drive a multi-step ML job with a stored job state and a once-a-minute cron that polls the provider
parallaxai-2023-avatar-generator#d1at corpus version 26a1b3a7e3dd
Chosen
A job is stored in the database and a cron calls a job processor endpoint once a minute to move it to the next state. The states are PENDING, MODEL_CREATING, MODEL_CREATED, INFERENCING, INFERENCING_COMPLETED and FINISHED: the processor asks Replicate to create a model, polls until it is done, asks for the avatars, polls again, then emails the photos to the user. The author describes it as one web form on the frontend and one cron with two API calls on the backend.
Fine-tune Stable Diffusion per user with LoRA through Replicate's API
parallaxai-2023-avatar-generator#d2at corpus version 26a1b3a7e3dd
Chosen
Avatars come from Stable Diffusion fine-tuned on each user's photos with the LoRA training method, run through Replicate's API. With LoRA on Replicate the author reports that training a model costs less than 1$ and takes less than 8 minutes.
Near: clear I need to use Stable Diffusion | Near: Replicate announced it added Lora as an API
Rejected
Midjourney. The author rated its quality as exceptional but noted it had no API and no fine-tuning, came from a small team and was unlikely to be open sourced.
Near: Midjourney - exceptional quality, no API
DreamBooth fine-tuning through Replicate's API. It worked well, but training one model cost 2.5$ and took more than 20 minutes, depending on the training set.
Near: it costed 2.5$ to train one model
Reasoning
None of the image generators the author tried recognised Kazakh national apparel and style, so the product needed fine-tuning on a user's face and that style. Stable Diffusion was lower in quality than Midjourney but open source from the start, with open weights and third-party API providers. A tweet said LoRA halved the compute needed for fine-tuning compared with DreamBooth.
Near: none of them recognized Kazakh national apparel | Near: Stable Diffusion - lower quality compared to Midjourney | Near: decreased computational resources needed for fine-tuning two times
Host on Vercel and deploy to production on every push to main
parallaxai-2023-avatar-generator#d3at corpus version 26a1b3a7e3dd
Chosen
The project is a Next.js app on Vercel, which creates a production deployment on every merge to the main branch on GitHub. The author worked only on main, with a Makefile target that adds, commits with a fixed message and pushes, and made 5-10 production deployments a day.
Section: Development Stack
Reasoning
The project setup was simple and the author did not want to spend time managing deployments for an MVP. He adds that the commit-straight-to-main habit would not suit large projects with mission-critical flows, but that at the time he had, as he puts it, 1.5 customers, so breaking things was acceptable.
Near: to avoid wasting time on deployment management | Near: at a time a had 1.5 customers
Outcome
The author reports setting up a boilerplate project in less than 10 minutes and then spending 99% of his time on the app's business logic, with Vercel handling deployments, monitoring and basic analytics.