feat: zip batch image support
This commit is contained in:
		
							parent
							
								
									503dca8fb6
								
							
						
					
					
						commit
						e011711600
					
				@ -39,18 +39,38 @@ class ComfyUIDeployExternalImageBatch:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    CATEGORY = "image"
 | 
					    CATEGORY = "image"
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def process_image(self, image):
 | 
				
			||||||
 | 
					        image = ImageOps.exif_transpose(image)
 | 
				
			||||||
 | 
					        image = image.convert("RGB")
 | 
				
			||||||
 | 
					        image = np.array(image).astype(np.float32) / 255.0
 | 
				
			||||||
 | 
					        image_tensor = torch.from_numpy(image)[None,]
 | 
				
			||||||
 | 
					        return image_tensor
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    def run(self, input_id, images=None, default_value=None, display_name=None, description=None):
 | 
					    def run(self, input_id, images=None, default_value=None, display_name=None, description=None):
 | 
				
			||||||
 | 
					        import requests
 | 
				
			||||||
 | 
					        import zipfile
 | 
				
			||||||
 | 
					        import io
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        processed_images = []
 | 
					        processed_images = []
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            images_list = json.loads(images)  # Assuming images is a JSON array string
 | 
					            images_list = json.loads(images)  # Assuming images is a JSON array string
 | 
				
			||||||
            print(images_list)
 | 
					            print(images_list)
 | 
				
			||||||
            for img_input in images_list:
 | 
					            for img_input in images_list:
 | 
				
			||||||
                if img_input.startswith('http'):
 | 
					                if img_input.startswith('http'):
 | 
				
			||||||
                    import requests
 | 
					 | 
				
			||||||
                    from io import BytesIO
 | 
					                    from io import BytesIO
 | 
				
			||||||
                    print("Fetching image from url: ", img_input)
 | 
					                    print("Fetching image from url: ", img_input)
 | 
				
			||||||
                    response = requests.get(img_input)
 | 
					                    response = requests.get(img_input)
 | 
				
			||||||
                    image = Image.open(BytesIO(response.content))
 | 
					                    image = Image.open(BytesIO(response.content))
 | 
				
			||||||
 | 
					                elif img_input.startswith('http') and img_input.endswith('.zip'):
 | 
				
			||||||
 | 
					                    print("Fetching zip file from url: ", img_input)
 | 
				
			||||||
 | 
					                    response = requests.get(img_input)
 | 
				
			||||||
 | 
					                    zip_file = zipfile.ZipFile(io.BytesIO(response.content))
 | 
				
			||||||
 | 
					                    for file_name in zip_file.namelist():
 | 
				
			||||||
 | 
					                        if file_name.lower().endswith(('.png', '.jpg', '.jpeg')):
 | 
				
			||||||
 | 
					                            with zip_file.open(file_name) as file:
 | 
				
			||||||
 | 
					                                image = Image.open(file)
 | 
				
			||||||
 | 
					                                image = self.process_image(image)
 | 
				
			||||||
 | 
					                                processed_images.append(image)
 | 
				
			||||||
                elif img_input.startswith('data:image/png;base64,') or img_input.startswith('data:image/jpeg;base64,') or img_input.startswith('data:image/jpg;base64,'):
 | 
					                elif img_input.startswith('data:image/png;base64,') or img_input.startswith('data:image/jpeg;base64,') or img_input.startswith('data:image/jpg;base64,'):
 | 
				
			||||||
                    import base64
 | 
					                    import base64
 | 
				
			||||||
                    from io import BytesIO
 | 
					                    from io import BytesIO
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user