Spaces:
Runtime error
Runtime error
File size: 2,988 Bytes
2150dbe cc36806 d9cf71a 2150dbe d9cf71a 2150dbe d9cf71a 2150dbe 435eeff 2150dbe d9cf71a 2150dbe 435eeff e2419ee cb9bbbd b9ba013 cb9bbbd 870ee21 b96e226 6d90bf4 870ee21 f8d1449 1e7407e 6d90bf4 6c907be 43b249a 6d90bf4 43b249a 6d90bf4 43b249a 6c907be 435eeff 91cc668 b9ba013 91cc668 435eeff 4f44913 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 98 99 100 101 102 103 104 |
"""
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(
"""
# Your own Stable Diffusion on Google Cloud Platform
""")
with gr.Row():
gcp_project_id = gr.Textbox(
label="GCP project ID",
)
gcp_region = gr.Dropdown(
["us-central1", "asia‑east1", "asia-northeast1"],
value="us-central1",
interactive=True,
label="GCP Region"
)
gr.Markdown(
"""
Configurations on scalability
""")
with gr.Row():
min_nodes = gr.Slider(
label="minimum number of nodes",
minimum=1,
maximum=10)
max_nodes = gr.Slider(
label="maximum number of nodes",
minimum=1,
maximum=10)
btn = gr.Button(value="Ready to Deploy!")
# btn.click(mirror, inputs=[im], outputs=[im_2])
with gr.Blocks() as demo2:
gr.Markdown(
"""
# Your own Stable Diffusion on Hugging Face 🤗 Endpoint
""")
gr.TabbedInterface(
[demoInterface, demo, demo2], ["Try-out", "🚀 Deploy on GCP", " Deploy on 🤗 Endpoint"]
).launch(enable_queue=True) |