Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -124,7 +124,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
| 124 |
seed = random.randint(0, MAX_SEED)
|
| 125 |
return seed
|
| 126 |
|
| 127 |
-
@spaces.GPU(duration=
|
| 128 |
def generate(
|
| 129 |
model_choice: str,
|
| 130 |
prompt: str,
|
|
@@ -174,6 +174,55 @@ def generate(
|
|
| 174 |
image_paths = [save_image(img) for img in images]
|
| 175 |
return image_paths, seed
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
def load_predefined_images1():
|
| 178 |
predefined_images1 = [
|
| 179 |
"assets/7.png",
|
|
@@ -215,6 +264,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
| 215 |
container=False,
|
| 216 |
)
|
| 217 |
run_button = gr.Button("Run", scale=0)
|
|
|
|
| 218 |
result = gr.Gallery(label="Result", columns=1, show_label=False)
|
| 219 |
|
| 220 |
with gr.Row():
|
|
@@ -328,6 +378,29 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
| 328 |
outputs=[result, seed],
|
| 329 |
)
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
gr.Markdown("### REALVISXL V5.0")
|
| 332 |
predefined_gallery = gr.Gallery(label="REALVISXL V5.0", columns=3, show_label=False, value=load_predefined_images1())
|
| 333 |
|
|
|
|
| 124 |
seed = random.randint(0, MAX_SEED)
|
| 125 |
return seed
|
| 126 |
|
| 127 |
+
@spaces.GPU(duration=70, enable_queue=True)
|
| 128 |
def generate(
|
| 129 |
model_choice: str,
|
| 130 |
prompt: str,
|
|
|
|
| 174 |
image_paths = [save_image(img) for img in images]
|
| 175 |
return image_paths, seed
|
| 176 |
|
| 177 |
+
def generate_cpu(
|
| 178 |
+
model_choice: str,
|
| 179 |
+
prompt: str,
|
| 180 |
+
negative_prompt: str = "",
|
| 181 |
+
use_negative_prompt: bool = False,
|
| 182 |
+
style_selection: str = DEFAULT_STYLE_NAME,
|
| 183 |
+
seed: int = 1,
|
| 184 |
+
width: int = 768,
|
| 185 |
+
height: int = 768,
|
| 186 |
+
guidance_scale: float = 4,
|
| 187 |
+
num_inference_steps: int = 150,
|
| 188 |
+
randomize_seed: bool = False,
|
| 189 |
+
use_resolution_binning: bool = True,
|
| 190 |
+
num_images: int = 1,
|
| 191 |
+
progress=gr.Progress(track_tqdm=True),
|
| 192 |
+
):
|
| 193 |
+
global models
|
| 194 |
+
pipe = models[model_choice]
|
| 195 |
+
|
| 196 |
+
seed = int(randomize_seed_fn(seed, randomize_seed))
|
| 197 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
| 198 |
+
|
| 199 |
+
prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 200 |
+
|
| 201 |
+
options = {
|
| 202 |
+
"prompt": [prompt] * num_images,
|
| 203 |
+
"negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,
|
| 204 |
+
"width": width,
|
| 205 |
+
"height": height,
|
| 206 |
+
"guidance_scale": guidance_scale,
|
| 207 |
+
"num_inference_steps": num_inference_steps,
|
| 208 |
+
"generator": generator,
|
| 209 |
+
"output_type": "pil",
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
if use_resolution_binning:
|
| 213 |
+
options["use_resolution_binning"] = True
|
| 214 |
+
|
| 215 |
+
images = []
|
| 216 |
+
for i in range(0, num_images, BATCH_SIZE):
|
| 217 |
+
batch_options = options.copy()
|
| 218 |
+
batch_options["prompt"] = options["prompt"][i:i+BATCH_SIZE]
|
| 219 |
+
if "negative_prompt" in batch_options:
|
| 220 |
+
batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
|
| 221 |
+
images.extend(pipe(**batch_options).images)
|
| 222 |
+
|
| 223 |
+
image_paths = [save_image(img) for img in images]
|
| 224 |
+
return image_paths, seed
|
| 225 |
+
|
| 226 |
def load_predefined_images1():
|
| 227 |
predefined_images1 = [
|
| 228 |
"assets/7.png",
|
|
|
|
| 264 |
container=False,
|
| 265 |
)
|
| 266 |
run_button = gr.Button("Run", scale=0)
|
| 267 |
+
cpu_run_button = gr.Button("CPU Run", scale=0)
|
| 268 |
result = gr.Gallery(label="Result", columns=1, show_label=False)
|
| 269 |
|
| 270 |
with gr.Row():
|
|
|
|
| 378 |
outputs=[result, seed],
|
| 379 |
)
|
| 380 |
|
| 381 |
+
gr.on(
|
| 382 |
+
triggers=[
|
| 383 |
+
cpu_run_button.click,
|
| 384 |
+
],
|
| 385 |
+
api_name="generate", # Add this line
|
| 386 |
+
fn=generate_cpu,
|
| 387 |
+
inputs=[
|
| 388 |
+
model_choice,
|
| 389 |
+
prompt,
|
| 390 |
+
negative_prompt,
|
| 391 |
+
use_negative_prompt,
|
| 392 |
+
style_selection,
|
| 393 |
+
seed,
|
| 394 |
+
width,
|
| 395 |
+
height,
|
| 396 |
+
guidance_scale,
|
| 397 |
+
num_inference_steps,
|
| 398 |
+
randomize_seed,
|
| 399 |
+
num_images,
|
| 400 |
+
],
|
| 401 |
+
outputs=[result, seed],
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
gr.Markdown("### REALVISXL V5.0")
|
| 405 |
predefined_gallery = gr.Gallery(label="REALVISXL V5.0", columns=3, show_label=False, value=load_predefined_images1())
|
| 406 |
|