portfolioprojectstxt2img

Multimodal Text-to-Image Pipeline

Background isolation and automated dynamic banner generation using in-memory processing.

CompanyDotkonnekt
TimelineNov 2025 — Mar 2026
Focus AreaGenerative Media & Pipelines
PythonrembgGoogle GenAIAWS S3Langfuse
Overview

At Dotkonnekt, we built an automated graphic banner generation system for campaign promotion. The main goal was to allow merchants to provide a subject image and a prompt, automatically isolating the subject from its original background, and then dynamically embedding it on a formatted canvas surrounded by a high-quality AI-generated setting.

I designed and built the complete backend pipeline in Python. When a client submits a multipart request containing the raw image and prompt, a controller parses and validates the input. The orchestrator calls Langfuse to retrieve the optimized model configuration and prompt template, ensuring dynamic tuning without redeploying code.

The core processing occurs in an in-memory image pipeline (BytesIO): the subject background is stripped using the rembg library, placed onto a 16:9 2048px blank canvas using dynamic scaling algorithms, and passed to a Google GenAI model (e.g. Imagen) to generate the surrounding background. The output is stored on AWS S3 and its key is returned to the client.

Architecture

End-to-end data flow through the pipeline.

Multimodal Text-to-Image Pipeline Architecture
Implementation Walkthrough
PHASE 01

Request Parsing and Validation

The controller authenticates the client, parses the multipart/form-data payload containing the subject image and the text prompt, and prepares the image bytes for processing in memory using BytesIO.

PHASE 02

Dynamic Config via Langfuse

To avoid baking model configs and prompts in code, the orchestrator pulls live prompt template configurations and model hyperparameters directly from Langfuse at runtime.

PHASE 03

Background Removal & Canvas Placement

The pipeline uses the rembg library to isolate the subject from the input image. It then initializes a 16:9 canvas (2048px width) and places the isolated subject onto it, dynamically scaling and centering the subject to leave natural margins.

PHASE 04

Inpainting with Google GenAI

The composite canvas along with the text prompt is passed to Google's GenAI model. The model runs inpainting/outpainting to fill the blank areas of the canvas, blending the subject seamlessly into the newly generated background.

PHASE 05

AWS S3 Storage

The generated high-resolution banner image is saved to AWS S3 using a tenancy-structured folder structure (`env/tenant/dir/gen_uuid.png`), and the S3 key is returned to the client.

Tech Stack Deep-Dive

Why each tool was chosen.

rembg

Background isolation

A lightweight, Python-based U2Net library that runs locally to isolate subjects from original image backgrounds efficiently.

Google GenAI (Imagen)

Outpainting & banner generation

Provides state-of-the-art outpainting capabilities, accurately blending the custom canvas structure with high-resolution generated background scenes.

Langfuse

Prompt and model configuration management

Enables instant tweaking of the base generation prompt and model hyper-parameters without code redeploys, keeping operations highly agile.

AWS S3

Asset storage

Secure, durable, and highly available storage for the final generated image banners, keeping filenames clean with unique UUID structures.

Back to portfoliosivakumar.dev