Spaces:
Runtime error
Runtime error
main
Browse files99 unmodified lines1001011021031041051064 unmodified lines11111211311411511612 unmodified lines12913013113213313413513613713813914014114214314414514614749 unmodified lines19719819920020120220320420530 unmodified lines2362372382392402412422437 unmodified lines25125225325425525625725825926026126222 unmodified lines28528628728828929029199 unmodified linest5xxl = flux_utils.load_t5xxl(T5XXL_PATH, torch.bfloat16, "cpu", disable_mmap=False)t5xxl.eval()ae = flux_utils.load_ae(AE_PATH, torch.bfloat16, "cpu", disable_mmap=False)logger.info("Models loaded successfully.")# Load LoRA weightsmultiplier = 1.04 unmodified lineslogger.info(f"Loaded LoRA weights from {LORA_WEIGHTS_PATH}: {info}")lora_model.eval()except Exception as e:logger.error(f"Error loading models: {e}")raise12 unmodified lineswidth, height = img.size# Convert to RGB to remove transparency, fill with white background if necessaryif img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info):background = Image.new("RGB", img.size, (fill, fill, fill))background.paste(img, mask=img.split()[-1]) # Use alpha channel as maskimg = backgroundif width == height:img = img.resize((self.size, self.size), Image.LANCZOS)else:max_dim = max(width, height)new_img = Image.new("RGB", (max_dim, max_dim), (self.fill, self.fill, self.fill))new_img.paste(img, ((max_dim - width) // 2, (max_dim - height) // 2))img = new_img.resize((self.size, self.size), Image.LANCZOS)return img# The function to generate image from a prompt and conditional image49 unmodified lineslogger.debug("Image encoded to latents.")conditions = {}conditions[prompt] = latents.to("cpu")ae.to("cpu")clip_l.to(device)t5xxl.to(device)30 unmodified linesargs = lambda: Noneargs.frame_num = frame_numclip_l.to("cpu")t5xxl.to("cpu")model.to(device)7 unmodified lines# Decode the final imagex = x.float()x = flux_utils.unpack_latents(x, packed_latent_height, packed_latent_width)model.to("cpu")ae.to(device)with accelerator.autocast(), torch.no_grad():x = ae.decode(x)logger.debug("Latents decoded into image.")ae.to("cpu")# Convert the tensor to an imagex = x.clamp(-1, 1)22 unmodified linessample_image = gr.Image(label="Upload a Conditional Image", type="pil")# Frame number selectionframe_num = gr.Radio([4, 9], label="Select Frame Number", value=4)# Seedseed = gr.Slider(0, np.iinfo(np.int32).max, step=1, label="Seed", value=0)99 unmodified lines1001011021031041054 unmodified lines11011111211311411511611712 unmodified lines13013113213313413513613713813914014114214314414514614714849 unmodified lines19819920020120220320420520620720830 unmodified lines2392402412422432442452467 unmodified lines25425525625725825926026126226326426522 unmodified lines28828929029129229329499 unmodified linest5xxl = flux_utils.load_t5xxl(T5XXL_PATH, torch.bfloat16, "cpu", disable_mmap=False)t5xxl.eval()ae = flux_utils.load_ae(AE_PATH, torch.bfloat16, "cpu", disable_mmap=False)# Load LoRA weightsmultiplier = 1.04 unmodified lineslogger.info(f"Loaded LoRA weights from {LORA_WEIGHTS_PATH}: {info}")lora_model.eval()logger.info("Models loaded successfully.")except Exception as e:logger.error(f"Error loading models: {e}")raise12 unmodified lineswidth, height = img.size# # Convert to RGB to remove transparency, fill with white background if necessary# if img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info):# background = Image.new("RGB", img.size, (fill, fill, fill))# background.paste(img, mask=img.split()[-1]) # Use alpha channel as mask# img = background# if width == height:# img = img.resize((self.size, self.size), Image.LANCZOS)# else:max_dim = max(width, height)new_img = Image.new("RGB", (max_dim, max_dim), (self.fill, self.fill, self.fill))new_img.paste(img, ((max_dim - width) // 2, (max_dim - height) // 2))img = new_img.resize((self.size, self.size), Image.LANCZOS)return img# The function to generate image from a prompt and conditional image49 unmodified lineslogger.debug("Image encoded to latents.")conditions = {}# conditions[prompt] = latents.to("cpu")conditions[prompt] = latents# ae.to("cpu")clip_l.to(device)t5xxl.to(device)30 unmodified linesargs = lambda: Noneargs.frame_num = frame_num# clip_l.to("cpu")# t5xxl.to("cpu")model.to(device)7 unmodified lines# Decode the final imagex = x.float()x = flux_utils.unpack_latents(x, packed_latent_height, packed_latent_width)# model.to("cpu")ae.to(device)with accelerator.autocast(), torch.no_grad():x = ae.decode(x)logger.debug("Latents decoded into image.")# ae.to("cpu")# Convert the tensor to an imagex = x.clamp(-1, 1)22 unmodified linessample_image = gr.Image(label="Upload a Conditional Image", type="pil")# Frame number selectionframe_num = gr.Radio([4, 9], label="Select Frame Number", value=9)# Seedseed = gr.Slider(0, np.iinfo(np.int32).max, step=1, label="Seed", value=0)
gradio_app.py+24-21