Skip to content

Model Swap Agent Added#87

Merged
kailashahirwar merged 1 commit intomainfrom
agents
Dec 24, 2025
Merged

Model Swap Agent Added#87
kailashahirwar merged 1 commit intomainfrom
agents

Conversation

@kailashahirwar
Copy link
Collaborator

@kailashahirwar kailashahirwar commented Dec 24, 2025

Description

This PR adds a new Model Swap Agent that intelligently replaces models/people in images while preserving outfits and styling. The agent uses LangChain to extract person attributes from natural language prompts and generates professional model-swapped images using multiple AI models (Nano Banana, Nano Banana Pro, FLUX 2 Pro, FLUX 2 Flex).

Related Issue

Fixes #86

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Documentation update

Component Affected

  • AI Agents
  • Image Generation (Nano Banana / FLUX.2)
  • CLI Tools
  • Documentation

Changes Made

  • Added Model Swap Agent (tryon/agents/model_swap/):

    • agent.py: Main ModelSwapAgent class with LangChain integration
    • tools.py: LangChain tools for all supported models (Nano Banana, Nano Banana Pro, FLUX 2 Pro, FLUX 2 Flex)
    • __init__.py: Module exports
  • Added Command Line Interface (model_swap_agent.py):

    • Full CLI support with model selection
    • Support for all model options
    • Resolution and search grounding options for Nano Banana Pro
    • Verbose output and error handling
  • Multi-Model Support:

    • Nano Banana: Fast 1024px generation
    • Nano Banana Pro: High-quality 4K resolution (default)
    • FLUX 2 Pro: Professional quality with custom dimensions
    • FLUX 2 Flex: Advanced controls (guidance, steps)
  • Documentation:

    • Comprehensive Docusaurus documentation (docs/docs/agents/model-swap-agent.md)
    • Updated README.md with Model Swap Agent section
    • Updated sidebars.ts to include new documentation
  • Features:

    • Intelligent attribute extraction from natural language prompts
    • Perfect outfit preservation (clothing, colors, patterns, textures)
    • Multi-LLM support (OpenAI, Anthropic, Google)
    • High-resolution output (up to 4K)
    • Professional photography quality maintenance

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes

Test Environment

  • Python Version: 3.10+
  • OS: macOS / Linux
  • GPU: N/A (uses cloud APIs)

Test Cases

  1. ✅ Basic model swap with Nano Banana Pro (default)
  2. ✅ Model swap with FLUX 2 Pro
  3. ✅ Model swap with FLUX 2 Flex
  4. ✅ Model swap with Nano Banana (fast)
  5. ✅ Resolution options for Nano Banana Pro (1K, 2K, 4K)
  6. ✅ Search grounding for Nano Banana Pro
  7. ✅ Different LLM providers (OpenAI, Anthropic, Google)
  8. ✅ Command line interface with all options
  9. ✅ Error handling and validation
  10. ✅ Outfit preservation verification

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots / Examples

Command Line Usage

# Basic usage with default Nano Banana Pro
python model_swap_agent.py \
    --image model.jpg \
    --prompt "Replace with a professional male model in his 30s, athletic build"

# Use FLUX 2 Pro for high-quality results
python model_swap_agent.py \
    --image model.jpg \
    --prompt "Replace with a professional female model" \
    --model flux2_pro

# 4K professional quality
python model_swap_agent.py \
    --image outfit.jpg \
    --prompt "Asian female model, mid-20s, athletic, confident pose" \
    --model nano_banana_pro \
    --resolution 4K

Python API Usage

from tryon.agents.model_swap import ModelSwapAgent

# Initialize agent
agent = ModelSwapAgent(llm_provider="openai")

# Generate model swap
result = agent.generate(
    image="person_wearing_outfit.jpg",
    prompt="Replace with a professional Asian female model in her 30s, athletic build"
)

if result["status"] == "success":
    for idx, image in enumerate(result['images']):
        image.save(f"swapped_model_{idx}.png")

Additional Notes

  • The agent uses LangChain 1.x API (create_agent)
  • Supports multiple LLM providers for intelligent prompt analysis
  • All models preserve outfit details automatically
  • Default model is Nano Banana Pro for best quality
  • Documentation is comprehensive and includes examples for all use cases
  • The implementation follows the same patterns as the existing Virtual Try-On Agent

API Keys Required

  • LLM Provider: OPENAI_API_KEY, ANTHROPIC_API_KEY, or GOOGLE_API_KEY
  • Nano Banana Models: GEMINI_API_KEY
  • FLUX 2 Models: BFL_API_KEY

Model Comparison

Model Resolution Speed Quality Best For
Nano Banana 1024px Fast ⚡ Good Quick iterations
Nano Banana Pro Up to 4K Medium Excellent Professional e-commerce (default)
FLUX 2 Pro Custom Medium High Professional quality
FLUX 2 Flex Custom Slower Highest Fine-tuned control

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Compliance Checks Passed!

@kailashahirwar kailashahirwar merged commit 994fc8e into main Dec 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Model Swap Agent - AI Agent for Replacing Models While Preserving Outfits

1 participant