File size: 2,589 Bytes
2150dbe
 
 
 
 
 
 
 
 
 
 
 
 
 
cc36806
 
d9cf71a
 
2150dbe
d9cf71a
 
 
 
 
2150dbe
d9cf71a
 
2150dbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435eeff
2150dbe
 
 
 
 
 
 
 
 
 
d9cf71a
2150dbe
435eeff
 
e2419ee
 
 
cb9bbbd
 
 
 
 
 
6c907be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435eeff
 
cb9bbbd
2150dbe
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
"""
Adapted from https://huggingface.co/spaces/stabilityai/stable-diffusion
"""

from tensorflow import keras

import time

import gradio as gr
import keras_cv

from constants import css, examples, img_height, img_width, num_images_to_gen
from share_btn import community_icon_html, loading_icon_html, share_js

from huggingface_hub import from_pretrained_keras

# MODEL_CKPT = "chansung/textual-inversion-pipeline@v1673026791"
# MODEL = from_pretrained_keras(MODEL_CKPT)

# model = keras_cv.models.StableDiffusion(
#     img_width=img_width, img_height=img_height, jit_compile=True
# )
# model._text_encoder = MODEL
# model._text_encoder.compile(jit_compile=True)

# # Warm-up the model.
# _ = model.text_to_image("Teddy bear", batch_size=num_images_to_gen)

def generate_image_fn(prompt: str, unconditional_guidance_scale: int) -> list:
    start_time = time.time()
    # `images is an `np.ndarray`. So we convert it to a list of ndarrays.
    # Each ndarray represents a generated image.
    # Reference: https://gradio.app/docs/#gallery
    images = model.text_to_image(
        prompt,
        batch_size=num_images_to_gen,
        unconditional_guidance_scale=unconditional_guidance_scale,
    )
    end_time = time.time()
    print(f"Time taken: {end_time - start_time} seconds.")
    return [image for image in images]

demoInterface = gr.Interface(
    generate_image_fn,
    inputs=[
        gr.Textbox(
            label="Enter your prompt",
            max_lines=1,
#            placeholder="cute Sundar Pichai creature",
        ),
        gr.Slider(value=40, minimum=8, maximum=50, step=1),
    ],
    outputs=gr.Gallery().style(grid=[2], height="auto"),
    # examples=[["cute Sundar Pichai creature", 8], ["Hello kitty", 8]],
    allow_flagging=False,
)

def welcome(name):
    return f"Welcome to Gradio, {name}!"

with gr.Blocks() as demo:
    gr.Markdown(
    """
    # Hello World!
    Start typing below to see the output.
    """)

    gr.Markdown(
    """
    GCP project ID
    """)
    gcp_project_id = gr.Textbox()

    gr.Markdown(
    """
    GCP region
    """)
    gcp_region = gr.Textbox()

    gr.Markdown(
    """
    Minimum number of nodes?
    """)    
    min_nodes = gr.Slider(label="minimum number of nodes"),
    
    gr.Markdown(
    """
    Maximum number of nodes?
    """)    
    max_nodes = gr.Slider(label="maximum number of nodes"),
    
    btn = gr.Button(value="Ready to Deploy!")
    # btn.click(mirror, inputs=[im], outputs=[im_2])    

gr.TabbedInterface(
    [demoInterface, demo], ["Try-out", "Deployment"]
).launch(enable_queue=True)