Spaces:
Runtime error
Runtime error
File size: 4,252 Bytes
4294d6b e66e398 b5f713d 4294d6b b5f713d 4294d6b e66e398 b5f713d e66e398 4294d6b b5f713d e66e398 4294d6b e66e398 b5f713d e66e398 b5f713d e66e398 b5f713d e66e398 b5f713d 4294d6b b5f713d 4294d6b e66e398 b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b e66e398 b5f713d 4294d6b b5f713d e66e398 b5f713d e66e398 b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b b5f713d 4294d6b e66e398 b5f713d e66e398 b5f713d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 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 |
import torch
import gradio as gr
from diffusers import DiffusionPipeline
# ================== DEVICE ==================
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}")
# ================== LOAD PIPELINE ==================
print("Loading Z-Image-Turbo pipeline...")
pipe = DiffusionPipeline.from_pretrained(
"Tongyi-MAI/Z-Image-Turbo",
low_cpu_mem_usage=False,
)
pipe = pipe.to(device)
print("Pipeline loaded!")
# ================== IMAGE GENERATION ==================
def generate_image(
prompt,
height,
width,
num_inference_steps,
seed,
randomize_seed,
progress=gr.Progress(track_tqdm=True),
):
if randomize_seed:
seed = torch.randint(0, 2**32 - 1, (1,)).item()
generator = torch.Generator(device).manual_seed(int(seed))
image = pipe(
prompt=prompt,
height=int(height),
width=int(width),
num_inference_steps=int(num_inference_steps),
guidance_scale=0.0,
generator=generator,
).images[0]
return image, seed
# ================== EXAMPLES ==================
examples = [
["Young Chinese woman in red Hanfu, intricate embroidery, neon lightning lamp floating above palm, cinematic lighting"],
["A majestic dragon soaring through clouds at sunset, fantasy art, ultra detailed"],
["Cozy coffee shop interior, rain on windows, warm light, photorealistic"],
["Astronaut riding a horse on Mars, cinematic sci-fi concept art"],
["Portrait of an old wizard with glowing staff, magical forest"],
]
# ================== THEME ==================
custom_theme = gr.themes.Soft(
primary_hue="yellow",
secondary_hue="amber",
neutral_hue="slate",
font=gr.themes.GoogleFont("Inter"),
text_size="lg",
spacing_size="md",
radius_size="lg",
)
# ================== UI ==================
with gr.Blocks(fill_height=True, theme=custom_theme) as demo:
gr.Markdown(
"""
# 🤖 Burak Image
**Ultra-fast AI image generation** • CPU / GPU Auto
"""
)
with gr.Row():
with gr.Column(scale=1, min_width=320):
prompt = gr.Textbox(
label="✨ Prompt",
placeholder="Describe the image you want...",
lines=5,
)
with gr.Accordion("⚙️ Advanced Settings", open=False):
with gr.Row():
height = gr.Slider(512, 2048, 1024, step=64, label="Height")
width = gr.Slider(512, 2048, 1024, step=64, label="Width")
num_inference_steps = gr.Slider(
1, 20, 9, step=1, label="Inference Steps"
)
randomize_seed = gr.Checkbox(
label="🎲 Random Seed", value=True
)
seed = gr.Number(
label="Seed", value=42, precision=0, visible=False
)
randomize_seed.change(
lambda x: gr.Number(visible=not x),
randomize_seed,
seed,
)
generate_btn = gr.Button(
"🚀 Generate Image",
variant="primary",
size="lg",
)
gr.Examples(
examples=examples,
inputs=[prompt],
label="💡 Example Prompts",
)
with gr.Column(scale=1, min_width=320):
output_image = gr.Image(
label="Generated Image",
type="pil",
height=600,
buttons=["download", "share"],
)
used_seed = gr.Number(
label="🎲 Seed Used",
interactive=False,
)
generate_btn.click(
generate_image,
inputs=[prompt, height, width, num_inference_steps, seed, randomize_seed],
outputs=[output_image, used_seed],
)
prompt.submit(
generate_image,
inputs=[prompt, height, width, num_inference_steps, seed, randomize_seed],
outputs=[output_image, used_seed],
)
# ================== LAUNCH ==================
if __name__ == "__main__":
demo.launch()
|