Spaces:
Rforfth4
/
Runtime error

File size: 2,319 Bytes
f8a748e
7f48662
 
1876385
f8a748e
1876385
f8a748e
7f48662
f8a748e
7f48662
84db7c2
f8a748e
7f48662
1876385
7f48662
 
 
 
 
 
f8a748e
7f48662
 
 
f8a748e
7f48662
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8a748e
 
7f48662
 
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
import gradio as gr
from PIL import Image
import os
import spaces

# os.environ['CUDA_VISIBLE_DEVICES'] = '7'

from OmniGen import OmniGenPipeline

pipe = OmniGenPipeline.from_pretrained("shitao/tmp-preview")
# pipe.to("cuda")

# ็คบไพ‹ๅค„็†ๅ‡ฝๆ•ฐ๏ผš็”Ÿๆˆๅ›พๅƒ
@spaces.GPU
def generate_image(text, img1, img2, img3, height, width, guidance_scale):
    input_images = [img1, img2, img3]
    # ๅŽป้™ค None
    input_images = [img for img in input_images if img is not None]
    if len(input_images) == 0:
        input_images = None

    output = pipe(
        prompt=text,
        input_images=input_images,
        height=height,
        width=width,
        guidance_scale=guidance_scale, 
        img_guidance_scale=1.6,
        separate_cfg_infer=True,
        use_kv_cache=False
    )
    img = output[0]
    return img

# Gradio ๆŽฅๅฃ
with gr.Blocks() as demo:
    gr.Markdown("## Text + Multiple Images to Image Generator")
    
    with gr.Row():
        with gr.Column():
            # ๆ–‡ๆœฌ่พ“ๅ…ฅๆก†
            prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Type your prompt here...")
            
            # ๅ›พ็‰‡ไธŠไผ ๆก†
            image_input_1 = gr.Image(label="<img><|image_1|></img>", type="filepath")
            image_input_2 = gr.Image(label="<img><|image_2|></img>", type="filepath")
            image_input_3 = gr.Image(label="<img><|image_3|></img>", type="filepath")
            
            # ้ซ˜ๅบฆๅ’Œๅฎฝๅบฆๆป‘ๅ—
            height_input = gr.Slider(label="Height", minimum=256, maximum=2048, value=1024, step=16)
            width_input = gr.Slider(label="Width", minimum=256, maximum=2048, value=1024, step=16)
            
            # ๅผ•ๅฏผๅฐบๅบฆ่พ“ๅ…ฅ
            guidance_scale_input = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, value=3.0, step=0.1)
            
            # ็”ŸๆˆๆŒ‰้’ฎ
            generate_button = gr.Button("Generate Image")
        
        with gr.Column():
            # ่พ“ๅ‡บๅ›พๅƒๆก†
            output_image = gr.Image(label="Output Image")

    # ๆŒ‰้’ฎ็‚นๅ‡ปไบ‹ไปถ
    generate_button.click(
        generate_image,
        inputs=[prompt_input, image_input_1, image_input_2, image_input_3, height_input, width_input, guidance_scale_input],
        outputs=output_image
    )

# ๅฏๅŠจๅบ”็”จ
demo.launch()