ComfyUI : Using the API : Part 2

<blockquote> <p>One particular use case I have after training a model with various saved checkpoints is to produce test images from each one with different prompts, and different image aspect ratios and perhaps different other settings. The only way to do this via the main UI was through a lot of clicking around. But that is one for a future guide.</p> </blockquote> <p>For this Part 2 guide I will produce a simple script that will:<br /> &mdash;&nbsp;<strong>Iterate through a list of prompts<br /> &mdash; &mdash; For each prompt, iterate through a list of checkpoints<br /> &mdash; &mdash; &mdash; For each checkpoint, iterate through a list of different image sizes<br /> &mdash; &mdash; &mdash; &mdash; For each image size, generate the image.<br /> &mdash; &mdash; &mdash; &mdash; Each image will be placed in a folder named as the&nbsp;</strong><code>[prompt]</code><br /> <strong>&mdash; &mdash; &mdash; &mdash; Each image named:</strong><code>[checkpoint_name]_[image_size]_index.png</code></p> <p>If you have followed&nbsp;<a href="https://medium.com/@yushantripleseven/comfyui-using-the-api-261293aa055a" rel="noopener">Part 1</a>, then much of it will be familiar. The main differences from Part 1 is that some parts will be broken up into smaller functions. Once again I will show the script in chunks so it&rsquo;s more digestible and then at the end I will show the whole thing.</p> <p>Once again, some python or general programming experience would be useful, but not essential.</p> <p>Let&rsquo;s start by saving the default workflow in api format and use the default name&nbsp;<code><strong>workflow_api.json</strong></code>.</p> <p>Next create a file named:&nbsp;<code><strong>multiprompt_multicheckpoint_multires_api_workflow.py</strong></code>. Open it in your editor of choice and add the import statements:</p> <p><a href="https://medium.com/@yushantripleseven/comfyui-using-the-api-part-2-daac17fd2727"><strong>Website</strong></a></p>
Tags: ComfyUI API