Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 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 |
-
|
| 28 |
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
-
# ===== Gradio UI =====
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
-
gr.Markdown("# 🚀 Z-Image Turbo (
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
with gr.Column():
|
| 40 |
-
prompt = gr.Textbox(
|
| 41 |
|
| 42 |
-
height = gr.Slider(256, 1024, value=512, step=64
|
| 43 |
-
width = gr.Slider(256, 1024, value=512, step=64
|
| 44 |
|
| 45 |
-
steps = gr.Slider(1, 20, value=9, step=1
|
| 46 |
-
seed = gr.Number(value=-1
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
with gr.Column():
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
fn=
|
| 55 |
inputs=[prompt, height, width, steps, seed],
|
| 56 |
-
outputs=
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from inference import generate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
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, ethereal lighting"""
|
| 5 |
|
| 6 |
|
| 7 |
+
def ui_generate(prompt, height, width, steps, seed):
|
| 8 |
+
return generate(
|
| 9 |
+
prompt=prompt,
|
| 10 |
+
height=int(height),
|
| 11 |
+
width=int(width),
|
| 12 |
+
steps=int(steps),
|
| 13 |
+
seed=int(seed),
|
| 14 |
+
)
|
| 15 |
|
| 16 |
|
|
|
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown("## 🚀 Z-Image Turbo (Fast Mode)")
|
| 19 |
|
| 20 |
with gr.Row():
|
| 21 |
with gr.Column():
|
| 22 |
+
prompt = gr.Textbox(value=default_prompt, lines=4, label="Prompt")
|
| 23 |
|
| 24 |
+
height = gr.Slider(256, 1024, value=512, step=64)
|
| 25 |
+
width = gr.Slider(256, 1024, value=512, step=64)
|
| 26 |
|
| 27 |
+
steps = gr.Slider(1, 20, value=9, step=1)
|
| 28 |
+
seed = gr.Number(value=-1)
|
| 29 |
|
| 30 |
+
btn = gr.Button("Generate")
|
| 31 |
|
| 32 |
with gr.Column():
|
| 33 |
+
out = gr.Image()
|
| 34 |
|
| 35 |
+
btn.click(
|
| 36 |
+
fn=ui_generate,
|
| 37 |
inputs=[prompt, height, width, steps, seed],
|
| 38 |
+
outputs=out,
|
| 39 |
)
|
| 40 |
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
demo.queue()
|
| 44 |
+
|
| 45 |
if __name__ == "__main__":
|
| 46 |
demo.launch()
|