Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import random
|
|
| 3 |
import gradio as gr
|
| 4 |
from diffusers import StableDiffusionXLPipeline
|
| 5 |
|
| 6 |
-
# Modell laden
|
| 7 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 8 |
"John6666/wai-real-mix-v10-sdxl",
|
| 9 |
use_safetensors=True,
|
|
@@ -11,16 +10,17 @@ pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
| 11 |
low_cpu_mem_usage=True
|
| 12 |
).to("cpu")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps, seed, width, height):
|
| 16 |
if seed == -1:
|
| 17 |
seed = random.randint(0, 2**32 - 1)
|
| 18 |
generator = torch.Generator(device="cpu").manual_seed(seed)
|
| 19 |
|
| 20 |
-
# Fallback fΓΌr negative_prompt, falls leer
|
| 21 |
if not negative_prompt.strip():
|
| 22 |
negative_prompt = "blurry, low quality, distorted"
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
image = pipe(
|
| 25 |
prompt=prompt,
|
| 26 |
negative_prompt=negative_prompt,
|
|
@@ -28,39 +28,39 @@ def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps,
|
|
| 28 |
num_inference_steps=num_inference_steps,
|
| 29 |
generator=generator,
|
| 30 |
width=width,
|
| 31 |
-
height=height
|
|
|
|
|
|
|
| 32 |
).images[0]
|
| 33 |
|
| 34 |
return image, seed
|
| 35 |
|
| 36 |
-
# UI mit Gradio
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
gr.Markdown("# π§ WAI Real Mix v10 (SDXL on CPU)")
|
| 39 |
-
gr.Markdown("Generate images with full control over prompts, resolution, and more.")
|
| 40 |
|
| 41 |
with gr.Row():
|
| 42 |
with gr.Column():
|
| 43 |
prompt = gr.Textbox(label="Prompt", placeholder="A futuristic city in sunset, ultra-detailed")
|
| 44 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="blurry, low quality, distorted")
|
| 45 |
-
|
| 46 |
with gr.Row():
|
| 47 |
width = gr.Slider(512, 1024, value=768, step=64, label="Width")
|
| 48 |
height = gr.Slider(512, 1024, value=768, step=64, label="Height")
|
| 49 |
-
|
| 50 |
guidance_scale = gr.Slider(1.0, 20.0, value=7.5, step=0.1, label="Guidance Scale (CFG)")
|
| 51 |
num_inference_steps = gr.Slider(10, 50, value=30, step=1, label="Inference Steps")
|
| 52 |
seed = gr.Number(value=-1, precision=0, label="Seed (-1 = random)")
|
| 53 |
-
|
| 54 |
run_button = gr.Button("Generate")
|
| 55 |
|
| 56 |
with gr.Column():
|
| 57 |
output_image = gr.Image(label="Generated Image")
|
| 58 |
used_seed = gr.Textbox(label="Used Seed", interactive=False)
|
|
|
|
| 59 |
|
| 60 |
run_button.click(
|
| 61 |
fn=generate_image,
|
| 62 |
inputs=[prompt, negative_prompt, guidance_scale, num_inference_steps, seed, width, height],
|
| 63 |
-
outputs=[output_image, used_seed]
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
demo.launch()
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from diffusers import StableDiffusionXLPipeline
|
| 5 |
|
|
|
|
| 6 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 7 |
"John6666/wai-real-mix-v10-sdxl",
|
| 8 |
use_safetensors=True,
|
|
|
|
| 10 |
low_cpu_mem_usage=True
|
| 11 |
).to("cpu")
|
| 12 |
|
| 13 |
+
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps, seed, width, height, progress=gr.Progress()):
|
|
|
|
| 14 |
if seed == -1:
|
| 15 |
seed = random.randint(0, 2**32 - 1)
|
| 16 |
generator = torch.Generator(device="cpu").manual_seed(seed)
|
| 17 |
|
|
|
|
| 18 |
if not negative_prompt.strip():
|
| 19 |
negative_prompt = "blurry, low quality, distorted"
|
| 20 |
|
| 21 |
+
def callback(step: int, timestep: int, latents):
|
| 22 |
+
progress((step + 1) / num_inference_steps)
|
| 23 |
+
|
| 24 |
image = pipe(
|
| 25 |
prompt=prompt,
|
| 26 |
negative_prompt=negative_prompt,
|
|
|
|
| 28 |
num_inference_steps=num_inference_steps,
|
| 29 |
generator=generator,
|
| 30 |
width=width,
|
| 31 |
+
height=height,
|
| 32 |
+
callback=callback,
|
| 33 |
+
callback_steps=1
|
| 34 |
).images[0]
|
| 35 |
|
| 36 |
return image, seed
|
| 37 |
|
|
|
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
gr.Markdown("# π§ WAI Real Mix v10 (SDXL on CPU)")
|
|
|
|
| 40 |
|
| 41 |
with gr.Row():
|
| 42 |
with gr.Column():
|
| 43 |
prompt = gr.Textbox(label="Prompt", placeholder="A futuristic city in sunset, ultra-detailed")
|
| 44 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="blurry, low quality, distorted")
|
|
|
|
| 45 |
with gr.Row():
|
| 46 |
width = gr.Slider(512, 1024, value=768, step=64, label="Width")
|
| 47 |
height = gr.Slider(512, 1024, value=768, step=64, label="Height")
|
|
|
|
| 48 |
guidance_scale = gr.Slider(1.0, 20.0, value=7.5, step=0.1, label="Guidance Scale (CFG)")
|
| 49 |
num_inference_steps = gr.Slider(10, 50, value=30, step=1, label="Inference Steps")
|
| 50 |
seed = gr.Number(value=-1, precision=0, label="Seed (-1 = random)")
|
|
|
|
| 51 |
run_button = gr.Button("Generate")
|
| 52 |
|
| 53 |
with gr.Column():
|
| 54 |
output_image = gr.Image(label="Generated Image")
|
| 55 |
used_seed = gr.Textbox(label="Used Seed", interactive=False)
|
| 56 |
+
progress_bar = gr.Progress(label="Progress")
|
| 57 |
|
| 58 |
run_button.click(
|
| 59 |
fn=generate_image,
|
| 60 |
inputs=[prompt, negative_prompt, guidance_scale, num_inference_steps, seed, width, height],
|
| 61 |
+
outputs=[output_image, used_seed],
|
| 62 |
+
progress=progress_bar
|
| 63 |
)
|
| 64 |
|
| 65 |
demo.launch()
|
| 66 |
+
|