Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from optimum.intel import OVZImagePipeline
|
| 4 |
+
|
| 5 |
+
# ===== Load model (only once) =====
|
| 6 |
+
pipe = OVZImagePipeline.from_pretrained(
|
| 7 |
+
"hsuwill000/Z-Image-Turbo-ov",
|
| 8 |
+
device="cpu"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# ===== Inference function =====
|
| 12 |
+
def generate_image(prompt, height, width, steps, seed):
|
| 13 |
+
if seed == -1:
|
| 14 |
+
generator = torch.Generator("cpu")
|
| 15 |
+
else:
|
| 16 |
+
generator = torch.Generator("cpu").manual_seed(int(seed))
|
| 17 |
+
|
| 18 |
+
image = pipe(
|
| 19 |
+
prompt=prompt,
|
| 20 |
+
height=int(height),
|
| 21 |
+
width=int(width),
|
| 22 |
+
num_inference_steps=int(steps),
|
| 23 |
+
guidance_scale=0.0, # Turbo 必須 0
|
| 24 |
+
generator=generator,
|
| 25 |
+
).images[0]
|
| 26 |
+
|
| 27 |
+
return image
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# ===== Default prompt =====
|
| 31 |
+
default_prompt = """Cinematic portrait of a Japanese girl as Shinobu Kocho, realistic facial features, gradient purple compound eyes, intricate butterfly hair ornament, wearing silk haori with butterfly wing patterns, soft moonlight, hyper-realistic, depth of field, purple butterfly particles, 8k resolution, ethereal lighting"""
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# ===== Gradio UI =====
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown("# 🚀 Z-Image Turbo (OpenVINO CPU)")
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
with gr.Column():
|
| 40 |
+
prompt = gr.Textbox(label="Prompt", value=default_prompt, lines=5)
|
| 41 |
+
|
| 42 |
+
height = gr.Slider(256, 1024, value=512, step=64, label="Height")
|
| 43 |
+
width = gr.Slider(256, 1024, value=512, step=64, label="Width")
|
| 44 |
+
|
| 45 |
+
steps = gr.Slider(1, 20, value=9, step=1, label="Inference Steps")
|
| 46 |
+
seed = gr.Number(value=-1, label="Seed (-1 = random)")
|
| 47 |
+
|
| 48 |
+
run_btn = gr.Button("Generate")
|
| 49 |
+
|
| 50 |
+
with gr.Column():
|
| 51 |
+
output = gr.Image(label="Generated Image")
|
| 52 |
+
|
| 53 |
+
run_btn.click(
|
| 54 |
+
fn=generate_image,
|
| 55 |
+
inputs=[prompt, height, width, steps, seed],
|
| 56 |
+
outputs=output,
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# ===== Launch =====
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
demo.launch()
|