Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import random
|
| 5 |
import torch
|
| 6 |
from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlowMatchEulerDiscreteScheduler
|
|
|
|
| 7 |
|
| 8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 9 |
dtype = torch.float16
|
|
@@ -14,7 +15,7 @@ pipe = StableDiffusion3Pipeline.from_pretrained(repo, torch_dtype=torch.float16)
|
|
| 14 |
MAX_SEED = np.iinfo(np.int32).max
|
| 15 |
MAX_IMAGE_SIZE = 1344
|
| 16 |
|
| 17 |
-
@spaces.GPU
|
| 18 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
| 19 |
|
| 20 |
if randomize_seed:
|
|
@@ -31,6 +32,14 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
| 31 |
height = height,
|
| 32 |
generator = generator
|
| 33 |
).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
return image, seed
|
| 36 |
|
|
@@ -93,7 +102,6 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme", js=js_func) as generino:
|
|
| 93 |
prompt = gr.Text(
|
| 94 |
label="Prompt",
|
| 95 |
show_label=False,
|
| 96 |
-
max_lines=3,
|
| 97 |
placeholder="Enter your prompt",
|
| 98 |
container=False,
|
| 99 |
elem_id="prompt",
|
|
@@ -168,4 +176,4 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme", js=js_func) as generino:
|
|
| 168 |
outputs = [result, seed]
|
| 169 |
)
|
| 170 |
|
| 171 |
-
generino.launch(show_api=False)
|
|
|
|
| 4 |
import random
|
| 5 |
import torch
|
| 6 |
from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlowMatchEulerDiscreteScheduler
|
| 7 |
+
import re
|
| 8 |
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
dtype = torch.float16
|
|
|
|
| 15 |
MAX_SEED = np.iinfo(np.int32).max
|
| 16 |
MAX_IMAGE_SIZE = 1344
|
| 17 |
|
| 18 |
+
@spaces.GPU(enable_queue=True)
|
| 19 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
| 20 |
|
| 21 |
if randomize_seed:
|
|
|
|
| 32 |
height = height,
|
| 33 |
generator = generator
|
| 34 |
).images[0]
|
| 35 |
+
|
| 36 |
+
# Sanitize the prompt to make it filesystem-safe
|
| 37 |
+
sanitized_prompt = re.sub(r'[<>:"/\\|?*]', '_', prompt)
|
| 38 |
+
sanitized_prompt = sanitized_prompt[:50] # Truncate to avoid excessively long filenames
|
| 39 |
+
|
| 40 |
+
# Save the image as PNG with the sanitized prompt in the name
|
| 41 |
+
save_path = f"generated_image_{sanitized_prompt}_{seed}.png"
|
| 42 |
+
image.save(save_path, format="PNG")
|
| 43 |
|
| 44 |
return image, seed
|
| 45 |
|
|
|
|
| 102 |
prompt = gr.Text(
|
| 103 |
label="Prompt",
|
| 104 |
show_label=False,
|
|
|
|
| 105 |
placeholder="Enter your prompt",
|
| 106 |
container=False,
|
| 107 |
elem_id="prompt",
|
|
|
|
| 176 |
outputs = [result, seed]
|
| 177 |
)
|
| 178 |
|
| 179 |
+
generino.queue(max_size=10).launch(show_api=False, share=False)
|