Update app.py
Browse files
app.py
CHANGED
|
@@ -1,290 +1,288 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import random
|
| 4 |
-
import spaces
|
| 5 |
-
import torch
|
| 6 |
-
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, AutoencoderTiny, AutoencoderKL, StableDiffusionUpscalePipeline
|
| 7 |
-
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
| 8 |
-
from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
|
| 9 |
-
from huggingface_hub import hf_hub_download
|
| 10 |
-
import os
|
| 11 |
-
import requests
|
| 12 |
-
|
| 13 |
-
dtype = torch.bfloat16
|
| 14 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 15 |
-
|
| 16 |
-
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
| 17 |
-
good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae", torch_dtype=dtype).to(device)
|
| 18 |
-
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype, vae=taef1).to(device)
|
| 19 |
-
|
| 20 |
-
# Performance optimizations
|
| 21 |
-
if hasattr(pipe, "enable_model_cpu_offload"):
|
| 22 |
-
pipe.enable_model_cpu_offload()
|
| 23 |
-
if hasattr(pipe, "enable_attention_slicing"):
|
| 24 |
-
pipe.enable_attention_slicing(1)
|
| 25 |
-
if hasattr(pipe, "enable_vae_slicing"):
|
| 26 |
-
pipe.enable_vae_slicing()
|
| 27 |
-
if hasattr(pipe, "enable_vae_tiling"):
|
| 28 |
-
pipe.enable_vae_tiling()
|
| 29 |
-
|
| 30 |
-
# Compile transformer for faster inference (if supported)
|
| 31 |
-
try:
|
| 32 |
-
pipe.transformer = torch.compile(pipe.transformer, mode="reduce-overhead", fullgraph=True)
|
| 33 |
-
print("✓ Transformer compiled for faster inference")
|
| 34 |
-
except Exception as e:
|
| 35 |
-
print(f"Warning: Could not compile transformer: {e}")
|
| 36 |
-
|
| 37 |
-
# Load upscaler pipeline with optimizations
|
| 38 |
-
upscaler = StableDiffusionUpscalePipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler", torch_dtype=dtype).to(device)
|
| 39 |
-
if hasattr(upscaler, "enable_model_cpu_offload"):
|
| 40 |
-
upscaler.enable_model_cpu_offload()
|
| 41 |
-
if hasattr(upscaler, "enable_attention_slicing"):
|
| 42 |
-
upscaler.enable_attention_slicing(1)
|
| 43 |
-
if hasattr(upscaler, "enable_vae_slicing"):
|
| 44 |
-
upscaler.enable_vae_slicing()
|
| 45 |
-
|
| 46 |
-
# Available LoRAs
|
| 47 |
-
LORAS = {
|
| 48 |
-
"None": None,
|
| 49 |
-
"AntiBlur": "Shakker-Labs/FLUX.1-dev-LoRA-AntiBlur",
|
| 50 |
-
"Add Details": "Shakker-Labs/FLUX.1-dev-LoRA-add-details"
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
print(f"
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
"
|
| 100 |
-
"
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
)
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
"
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
with gr.
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
)
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
gr.
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
)
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
)
|
| 289 |
-
|
| 290 |
demo.launch(share=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import random
|
| 4 |
+
import spaces
|
| 5 |
+
import torch
|
| 6 |
+
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, AutoencoderTiny, AutoencoderKL, StableDiffusionUpscalePipeline
|
| 7 |
+
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
| 8 |
+
from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
|
| 9 |
+
from huggingface_hub import hf_hub_download
|
| 10 |
+
import os
|
| 11 |
+
import requests
|
| 12 |
+
|
| 13 |
+
dtype = torch.bfloat16
|
| 14 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 15 |
+
|
| 16 |
+
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
| 17 |
+
good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae", torch_dtype=dtype).to(device)
|
| 18 |
+
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype, vae=taef1).to(device)
|
| 19 |
+
|
| 20 |
+
# Performance optimizations
|
| 21 |
+
if hasattr(pipe, "enable_model_cpu_offload"):
|
| 22 |
+
pipe.enable_model_cpu_offload()
|
| 23 |
+
if hasattr(pipe, "enable_attention_slicing"):
|
| 24 |
+
pipe.enable_attention_slicing(1)
|
| 25 |
+
if hasattr(pipe, "enable_vae_slicing"):
|
| 26 |
+
pipe.enable_vae_slicing()
|
| 27 |
+
if hasattr(pipe, "enable_vae_tiling"):
|
| 28 |
+
pipe.enable_vae_tiling()
|
| 29 |
+
|
| 30 |
+
# Compile transformer for faster inference (if supported)
|
| 31 |
+
try:
|
| 32 |
+
pipe.transformer = torch.compile(pipe.transformer, mode="reduce-overhead", fullgraph=True)
|
| 33 |
+
print("✓ Transformer compiled for faster inference")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Warning: Could not compile transformer: {e}")
|
| 36 |
+
|
| 37 |
+
# Load upscaler pipeline with optimizations
|
| 38 |
+
upscaler = StableDiffusionUpscalePipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler", torch_dtype=dtype).to(device)
|
| 39 |
+
if hasattr(upscaler, "enable_model_cpu_offload"):
|
| 40 |
+
upscaler.enable_model_cpu_offload()
|
| 41 |
+
if hasattr(upscaler, "enable_attention_slicing"):
|
| 42 |
+
upscaler.enable_attention_slicing(1)
|
| 43 |
+
if hasattr(upscaler, "enable_vae_slicing"):
|
| 44 |
+
upscaler.enable_vae_slicing()
|
| 45 |
+
|
| 46 |
+
# Available LoRAs
|
| 47 |
+
LORAS = {
|
| 48 |
+
"None": None,
|
| 49 |
+
"AntiBlur": "Shakker-Labs/FLUX.1-dev-LoRA-AntiBlur",
|
| 50 |
+
"Add Details": "Shakker-Labs/FLUX.1-dev-LoRA-add-details"
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# Store loaded LoRA paths
|
| 54 |
+
loaded_loras = {}
|
| 55 |
+
|
| 56 |
+
def download_lora_from_url(url, filename):
|
| 57 |
+
"""Download LoRA file from direct URL"""
|
| 58 |
+
if not os.path.exists(filename):
|
| 59 |
+
print(f"Downloading {filename}...")
|
| 60 |
+
response = requests.get(url)
|
| 61 |
+
with open(filename, 'wb') as f:
|
| 62 |
+
f.write(response.content)
|
| 63 |
+
print(f"Downloaded {filename}")
|
| 64 |
+
return filename
|
| 65 |
+
|
| 66 |
+
def preload_and_apply_all_loras():
|
| 67 |
+
"""Download and apply all LoRAs simultaneously at startup"""
|
| 68 |
+
global loaded_loras
|
| 69 |
+
|
| 70 |
+
print("Downloading and applying all LoRAs...")
|
| 71 |
+
|
| 72 |
+
for lora_name, lora_path in LORAS.items():
|
| 73 |
+
if lora_name == "None" or lora_path is None:
|
| 74 |
+
continue
|
| 75 |
+
|
| 76 |
+
# Handle direct URL downloads
|
| 77 |
+
if lora_path.startswith('http'):
|
| 78 |
+
filename = f"{lora_name.lower().replace(' ', '_')}_lora.safetensors"
|
| 79 |
+
lora_path = download_lora_from_url(lora_path, filename)
|
| 80 |
+
|
| 81 |
+
loaded_loras[lora_name] = lora_path
|
| 82 |
+
print(f"Downloaded {lora_name}")
|
| 83 |
+
|
| 84 |
+
# Apply each LoRA with optimal scaling
|
| 85 |
+
try:
|
| 86 |
+
optimal_scale = get_optimal_lora_scale(lora_name)
|
| 87 |
+
pipe.load_lora_weights(lora_path, adapter_name=lora_name.lower().replace(' ', '_'))
|
| 88 |
+
print(f"Applied {lora_name} with scale {optimal_scale}")
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"Failed to apply {lora_name}: {e}")
|
| 91 |
+
|
| 92 |
+
print(f"All {len(loaded_loras)} LoRAs downloaded and applied!")
|
| 93 |
+
|
| 94 |
+
def get_optimal_lora_scale(lora_name):
|
| 95 |
+
"""Return optimal LoRA scale based on LoRA type for better quality/speed balance"""
|
| 96 |
+
lora_scales = {
|
| 97 |
+
"AntiBlur": 0.8, # Slightly lower for better balance
|
| 98 |
+
"Add Details": 1.2, # Higher for more detail enhancement
|
| 99 |
+
"Ultra Realism": 0.9, # Balanced for realism
|
| 100 |
+
"Face Realism": 1.1, # Optimized for facial features
|
| 101 |
+
}
|
| 102 |
+
return lora_scales.get(lora_name, 1.0)
|
| 103 |
+
|
| 104 |
+
# Download and apply all LoRAs at startup
|
| 105 |
+
preload_and_apply_all_loras()
|
| 106 |
+
|
| 107 |
+
torch.cuda.empty_cache()
|
| 108 |
+
|
| 109 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 110 |
+
MAX_IMAGE_SIZE = 2048
|
| 111 |
+
|
| 112 |
+
pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
| 113 |
+
|
| 114 |
+
@spaces.GPU(duration=75)
|
| 115 |
+
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, enable_upscale=False, progress=gr.Progress(track_tqdm=True)):
|
| 116 |
+
if randomize_seed:
|
| 117 |
+
seed = random.randint(0, MAX_SEED)
|
| 118 |
+
generator = torch.Generator().manual_seed(seed)
|
| 119 |
+
|
| 120 |
+
# All LoRAs are already loaded and active
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
final_img = None
|
| 124 |
+
for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
|
| 125 |
+
prompt=prompt,
|
| 126 |
+
guidance_scale=guidance_scale,
|
| 127 |
+
num_inference_steps=num_inference_steps,
|
| 128 |
+
width=width,
|
| 129 |
+
height=height,
|
| 130 |
+
generator=generator,
|
| 131 |
+
output_type="pil",
|
| 132 |
+
good_vae=good_vae,
|
| 133 |
+
):
|
| 134 |
+
final_img = img
|
| 135 |
+
yield img, seed
|
| 136 |
+
|
| 137 |
+
# Apply upscaling if enabled with optimized settings
|
| 138 |
+
if enable_upscale and final_img is not None:
|
| 139 |
+
try:
|
| 140 |
+
# Use fewer steps for faster upscaling with minimal quality loss
|
| 141 |
+
upscaled_img = upscaler(
|
| 142 |
+
prompt=prompt,
|
| 143 |
+
image=final_img,
|
| 144 |
+
num_inference_steps=15, # Reduced from 20 for speed
|
| 145 |
+
guidance_scale=6.0, # Slightly lower for faster convergence
|
| 146 |
+
generator=generator,
|
| 147 |
+
).images[0]
|
| 148 |
+
yield upscaled_img, seed
|
| 149 |
+
except Exception as e:
|
| 150 |
+
print(f"Error during upscaling: {e}")
|
| 151 |
+
yield final_img, seed
|
| 152 |
+
|
| 153 |
+
except Exception as e:
|
| 154 |
+
print(f"Error during generation: {e}")
|
| 155 |
+
# Fallback to basic generation
|
| 156 |
+
img = pipe(
|
| 157 |
+
prompt=prompt,
|
| 158 |
+
guidance_scale=guidance_scale,
|
| 159 |
+
num_inference_steps=num_inference_steps,
|
| 160 |
+
width=width,
|
| 161 |
+
height=height,
|
| 162 |
+
generator=generator,
|
| 163 |
+
).images[0]
|
| 164 |
+
|
| 165 |
+
# Apply upscaling if enabled
|
| 166 |
+
if enable_upscale:
|
| 167 |
+
try:
|
| 168 |
+
img = upscaler(
|
| 169 |
+
prompt=prompt,
|
| 170 |
+
image=img,
|
| 171 |
+
num_inference_steps=20,
|
| 172 |
+
guidance_scale=7.5,
|
| 173 |
+
generator=generator,
|
| 174 |
+
).images[0]
|
| 175 |
+
except Exception as e:
|
| 176 |
+
print(f"Error during upscaling: {e}")
|
| 177 |
+
|
| 178 |
+
yield img, seed
|
| 179 |
+
|
| 180 |
+
examples = [
|
| 181 |
+
"a tiny astronaut hatching from an egg on the moon",
|
| 182 |
+
"a cat holding a sign that says hello world",
|
| 183 |
+
"an anime illustration of a wiener schnitzel",
|
| 184 |
+
]
|
| 185 |
+
|
| 186 |
+
css="""
|
| 187 |
+
#col-container {
|
| 188 |
+
margin: 0 auto;
|
| 189 |
+
max-width: 520px;
|
| 190 |
+
}
|
| 191 |
+
"""
|
| 192 |
+
|
| 193 |
+
with gr.Blocks(css=css) as demo:
|
| 194 |
+
|
| 195 |
+
with gr.Column(elem_id="col-container"):
|
| 196 |
+
gr.Markdown(f"""# FLUX.1 [dev]
|
| 197 |
+
12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
| 198 |
+
[[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
|
| 199 |
+
""")
|
| 200 |
+
|
| 201 |
+
with gr.Row():
|
| 202 |
+
|
| 203 |
+
prompt = gr.Text(
|
| 204 |
+
label="Prompt",
|
| 205 |
+
show_label=False,
|
| 206 |
+
max_lines=1,
|
| 207 |
+
placeholder="Enter your prompt",
|
| 208 |
+
container=False,
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
run_button = gr.Button("Run", scale=0)
|
| 212 |
+
|
| 213 |
+
result = gr.Image(label="Result", show_label=False)
|
| 214 |
+
|
| 215 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 216 |
+
|
| 217 |
+
gr.Markdown("**LoRAs Active:** All LoRAs are loaded and active simultaneously")
|
| 218 |
+
|
| 219 |
+
enable_upscale = gr.Checkbox(
|
| 220 |
+
label="Enable 4x Upscaling",
|
| 221 |
+
value=False,
|
| 222 |
+
info="Upscale final image using Stable Diffusion 4x upscaler"
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
seed = gr.Slider(
|
| 226 |
+
label="Seed",
|
| 227 |
+
minimum=0,
|
| 228 |
+
maximum=MAX_SEED,
|
| 229 |
+
step=1,
|
| 230 |
+
value=0,
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 234 |
+
|
| 235 |
+
with gr.Row():
|
| 236 |
+
|
| 237 |
+
width = gr.Slider(
|
| 238 |
+
label="Width",
|
| 239 |
+
minimum=256,
|
| 240 |
+
maximum=MAX_IMAGE_SIZE,
|
| 241 |
+
step=32,
|
| 242 |
+
value=1024,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
height = gr.Slider(
|
| 246 |
+
label="Height",
|
| 247 |
+
minimum=256,
|
| 248 |
+
maximum=MAX_IMAGE_SIZE,
|
| 249 |
+
step=32,
|
| 250 |
+
value=1024,
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
with gr.Row():
|
| 254 |
+
|
| 255 |
+
guidance_scale = gr.Slider(
|
| 256 |
+
label="Guidance Scale",
|
| 257 |
+
minimum=1,
|
| 258 |
+
maximum=15,
|
| 259 |
+
step=0.1,
|
| 260 |
+
value=3.5,
|
| 261 |
+
info="Lower values = faster generation, higher values = more prompt adherence"
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
num_inference_steps = gr.Slider(
|
| 265 |
+
label="Number of inference steps",
|
| 266 |
+
minimum=4,
|
| 267 |
+
maximum=50,
|
| 268 |
+
step=1,
|
| 269 |
+
value=20,
|
| 270 |
+
info="Lower values = faster generation, higher values = better quality"
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
gr.Examples(
|
| 274 |
+
examples = examples,
|
| 275 |
+
fn = infer,
|
| 276 |
+
inputs = [prompt],
|
| 277 |
+
outputs = [result, seed],
|
| 278 |
+
cache_examples="lazy"
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
gr.on(
|
| 282 |
+
triggers=[run_button.click, prompt.submit],
|
| 283 |
+
fn = infer,
|
| 284 |
+
inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, enable_upscale],
|
| 285 |
+
outputs = [result, seed]
|
| 286 |
+
)
|
| 287 |
+
|
|
|
|
|
|
|
| 288 |
demo.launch(share=True)
|