File size: 4,283 Bytes
e10f7f0
 
 
 
fb0b46c
d802916
fb0b46c
4aff4c5
 
fb0b46c
a61bba9
e10f7f0
 
 
 
a9609d3
24f485a
43fff5f
5fa19cb
e10f7f0
43fff5f
 
 
 
5fa19cb
43fff5f
e10f7f0
43fff5f
 
 
 
 
 
 
 
 
 
e10f7f0
43fff5f
 
 
 
 
 
 
 
 
 
 
 
 
 
e10f7f0
 
9523e15
e10f7f0
 
9523e15
e10f7f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d7199f
 
 
e10f7f0
 
 
 
 
 
 
 
9ca7096
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
import gradio as gr
import numpy as np
from PIL import Image
import openvino_genai as ov_genai
import subprocess, sys
import os
subprocess.run([sys.executable, "download_models.py"], check=True)

# Core count

BACKEND = os.environ.get("BACKEND", "genai")  # "optimum" or "genai"

MODEL_PATH = "LCM_Dreamshaper_v7-int8-ov"
DEVICE = "CPU"



if BACKEND == "optimum":
    from optimum.intel import OVDiffusionPipeline

    print("Loading with Optimum-Intel...")
    pipe =  OVDiffusionPipeline.from_pretrained(
        MODEL_PATH,
        device=DEVICE,
        safety_checker=None
    )

    def generate(prompt, negative_prompt, num_steps, guidance_scale, seed):
        generator = np.random.RandomState(seed if seed != -1 else None)
        result = pipe(
            prompt=prompt,
            negative_prompt=negative_prompt or None,
            num_inference_steps=num_steps,
            guidance_scale=guidance_scale,
            generator=generator,
        )
        return result.images[0]

else:
    import openvino_genai as ov_genai
    print("Loading with OpenVINO GenAI...")
    pipe = ov_genai.Text2ImagePipeline(MODEL_PATH, DEVICE)

    def generate(prompt, negative_prompt, num_steps, guidance_scale, seed):
        actual_seed = seed if seed != -1 else np.random.randint(0, 2**31)
        image_tensor = pipe.generate(
            prompt,
            num_inference_steps=num_steps,
            guidance_scale=guidance_scale,
            rng_seed=actual_seed,
        )
        return Image.fromarray(np.array(image_tensor.data[0]))


with gr.Blocks(title="SD1.5 3d interior design – OpenVINO") as demo:
    gr.Markdown(
        """
        # 🏠 SD1.5 Interior LoRA + LCM-style Model— OpenVINO INT8
        Fast CPU inference with Latent Consistency Model.  
        4 steps is usually enough — crank it to 8 for more detail.
        """
    )

    with gr.Row():
        with gr.Column(scale=1):
            prompt = gr.Textbox(
                label="Prompt",
                placeholder="photo, full body man, cinematic lighting...",
                lines=3,
            )
            negative_prompt = gr.Textbox(
                label="Negative Prompt",
                placeholder="blurry, low quality, watermark...",
                lines=2,
                value="blurry, low quality, artifacts, watermark",
            )
            with gr.Row():
                num_steps = gr.Slider(
                    label="Inference Steps",
                    minimum=1,
                    maximum=16,
                    value=4,
                    step=1,
                )
                guidance_scale = gr.Slider(
                    label="Guidance Scale",
                    minimum=0.0,
                    maximum=3.0,
                    value=0.8,
                    step=0.1,
                )
            seed = gr.Number(
                label="Seed (-1 = random)",
                value=-1,
                precision=0,
            )
            btn = gr.Button("Generate", variant="primary")

        with gr.Column(scale=1):
            output = gr.Image(label="Generated Image", type="pil")

    btn.click(
        fn=generate,
        inputs=[prompt, negative_prompt, num_steps, guidance_scale, seed],
        outputs=output,
    )

    gr.Examples(
        examples=[
            ["isometric ,3d render,interior a living room with a couch, chair, table and clock,indoors, book, pillow, no humans, window, bed, chair, table, plant, curtains, scenery, couch, wooden floor, clock, lamp, alarm clock","blurry, low quality", 4, 1.0, 42],
            ["isometric ,3d render,interior a bedroom with a bed, desk and computer monitor in a neon frame,book, pillow, no humans, window, bed, night, chair, plant, scenery, desk, lamp, computer, monitor","blurry, low quality", 8, 1.0, 7],
            ["isometric ,3d render,interior a small kitchen with a table and chairs,food, indoors, no humans, window, chair, table, bottle, scenery, plate, kitchen, frying pan, sink, rug, stove, cutting board","blurry, low quality", 8, 0.8, 123],
        ],
        inputs=[prompt, negative_prompt, num_steps, guidance_scale, seed],
        outputs=output,
        fn=generate,
        cache_examples=False,
    )

if __name__ == "__main__":
    demo.launch()