Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- app.py +18 -4
- live_preview_helpers.py +166 -166
- loras.json +0 -27
- modutils.py +2 -2
- requirements.txt +2 -2
app.py
CHANGED
|
@@ -3,10 +3,10 @@ import gradio as gr
|
|
| 3 |
import json
|
| 4 |
import torch
|
| 5 |
from diffusers import DiffusionPipeline, AutoencoderTiny, AutoencoderKL, AutoPipelineForImage2Image
|
| 6 |
-
from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
|
| 7 |
from diffusers.utils import load_image
|
| 8 |
from diffusers import FluxControlNetPipeline, FluxControlNetModel, FluxMultiControlNetModel, FluxControlNetImg2ImgPipeline
|
| 9 |
-
from huggingface_hub import HfFileSystem, ModelCard
|
| 10 |
import os
|
| 11 |
import copy
|
| 12 |
import random
|
|
@@ -589,9 +589,16 @@ def check_custom_model(link):
|
|
| 589 |
# Assume it's a Hugging Face model path
|
| 590 |
return get_huggingface_safetensors(link)
|
| 591 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
css = '''
|
| 593 |
-
#gen_btn{height: 100%}
|
| 594 |
#gen_column{align-self: stretch}
|
|
|
|
| 595 |
#title{text-align: center}
|
| 596 |
#title h1{font-size: 3em; display:inline-flex; align-items:center}
|
| 597 |
#title img{width: 100px; margin-right: 0.25em}
|
|
@@ -605,11 +612,12 @@ css = '''
|
|
| 605 |
#progress .generating{display:none}
|
| 606 |
.progress-container {width: 100%;height: 30px;background-color: #f0f0f0;border-radius: 15px;overflow: hidden;margin-bottom: 20px}
|
| 607 |
.progress-bar {height: 100%;background-color: #4f46e5;width: calc(var(--current) / var(--total) * 100%);transition: width 0.5s ease-in-out}
|
| 608 |
-
.button_total{height: 100
|
| 609 |
#loaded_loras [data-testid="block-info"]{font-size:80%}
|
| 610 |
#custom_lora_structure{background: var(--block-background-fill)}
|
| 611 |
#custom_lora_btn{margin-top: auto;margin-bottom: 11px}
|
| 612 |
#random_btn{font-size: 300%}
|
|
|
|
| 613 |
.info {text-align:center; !important}
|
| 614 |
'''
|
| 615 |
with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=css, delete_cache=(60, 3600)) as app:
|
|
@@ -682,6 +690,8 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=css, delete_ca
|
|
| 682 |
with gr.Column():
|
| 683 |
progress_bar = gr.Markdown(elem_id="progress",visible=False)
|
| 684 |
result = gr.Image(label="Generated Image", format="png", show_share_button=False)
|
|
|
|
|
|
|
| 685 |
with gr.Group():
|
| 686 |
model_name = gr.Dropdown(label="Base Model", info="You can enter a huggingface model repo_id to want to use.", choices=models, value=models[0], allow_custom_value=True)
|
| 687 |
model_info = gr.Markdown(elem_classes="info")
|
|
@@ -810,6 +820,10 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=css, delete_ca
|
|
| 810 |
outputs=[result, seed, progress_bar],
|
| 811 |
queue=True,
|
| 812 |
show_api=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
)
|
| 814 |
|
| 815 |
input_image.upload(preprocess_i2i_image, [input_image, input_image_preprocess, height, width], [input_image], queue=False, show_api=False)
|
|
|
|
| 3 |
import json
|
| 4 |
import torch
|
| 5 |
from diffusers import DiffusionPipeline, AutoencoderTiny, AutoencoderKL, AutoPipelineForImage2Image
|
| 6 |
+
from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
|
| 7 |
from diffusers.utils import load_image
|
| 8 |
from diffusers import FluxControlNetPipeline, FluxControlNetModel, FluxMultiControlNetModel, FluxControlNetImg2ImgPipeline
|
| 9 |
+
from huggingface_hub import hf_hub_download, HfFileSystem, ModelCard, snapshot_download
|
| 10 |
import os
|
| 11 |
import copy
|
| 12 |
import random
|
|
|
|
| 589 |
# Assume it's a Hugging Face model path
|
| 590 |
return get_huggingface_safetensors(link)
|
| 591 |
|
| 592 |
+
def update_history(new_image, history):
|
| 593 |
+
"""Updates the history gallery with the new image."""
|
| 594 |
+
if history is None:
|
| 595 |
+
history = []
|
| 596 |
+
history.insert(0, new_image)
|
| 597 |
+
return history
|
| 598 |
+
|
| 599 |
css = '''
|
|
|
|
| 600 |
#gen_column{align-self: stretch}
|
| 601 |
+
#gen_btn{height: 100%}
|
| 602 |
#title{text-align: center}
|
| 603 |
#title h1{font-size: 3em; display:inline-flex; align-items:center}
|
| 604 |
#title img{width: 100px; margin-right: 0.25em}
|
|
|
|
| 612 |
#progress .generating{display:none}
|
| 613 |
.progress-container {width: 100%;height: 30px;background-color: #f0f0f0;border-radius: 15px;overflow: hidden;margin-bottom: 20px}
|
| 614 |
.progress-bar {height: 100%;background-color: #4f46e5;width: calc(var(--current) / var(--total) * 100%);transition: width 0.5s ease-in-out}
|
| 615 |
+
#component-8, .button_total{height: 100%; align-self: stretch;}
|
| 616 |
#loaded_loras [data-testid="block-info"]{font-size:80%}
|
| 617 |
#custom_lora_structure{background: var(--block-background-fill)}
|
| 618 |
#custom_lora_btn{margin-top: auto;margin-bottom: 11px}
|
| 619 |
#random_btn{font-size: 300%}
|
| 620 |
+
#component-11{align-self: stretch;}
|
| 621 |
.info {text-align:center; !important}
|
| 622 |
'''
|
| 623 |
with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=css, delete_cache=(60, 3600)) as app:
|
|
|
|
| 690 |
with gr.Column():
|
| 691 |
progress_bar = gr.Markdown(elem_id="progress",visible=False)
|
| 692 |
result = gr.Image(label="Generated Image", format="png", show_share_button=False)
|
| 693 |
+
with gr.Accordion("History", open=False):
|
| 694 |
+
history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", interactive=False)
|
| 695 |
with gr.Group():
|
| 696 |
model_name = gr.Dropdown(label="Base Model", info="You can enter a huggingface model repo_id to want to use.", choices=models, value=models[0], allow_custom_value=True)
|
| 697 |
model_info = gr.Markdown(elem_classes="info")
|
|
|
|
| 820 |
outputs=[result, seed, progress_bar],
|
| 821 |
queue=True,
|
| 822 |
show_api=True,
|
| 823 |
+
).then( # Update the history gallery
|
| 824 |
+
fn=lambda x, history: update_history(x, history),
|
| 825 |
+
inputs=[result, history_gallery],
|
| 826 |
+
outputs=history_gallery,
|
| 827 |
)
|
| 828 |
|
| 829 |
input_image.upload(preprocess_i2i_image, [input_image, input_image_preprocess, height, width], [input_image], queue=False, show_api=False)
|
live_preview_helpers.py
CHANGED
|
@@ -1,166 +1,166 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import numpy as np
|
| 3 |
-
from diffusers import FluxPipeline, AutoencoderTiny, FlowMatchEulerDiscreteScheduler
|
| 4 |
-
from typing import Any, Dict, List, Optional, Union
|
| 5 |
-
|
| 6 |
-
# Helper functions
|
| 7 |
-
def calculate_shift(
|
| 8 |
-
image_seq_len,
|
| 9 |
-
base_seq_len: int = 256,
|
| 10 |
-
max_seq_len: int = 4096,
|
| 11 |
-
base_shift: float = 0.5,
|
| 12 |
-
max_shift: float = 1.16,
|
| 13 |
-
):
|
| 14 |
-
m = (max_shift - base_shift) / (max_seq_len - base_seq_len)
|
| 15 |
-
b = base_shift - m * base_seq_len
|
| 16 |
-
mu = image_seq_len * m + b
|
| 17 |
-
return mu
|
| 18 |
-
|
| 19 |
-
def retrieve_timesteps(
|
| 20 |
-
scheduler,
|
| 21 |
-
num_inference_steps: Optional[int] = None,
|
| 22 |
-
device: Optional[Union[str, torch.device]] = None,
|
| 23 |
-
timesteps: Optional[List[int]] = None,
|
| 24 |
-
sigmas: Optional[List[float]] = None,
|
| 25 |
-
**kwargs,
|
| 26 |
-
):
|
| 27 |
-
if timesteps is not None and sigmas is not None:
|
| 28 |
-
raise ValueError("Only one of `timesteps` or `sigmas` can be passed. Please choose one to set custom values")
|
| 29 |
-
if timesteps is not None:
|
| 30 |
-
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
|
| 31 |
-
timesteps = scheduler.timesteps
|
| 32 |
-
num_inference_steps = len(timesteps)
|
| 33 |
-
elif sigmas is not None:
|
| 34 |
-
scheduler.set_timesteps(sigmas=sigmas, device=device, **kwargs)
|
| 35 |
-
timesteps = scheduler.timesteps
|
| 36 |
-
num_inference_steps = len(timesteps)
|
| 37 |
-
else:
|
| 38 |
-
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
|
| 39 |
-
timesteps = scheduler.timesteps
|
| 40 |
-
return timesteps, num_inference_steps
|
| 41 |
-
|
| 42 |
-
# FLUX pipeline function
|
| 43 |
-
@torch.inference_mode()
|
| 44 |
-
def flux_pipe_call_that_returns_an_iterable_of_images(
|
| 45 |
-
self,
|
| 46 |
-
prompt: Union[str, List[str]] = None,
|
| 47 |
-
prompt_2: Optional[Union[str, List[str]]] = None,
|
| 48 |
-
height: Optional[int] = None,
|
| 49 |
-
width: Optional[int] = None,
|
| 50 |
-
num_inference_steps: int = 28,
|
| 51 |
-
timesteps: List[int] = None,
|
| 52 |
-
guidance_scale: float = 3.5,
|
| 53 |
-
num_images_per_prompt: Optional[int] = 1,
|
| 54 |
-
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
| 55 |
-
latents: Optional[torch.FloatTensor] = None,
|
| 56 |
-
prompt_embeds: Optional[torch.FloatTensor] = None,
|
| 57 |
-
pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
| 58 |
-
output_type: Optional[str] = "pil",
|
| 59 |
-
return_dict: bool = True,
|
| 60 |
-
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
| 61 |
-
max_sequence_length: int = 512,
|
| 62 |
-
good_vae: Optional[Any] = None,
|
| 63 |
-
):
|
| 64 |
-
height = height or self.default_sample_size * self.vae_scale_factor
|
| 65 |
-
width = width or self.default_sample_size * self.vae_scale_factor
|
| 66 |
-
|
| 67 |
-
# 1. Check inputs
|
| 68 |
-
self.check_inputs(
|
| 69 |
-
prompt,
|
| 70 |
-
prompt_2,
|
| 71 |
-
height,
|
| 72 |
-
width,
|
| 73 |
-
prompt_embeds=prompt_embeds,
|
| 74 |
-
pooled_prompt_embeds=pooled_prompt_embeds,
|
| 75 |
-
max_sequence_length=max_sequence_length,
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
self._guidance_scale = guidance_scale
|
| 79 |
-
self._joint_attention_kwargs = joint_attention_kwargs
|
| 80 |
-
self._interrupt = False
|
| 81 |
-
|
| 82 |
-
# 2. Define call parameters
|
| 83 |
-
batch_size = 1 if isinstance(prompt, str) else len(prompt)
|
| 84 |
-
device = self._execution_device
|
| 85 |
-
|
| 86 |
-
# 3. Encode prompt
|
| 87 |
-
lora_scale = joint_attention_kwargs.get("scale", None) if joint_attention_kwargs is not None else None
|
| 88 |
-
prompt_embeds, pooled_prompt_embeds, text_ids = self.encode_prompt(
|
| 89 |
-
prompt=prompt,
|
| 90 |
-
prompt_2=prompt_2,
|
| 91 |
-
prompt_embeds=prompt_embeds,
|
| 92 |
-
pooled_prompt_embeds=pooled_prompt_embeds,
|
| 93 |
-
device=device,
|
| 94 |
-
num_images_per_prompt=num_images_per_prompt,
|
| 95 |
-
max_sequence_length=max_sequence_length,
|
| 96 |
-
lora_scale=lora_scale,
|
| 97 |
-
)
|
| 98 |
-
# 4. Prepare latent variables
|
| 99 |
-
num_channels_latents = self.transformer.config.in_channels // 4
|
| 100 |
-
latents, latent_image_ids = self.prepare_latents(
|
| 101 |
-
batch_size * num_images_per_prompt,
|
| 102 |
-
num_channels_latents,
|
| 103 |
-
height,
|
| 104 |
-
width,
|
| 105 |
-
prompt_embeds.dtype,
|
| 106 |
-
device,
|
| 107 |
-
generator,
|
| 108 |
-
latents,
|
| 109 |
-
)
|
| 110 |
-
# 5. Prepare timesteps
|
| 111 |
-
sigmas = np.linspace(1.0, 1 / num_inference_steps, num_inference_steps)
|
| 112 |
-
image_seq_len = latents.shape[1]
|
| 113 |
-
mu = calculate_shift(
|
| 114 |
-
image_seq_len,
|
| 115 |
-
self.scheduler.config.base_image_seq_len,
|
| 116 |
-
self.scheduler.config.max_image_seq_len,
|
| 117 |
-
self.scheduler.config.base_shift,
|
| 118 |
-
self.scheduler.config.max_shift,
|
| 119 |
-
)
|
| 120 |
-
timesteps, num_inference_steps = retrieve_timesteps(
|
| 121 |
-
self.scheduler,
|
| 122 |
-
num_inference_steps,
|
| 123 |
-
device,
|
| 124 |
-
timesteps,
|
| 125 |
-
sigmas,
|
| 126 |
-
mu=mu,
|
| 127 |
-
)
|
| 128 |
-
self._num_timesteps = len(timesteps)
|
| 129 |
-
|
| 130 |
-
# Handle guidance
|
| 131 |
-
guidance = torch.full([1], guidance_scale, device=device, dtype=torch.float32).expand(latents.shape[0]) if self.transformer.config.guidance_embeds else None
|
| 132 |
-
|
| 133 |
-
# 6. Denoising loop
|
| 134 |
-
for i, t in enumerate(timesteps):
|
| 135 |
-
if self.interrupt:
|
| 136 |
-
continue
|
| 137 |
-
|
| 138 |
-
timestep = t.expand(latents.shape[0]).to(latents.dtype)
|
| 139 |
-
|
| 140 |
-
noise_pred = self.transformer(
|
| 141 |
-
hidden_states=latents,
|
| 142 |
-
timestep=timestep / 1000,
|
| 143 |
-
guidance=guidance,
|
| 144 |
-
pooled_projections=pooled_prompt_embeds,
|
| 145 |
-
encoder_hidden_states=prompt_embeds,
|
| 146 |
-
txt_ids=text_ids,
|
| 147 |
-
img_ids=latent_image_ids,
|
| 148 |
-
joint_attention_kwargs=self.joint_attention_kwargs,
|
| 149 |
-
return_dict=False,
|
| 150 |
-
)[0]
|
| 151 |
-
# Yield intermediate result
|
| 152 |
-
latents_for_image = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
| 153 |
-
latents_for_image = (latents_for_image / self.vae.config.scaling_factor) + self.vae.config.shift_factor
|
| 154 |
-
image = self.vae.decode(latents_for_image, return_dict=False)[0]
|
| 155 |
-
yield self.image_processor.postprocess(image, output_type=output_type)[0]
|
| 156 |
-
latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
|
| 157 |
-
torch.cuda.empty_cache()
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
# Final image using good_vae
|
| 161 |
-
latents = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
| 162 |
-
latents = (latents / good_vae.config.scaling_factor) + good_vae.config.shift_factor
|
| 163 |
-
image = good_vae.decode(latents, return_dict=False)[0]
|
| 164 |
-
self.maybe_free_model_hooks()
|
| 165 |
-
torch.cuda.empty_cache()
|
| 166 |
-
yield self.image_processor.postprocess(image, output_type=output_type)[0]
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import numpy as np
|
| 3 |
+
from diffusers import FluxPipeline, AutoencoderTiny, FlowMatchEulerDiscreteScheduler
|
| 4 |
+
from typing import Any, Dict, List, Optional, Union
|
| 5 |
+
|
| 6 |
+
# Helper functions
|
| 7 |
+
def calculate_shift(
|
| 8 |
+
image_seq_len,
|
| 9 |
+
base_seq_len: int = 256,
|
| 10 |
+
max_seq_len: int = 4096,
|
| 11 |
+
base_shift: float = 0.5,
|
| 12 |
+
max_shift: float = 1.16,
|
| 13 |
+
):
|
| 14 |
+
m = (max_shift - base_shift) / (max_seq_len - base_seq_len)
|
| 15 |
+
b = base_shift - m * base_seq_len
|
| 16 |
+
mu = image_seq_len * m + b
|
| 17 |
+
return mu
|
| 18 |
+
|
| 19 |
+
def retrieve_timesteps(
|
| 20 |
+
scheduler,
|
| 21 |
+
num_inference_steps: Optional[int] = None,
|
| 22 |
+
device: Optional[Union[str, torch.device]] = None,
|
| 23 |
+
timesteps: Optional[List[int]] = None,
|
| 24 |
+
sigmas: Optional[List[float]] = None,
|
| 25 |
+
**kwargs,
|
| 26 |
+
):
|
| 27 |
+
if timesteps is not None and sigmas is not None:
|
| 28 |
+
raise ValueError("Only one of `timesteps` or `sigmas` can be passed. Please choose one to set custom values")
|
| 29 |
+
if timesteps is not None:
|
| 30 |
+
scheduler.set_timesteps(timesteps=timesteps, device=device, **kwargs)
|
| 31 |
+
timesteps = scheduler.timesteps
|
| 32 |
+
num_inference_steps = len(timesteps)
|
| 33 |
+
elif sigmas is not None:
|
| 34 |
+
scheduler.set_timesteps(sigmas=sigmas, device=device, **kwargs)
|
| 35 |
+
timesteps = scheduler.timesteps
|
| 36 |
+
num_inference_steps = len(timesteps)
|
| 37 |
+
else:
|
| 38 |
+
scheduler.set_timesteps(num_inference_steps, device=device, **kwargs)
|
| 39 |
+
timesteps = scheduler.timesteps
|
| 40 |
+
return timesteps, num_inference_steps
|
| 41 |
+
|
| 42 |
+
# FLUX pipeline function
|
| 43 |
+
@torch.inference_mode()
|
| 44 |
+
def flux_pipe_call_that_returns_an_iterable_of_images(
|
| 45 |
+
self,
|
| 46 |
+
prompt: Union[str, List[str]] = None,
|
| 47 |
+
prompt_2: Optional[Union[str, List[str]]] = None,
|
| 48 |
+
height: Optional[int] = None,
|
| 49 |
+
width: Optional[int] = None,
|
| 50 |
+
num_inference_steps: int = 28,
|
| 51 |
+
timesteps: List[int] = None,
|
| 52 |
+
guidance_scale: float = 3.5,
|
| 53 |
+
num_images_per_prompt: Optional[int] = 1,
|
| 54 |
+
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
| 55 |
+
latents: Optional[torch.FloatTensor] = None,
|
| 56 |
+
prompt_embeds: Optional[torch.FloatTensor] = None,
|
| 57 |
+
pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
| 58 |
+
output_type: Optional[str] = "pil",
|
| 59 |
+
return_dict: bool = True,
|
| 60 |
+
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
| 61 |
+
max_sequence_length: int = 512,
|
| 62 |
+
good_vae: Optional[Any] = None,
|
| 63 |
+
):
|
| 64 |
+
height = height or self.default_sample_size * self.vae_scale_factor
|
| 65 |
+
width = width or self.default_sample_size * self.vae_scale_factor
|
| 66 |
+
|
| 67 |
+
# 1. Check inputs
|
| 68 |
+
self.check_inputs(
|
| 69 |
+
prompt,
|
| 70 |
+
prompt_2,
|
| 71 |
+
height,
|
| 72 |
+
width,
|
| 73 |
+
prompt_embeds=prompt_embeds,
|
| 74 |
+
pooled_prompt_embeds=pooled_prompt_embeds,
|
| 75 |
+
max_sequence_length=max_sequence_length,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
self._guidance_scale = guidance_scale
|
| 79 |
+
self._joint_attention_kwargs = joint_attention_kwargs
|
| 80 |
+
self._interrupt = False
|
| 81 |
+
|
| 82 |
+
# 2. Define call parameters
|
| 83 |
+
batch_size = 1 if isinstance(prompt, str) else len(prompt)
|
| 84 |
+
device = self._execution_device
|
| 85 |
+
|
| 86 |
+
# 3. Encode prompt
|
| 87 |
+
lora_scale = joint_attention_kwargs.get("scale", None) if joint_attention_kwargs is not None else None
|
| 88 |
+
prompt_embeds, pooled_prompt_embeds, text_ids = self.encode_prompt(
|
| 89 |
+
prompt=prompt,
|
| 90 |
+
prompt_2=prompt_2,
|
| 91 |
+
prompt_embeds=prompt_embeds,
|
| 92 |
+
pooled_prompt_embeds=pooled_prompt_embeds,
|
| 93 |
+
device=device,
|
| 94 |
+
num_images_per_prompt=num_images_per_prompt,
|
| 95 |
+
max_sequence_length=max_sequence_length,
|
| 96 |
+
lora_scale=lora_scale,
|
| 97 |
+
)
|
| 98 |
+
# 4. Prepare latent variables
|
| 99 |
+
num_channels_latents = self.transformer.config.in_channels // 4
|
| 100 |
+
latents, latent_image_ids = self.prepare_latents(
|
| 101 |
+
batch_size * num_images_per_prompt,
|
| 102 |
+
num_channels_latents,
|
| 103 |
+
height,
|
| 104 |
+
width,
|
| 105 |
+
prompt_embeds.dtype,
|
| 106 |
+
device,
|
| 107 |
+
generator,
|
| 108 |
+
latents,
|
| 109 |
+
)
|
| 110 |
+
# 5. Prepare timesteps
|
| 111 |
+
sigmas = np.linspace(1.0, 1 / num_inference_steps, num_inference_steps)
|
| 112 |
+
image_seq_len = latents.shape[1]
|
| 113 |
+
mu = calculate_shift(
|
| 114 |
+
image_seq_len,
|
| 115 |
+
self.scheduler.config.base_image_seq_len,
|
| 116 |
+
self.scheduler.config.max_image_seq_len,
|
| 117 |
+
self.scheduler.config.base_shift,
|
| 118 |
+
self.scheduler.config.max_shift,
|
| 119 |
+
)
|
| 120 |
+
timesteps, num_inference_steps = retrieve_timesteps(
|
| 121 |
+
self.scheduler,
|
| 122 |
+
num_inference_steps,
|
| 123 |
+
device,
|
| 124 |
+
timesteps,
|
| 125 |
+
sigmas,
|
| 126 |
+
mu=mu,
|
| 127 |
+
)
|
| 128 |
+
self._num_timesteps = len(timesteps)
|
| 129 |
+
|
| 130 |
+
# Handle guidance
|
| 131 |
+
guidance = torch.full([1], guidance_scale, device=device, dtype=torch.float32).expand(latents.shape[0]) if self.transformer.config.guidance_embeds else None
|
| 132 |
+
|
| 133 |
+
# 6. Denoising loop
|
| 134 |
+
for i, t in enumerate(timesteps):
|
| 135 |
+
if self.interrupt:
|
| 136 |
+
continue
|
| 137 |
+
|
| 138 |
+
timestep = t.expand(latents.shape[0]).to(latents.dtype)
|
| 139 |
+
|
| 140 |
+
noise_pred = self.transformer(
|
| 141 |
+
hidden_states=latents,
|
| 142 |
+
timestep=timestep / 1000,
|
| 143 |
+
guidance=guidance,
|
| 144 |
+
pooled_projections=pooled_prompt_embeds,
|
| 145 |
+
encoder_hidden_states=prompt_embeds,
|
| 146 |
+
txt_ids=text_ids,
|
| 147 |
+
img_ids=latent_image_ids,
|
| 148 |
+
joint_attention_kwargs=self.joint_attention_kwargs,
|
| 149 |
+
return_dict=False,
|
| 150 |
+
)[0]
|
| 151 |
+
# Yield intermediate result
|
| 152 |
+
latents_for_image = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
| 153 |
+
latents_for_image = (latents_for_image / self.vae.config.scaling_factor) + self.vae.config.shift_factor
|
| 154 |
+
image = self.vae.decode(latents_for_image, return_dict=False)[0]
|
| 155 |
+
yield self.image_processor.postprocess(image, output_type=output_type)[0]
|
| 156 |
+
latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
|
| 157 |
+
torch.cuda.empty_cache()
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# Final image using good_vae
|
| 161 |
+
latents = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
| 162 |
+
latents = (latents / good_vae.config.scaling_factor) + good_vae.config.shift_factor
|
| 163 |
+
image = good_vae.decode(latents, return_dict=False)[0]
|
| 164 |
+
self.maybe_free_model_hooks()
|
| 165 |
+
torch.cuda.empty_cache()
|
| 166 |
+
yield self.image_processor.postprocess(image, output_type=output_type)[0]
|
loras.json
CHANGED
|
@@ -111,12 +111,6 @@
|
|
| 111 |
"trigger_word": "JojosoStyle",
|
| 112 |
"trigger_position": "prepend"
|
| 113 |
},
|
| 114 |
-
{
|
| 115 |
-
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/picture-6-rev1.png?raw=true",
|
| 116 |
-
"title": "flux-Realism",
|
| 117 |
-
"repo": "XLabs-AI/flux-RealismLora",
|
| 118 |
-
"trigger_word": ""
|
| 119 |
-
},
|
| 120 |
{
|
| 121 |
"image": "https://huggingface.co/multimodalart/vintage-ads-flux/resolve/main/samples/j_XNU6Oe0mgttyvf9uPb3_dc244dd3d6c246b4aff8351444868d66.png",
|
| 122 |
"title": "Vintage Ads",
|
|
@@ -205,13 +199,6 @@
|
|
| 205 |
"repo": "dataautogpt3/FLUX-SyntheticAnime",
|
| 206 |
"trigger_word": "1980s anime screengrab, VHS quality"
|
| 207 |
},
|
| 208 |
-
{
|
| 209 |
-
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/result_14.png?raw=true",
|
| 210 |
-
"title": "flux-anime",
|
| 211 |
-
"repo": "XLabs-AI/flux-lora-collection",
|
| 212 |
-
"weights": "anime_lora.safetensors",
|
| 213 |
-
"trigger_word": ", anime"
|
| 214 |
-
},
|
| 215 |
{
|
| 216 |
"image": "https://replicate.delivery/yhqm/QD8Ioy5NExqSCtBS8hG04XIRQZFaC9pxJemINT1bibyjZfSTA/out-0.webp",
|
| 217 |
"title": "80s Cyberpunk",
|
|
@@ -225,20 +212,6 @@
|
|
| 225 |
"repo": "kudzueye/boreal-flux-dev-v2",
|
| 226 |
"trigger_word": "phone photo"
|
| 227 |
},
|
| 228 |
-
{
|
| 229 |
-
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/result_18.png?raw=true",
|
| 230 |
-
"title": "flux-disney",
|
| 231 |
-
"repo": "XLabs-AI/flux-lora-collection",
|
| 232 |
-
"weights": "disney_lora.safetensors",
|
| 233 |
-
"trigger_word": ", disney style"
|
| 234 |
-
},
|
| 235 |
-
{
|
| 236 |
-
"image": "https://github.com/XLabs-AI/x-flux/blob/main/assets/readme/examples/result_23.png?raw=true",
|
| 237 |
-
"title": "flux-art",
|
| 238 |
-
"repo": "XLabs-AI/flux-lora-collection",
|
| 239 |
-
"weights": "art_lora.safetensors",
|
| 240 |
-
"trigger_word": ", art"
|
| 241 |
-
},
|
| 242 |
{
|
| 243 |
"image": "https://huggingface.co/martintomov/retrofuturism-flux/resolve/main/images/2e40deba-858e-454f-ae1c-d1ba2adb6a65.jpeg",
|
| 244 |
"title": "Retrofuturism Flux",
|
|
|
|
| 111 |
"trigger_word": "JojosoStyle",
|
| 112 |
"trigger_position": "prepend"
|
| 113 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
{
|
| 115 |
"image": "https://huggingface.co/multimodalart/vintage-ads-flux/resolve/main/samples/j_XNU6Oe0mgttyvf9uPb3_dc244dd3d6c246b4aff8351444868d66.png",
|
| 116 |
"title": "Vintage Ads",
|
|
|
|
| 199 |
"repo": "dataautogpt3/FLUX-SyntheticAnime",
|
| 200 |
"trigger_word": "1980s anime screengrab, VHS quality"
|
| 201 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
{
|
| 203 |
"image": "https://replicate.delivery/yhqm/QD8Ioy5NExqSCtBS8hG04XIRQZFaC9pxJemINT1bibyjZfSTA/out-0.webp",
|
| 204 |
"title": "80s Cyberpunk",
|
|
|
|
| 212 |
"repo": "kudzueye/boreal-flux-dev-v2",
|
| 213 |
"trigger_word": "phone photo"
|
| 214 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
{
|
| 216 |
"image": "https://huggingface.co/martintomov/retrofuturism-flux/resolve/main/images/2e40deba-858e-454f-ae1c-d1ba2adb6a65.jpeg",
|
| 217 |
"title": "Retrofuturism Flux",
|
modutils.py
CHANGED
|
@@ -136,7 +136,7 @@ def save_gallery_images(images, progress=gr.Progress(track_tqdm=True)):
|
|
| 136 |
dt_now = datetime.now(timezone(timedelta(hours=9)))
|
| 137 |
basename = dt_now.strftime('%Y%m%d_%H%M%S_')
|
| 138 |
i = 1
|
| 139 |
-
if not images: return images
|
| 140 |
output_images = []
|
| 141 |
output_paths = []
|
| 142 |
for image in images:
|
|
@@ -153,7 +153,7 @@ def save_gallery_images(images, progress=gr.Progress(track_tqdm=True)):
|
|
| 153 |
output_paths.append(str(newpath))
|
| 154 |
output_images.append((str(newpath), str(filename)))
|
| 155 |
progress(1, desc="Gallery updated.")
|
| 156 |
-
return gr.update(value=output_images), gr.update(value=output_paths
|
| 157 |
|
| 158 |
|
| 159 |
def download_private_repo(repo_id, dir_path, is_replace):
|
|
|
|
| 136 |
dt_now = datetime.now(timezone(timedelta(hours=9)))
|
| 137 |
basename = dt_now.strftime('%Y%m%d_%H%M%S_')
|
| 138 |
i = 1
|
| 139 |
+
if not images: return images, gr.update(visible=False)
|
| 140 |
output_images = []
|
| 141 |
output_paths = []
|
| 142 |
for image in images:
|
|
|
|
| 153 |
output_paths.append(str(newpath))
|
| 154 |
output_images.append((str(newpath), str(filename)))
|
| 155 |
progress(1, desc="Gallery updated.")
|
| 156 |
+
return gr.update(value=output_images), gr.update(value=output_paths, visible=True)
|
| 157 |
|
| 158 |
|
| 159 |
def download_private_repo(repo_id, dir_path, is_replace):
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
spaces
|
| 2 |
torch
|
| 3 |
git+https://github.com/huggingface/diffusers.git@1131e3d04e3131f4c24565257665d75364d696d9
|
| 4 |
-
transformers
|
| 5 |
git+https://github.com/huggingface/peft.git
|
| 6 |
sentencepiece
|
| 7 |
torchvision
|
|
|
|
| 1 |
+
spaces>=0.30.3
|
| 2 |
torch
|
| 3 |
git+https://github.com/huggingface/diffusers.git@1131e3d04e3131f4c24565257665d75364d696d9
|
| 4 |
+
git+https://github.com/huggingface/transformers.git
|
| 5 |
git+https://github.com/huggingface/peft.git
|
| 6 |
sentencepiece
|
| 7 |
torchvision
|