-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add lucy-2.1-vton batch API support #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| """ | ||
| Virtual Try-On Example | ||
|
|
||
| This example demonstrates how to use the lucy-2.1-vton model to perform | ||
| virtual try-on on a video using a reference garment image. | ||
|
|
||
| Usage: | ||
| # With reference image and prompt: | ||
| DECART_API_KEY=your-key python video_tryon.py input.mp4 --reference garment.png --prompt "wear this outfit" | ||
|
|
||
| # With reference image only (empty prompt): | ||
| DECART_API_KEY=your-key python video_tryon.py input.mp4 --reference garment.png | ||
|
|
||
| Requirements: | ||
| pip install decart | ||
| """ | ||
|
|
||
| import asyncio | ||
| import argparse | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from decart import DecartClient, models | ||
|
|
||
|
|
||
| async def main(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Virtual try-on: apply a garment from a reference image onto a person in a video" | ||
| ) | ||
| parser.add_argument("video", help="Path to input video file") | ||
| parser.add_argument("--reference", "-r", required=True, help="Path to reference garment image") | ||
| parser.add_argument("--prompt", "-p", default="", help="Text prompt (default: empty string)") | ||
| parser.add_argument("--output", "-o", help="Output file path (default: output_tryon.mp4)") | ||
| parser.add_argument("--seed", "-s", type=int, help="Random seed for reproducibility") | ||
| parser.add_argument("--no-enhance", action="store_true", help="Disable prompt enhancement") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| api_key = os.getenv("DECART_API_KEY") | ||
| if not api_key: | ||
| print("Error: DECART_API_KEY environment variable not set") | ||
| sys.exit(1) | ||
|
|
||
| video_path = Path(args.video) | ||
| if not video_path.exists(): | ||
| print(f"Error: Video file not found: {video_path}") | ||
| sys.exit(1) | ||
|
|
||
| ref_path = Path(args.reference) | ||
| if not ref_path.exists(): | ||
| print(f"Error: Reference image not found: {ref_path}") | ||
| sys.exit(1) | ||
|
|
||
| output_path = args.output or f"output_tryon_{video_path.stem}.mp4" | ||
|
|
||
| print("=" * 50) | ||
| print("Virtual Try-On") | ||
| print("=" * 50) | ||
| print(f"Input video: {video_path}") | ||
| print(f"Reference image: {ref_path}") | ||
| if args.prompt: | ||
| print(f"Prompt: '{args.prompt}'") | ||
| print(f"Enhance prompt: {not args.no_enhance}") | ||
| print(f"Output: {output_path}") | ||
| if args.seed is not None: | ||
| print(f"Seed: {args.seed}") | ||
| print("=" * 50) | ||
|
|
||
| async with DecartClient(api_key=api_key) as client: | ||
| options = { | ||
| "model": models.video("lucy-2.1-vton"), | ||
| "data": video_path, | ||
| "prompt": args.prompt, | ||
| "reference_image": ref_path, | ||
| } | ||
|
|
||
| if args.prompt: | ||
| options["enhance_prompt"] = not args.no_enhance | ||
|
|
||
| if args.seed is not None: | ||
| options["seed"] = args.seed | ||
|
|
||
| def on_status_change(job): | ||
| status_emoji = { | ||
| "pending": "⏳", | ||
| "processing": "🔄", | ||
| "completed": "✅", | ||
| "failed": "❌", | ||
| } | ||
| emoji = status_emoji.get(job.status, "•") | ||
| print(f"{emoji} Status: {job.status}") | ||
|
|
||
| options["on_status_change"] = on_status_change | ||
|
|
||
| print("\nSubmitting job...") | ||
| result = await client.queue.submit_and_poll(options) | ||
|
|
||
| if result.status == "failed": | ||
| print(f"\n❌ Job failed: {result.error}") | ||
| sys.exit(1) | ||
|
|
||
| print("\n✅ Job completed!") | ||
| print(f"💾 Saving to {output_path}...") | ||
|
|
||
| with open(output_path, "wb") as f: | ||
| f.write(result.data) | ||
|
|
||
| print(f"✓ Video saved to {output_path}") | ||
| print(f" Size: {len(result.data) / 1024 / 1024:.2f} MB") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.