DEV Community

William Li
William Li

Posted on

How I Built an AI Pet Portrait Generator That Turns Photos Into Art

How I Built an AI Pet Portrait Generator That Turns Photos Into Art

Ever wondered what your dog would look like as a watercolor painting? Or your cat as a royal portrait? I built a web app that does exactly that - Pet Portrait Studio transforms pet photos into custom artwork using AI.

The Problem

Traditional pet portraits cost $200-500 and take 2-4 weeks. I wanted to create something that delivers in minutes, starting from $9.

The Tech Stack

  • Backend: Python + Flask + SQLAlchemy
  • AI Engine: Multimodal models for image analysis + image generation
  • Storage: Alibaba Cloud OSS for image hosting
  • Payment: PayPal REST API
  • Email: Alibaba Cloud Enterprise Email

How It Works

1. Photo Analysis

When a user uploads a pet photo, the system uses a multimodal AI model to detect:

def analyze_pet_image(image_path: str) -> ImageAnalysis:
    """Analyze a pet image to extract features."""
    # Priority: AI Vision → Local Analysis → Smart Defaults
    result = call_modelscope_vision(
        image_path,
        prompt="Identify pet type, breed, and color in JSON format"
    )
    return ImageAnalysis(
        species=result.get("species"),
        breed=result.get("breed"),
        color=result.get("color"),
        confidence=result.get("confidence")
    )
Enter fullscreen mode Exit fullscreen mode

This auto-fills the form fields, so users don't have to manually select their pet's breed.

2. Prompt Engineering

The core of the system is the prompt engine that generates style-specific prompts:

  • Watercolor: "Soft, flowing watercolor painting with gentle washes..."
  • Oil Painting: "Classical oil painting with rich textures and warm tones..."
  • Cartoon: "Fun, Pixar-style cartoon with vibrant colors..."

Each style has 100+ prompt variations to ensure uniqueness.

3. Quality Scoring

Generated portraits are scored by a separate AI model on 4 dimensions:

  • Image clarity (25%)
  • Artistic style consistency (25%)
  • Pet feature accuracy (25%)
  • Overall aesthetics (25%)

Only portraits scoring above 7/10 are delivered.

4. Delivery

Portraits are delivered via email with download links. The system supports:

  • Priority queue (paid orders process first)
  • Revisions (Pro: 1, Deluxe: 3)
  • HD upscaling for Deluxe tier

Key Technical Decisions

Why Flask over Django? The app is primarily a single-purpose tool, not a complex platform. Flask's simplicity fits better.

Why self-hosted AI? Using Alibaba Cloud's DashScope API gives us control over model selection and cost. We can switch models without changing the application code.

Why SQLite? For a solo operator with <1000 orders/day, SQLite with WAL mode handles the load fine. PostgreSQL migration is planned for when traffic grows.

Results

  • 30 SEO landing pages targeting long-tail keywords
  • 14 blog posts for content marketing
  • Conversion rate: ~60% (small sample)
  • Average delivery time: 5-15 minutes

Try It

Upload your pet photo at custompetart.store - registered users get 3 free portraits.

Top comments (0)