File size: 1,920 Bytes
886a968
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
from pathlib import Path

from PIL import Image

root = Path(os.path.dirname(__file__))

def infer(
    text,
    guidance_scale,
):

    img = (
        Image.open(root / "cheetah.jpg")
        if text == "Cheetah"
        else Image.open(root / "frog.jpg")
    )
    img = img.resize((224, 224))

    return ([img, img, img, img], "image")

block = gr.Blocks()

examples = [
    ["A serious capybara at work, wearing a suit", 7],
    ["A Squirtle fine dining with a view to the London Eye", 7],
    ["A tamale food cart in front of a Japanese Castle", 7],
    ["a graffiti of a robot serving meals to people", 7],
    ["a beautiful cabin in Attersee, Austria, 3d animation style", 7],
]

with block as demo:
    with gr.Row(elem_id="prompt-container", equal_height=True):
        text = gr.Textbox(
            label="Enter your prompt",
            show_label=False,
            max_lines=1,
            placeholder="Enter your prompt",
            elem_id="prompt-text-input",
        )

    gallery = gr.Gallery(
        label="Generated images", show_label=False, elem_id="gallery", rows=2, columns=2
    )
    out_txt = gr.Textbox(
        label="Prompt",
        placeholder="Enter a prompt to generate an image",
        lines=3,
        elem_id="prompt-text-input",
    )

    guidance_scale = gr.Slider(
        label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
    )

    ex = gr.Examples(
        examples=examples,
        fn=infer,
        inputs=[text, guidance_scale],
        outputs=[gallery, out_txt],
        cache_examples=True,
    )

    text.submit(
        infer,
        inputs=[text, guidance_scale],
        outputs=[gallery, out_txt],
        concurrency_id="infer",
        concurrency_limit=8,
    )

with gr.Blocks() as demo:
    block.render()

if __name__ == "__main__":
    demo.queue(max_size=10, api_open=False).launch(show_api=False)