Building an E-Commerce Style Transfer Tool with Large Models: From Requirements to Production
This article presents the design and implementation of an AI-powered e-commerce image generation tool. It explains how to preserve product consistency while applying the visual style of a reference image, and covers prompt structuring, asynchronous task processing, state management, image preprocessing, history tracking, and human review.
1. Project Background: A Real E-Commerce Challenge
This project began with a common need from an e-commerce professional. The products themselves were high quality, but they lacked strong brand recognition and premium positioning. Compared with products from established brands, their product detail pages had weaker visual presentation, and conversion rates remained low.
The traditional solution was to hire professional designers to create visual assets. However, this approach was expensive and time-consuming. It also became difficult to keep up when new SKUs were added frequently.
The requirement can be abstracted as a typical image generation task:
Given a reference image that represents the visual style of a premium brand and a product photo, generate a marketing image that preserves the product’s appearance while aligning the overall visual style with the reference.
This type of application involves three core technical challenges:
- Product consistency: The generated product must preserve the original shape, color, and details. Otherwise, it becomes misleading and may result in customer complaints.
- Controllable style transfer: The generated image should match the reference image’s visual direction without copying it so closely that it creates potential copyright or imitation concerns.
- Production readiness: The system cannot remain a simple demo. It needs user accounts, history management, and batch-processing capabilities to support daily use by e-commerce operators.
2. Overall Technical Design
The system uses a separated frontend and backend architecture. Image generation is provided through a cloud-based large model image generation API, while business logic and user data are managed by the application itself.
2.1 End-to-End Workflow
User uploads a reference image, product image, and description│▼Frontend validation and preprocessing (format, dimensions, compression)│▼Backend task queue ──► Call the image generation model API│ │▼ ▼Persist task status Write generated output to object storage│▼Frontend polls or uses WebSocket to retrieve and display the result
2.2 Key Design Considerations
Structured Prompt Construction
The core of controllable style transfer lies in the structure of the prompt. In practice, the prompt was divided into four sections and assembled programmatically instead of being hard-coded:
def build_prompt(style_desc, product_desc, constraints):return f"""Use the first image as a style reference for composition, lighting, and background atmosphere.Place the product from the second image into that scene.The product must remain unchanged: {product_desc}Style requirements: {style_desc}Do not change the product shape, add text or watermarks, or invent product details.{constraints}"""
The prohibition section is especially important. During early testing, the model often embellished the product by inventing a logo or changing the curvature of a bottle. These negative constraints must be stated explicitly to reduce product-consistency failures.
Product Consistency Safeguards
Prompts alone cannot guarantee perfect consistency. Therefore, the backend adds a manual review step. Each generated result first enters a Pending Review state. The user can preview it and either regenerate the image or approve it.
The interface also preserves a side-by-side comparison between the original product image and the generated image, reducing the risk of using an inaccurate result.
3. Developing a Long-Running AI Engineering Task
The development process itself served as a practical test of AI-assisted long-running programming. A long-running task is not a small requirement that can be completed in a single prompt. It is a complex engineering effort that spans multiple steps and modules and may involve dependency conflicts, API errors, logic defects, and other unexpected issues. The system must be planned, implemented, tested, and corrected over an extended period.
3.1 Task Decomposition
The project was divided into six independently verifiable milestones:
- User registration and login, including session management;
- Image upload and object storage integration;
- Image generation API integration with retry handling;
- History management and task state transitions;
- A three-step frontend workflow: upload the reference image, upload the product image and description, then generate with one click;
- End-to-end integration testing and coverage of exceptional scenarios.
Each milestone was validated end to end as soon as it was completed, rather than waiting until the entire system had been built. This is particularly important for long-running tasks. The longer an error remains undetected, the more expensive it becomes to fix as the codebase grows.
3.2 Task State Machine
Task status is one of the most overlooked yet important parts of the system:
PENDING → GENERATING → GENERATED → CONFIRMED / FAILED
The image generation API may time out, apply rate limits, or return invalid content. Each situation requires an appropriate retry and fallback strategy.
For example, rate-limit errors can trigger exponential backoff. If the task fails three consecutive times, it is moved to FAILED and the user is notified. This prevents tasks from remaining stuck in an intermediate state.
4. Lessons from Implementation and Optimization
Image Preprocessing Is Essential
User-uploaded product photos vary widely. Excessive dimensions and cluttered backgrounds can significantly affect generation quality. The upload process therefore includes standardized compression and dimension normalization.
For product images, the interface also provides a simple way for users to identify the main product area, such as by guiding them to select the product subject. This noticeably improves consistency in the generated result.
Asynchronous Processing Is Required
Image generation commonly takes several tens of seconds. A synchronous request can easily time out. The backend therefore uses a task queue and status polling, while the frontend displays progress feedback. This creates an experience closer to that of established AI generation products.
History Management Drives Retention
E-commerce users often process multiple SKUs in batches. History management allows them to filter results by time and reuse a previous prompt for further adjustments.
Although this feature appears simple, it is an important dividing line between a tool that is merely interesting to try and one that can be used in production.
5. Conclusion
This project validated a clear path from business requirements to a usable product:
Turn an ambiguous business request into a well-defined generation task, use structured prompts to improve controllability, use state machines and asynchronous architecture to ensure reliability, and add a human review step to manage consistency risks.
Large models provide the creative capability, while engineering systems provide predictability and operational reliability. Only by combining both can an image generation tool become genuinely useful.
For teams with similar requirements, image generation capabilities can be accessed through cloud services. The real challenge lies in understanding the business scenario and refining the engineering details required to make the solution reliable in everyday use.
