|
|
import banana_dev as banana |
|
|
import base64 |
|
|
from io import BytesIO |
|
|
from PIL import Image |
|
|
import gradio as gr |
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model_inputs = { |
|
|
"endpoint": "txt2img", |
|
|
"params": { |
|
|
"prompt": "", |
|
|
"negative_prompt": "", |
|
|
"steps": 25, |
|
|
"sampler_name": "Euler a", |
|
|
"cfg_scale": 7.5, |
|
|
"seed": 42, |
|
|
"batch_size": 1, |
|
|
"n_iter": 1, |
|
|
"width": 768, |
|
|
"height": 768, |
|
|
"tiling": False |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stable_diffusion_txt2img(prompt, api_key, model_key, model_inputs): |
|
|
|
|
|
model_inputs["params"]["prompt"] = prompt |
|
|
|
|
|
|
|
|
out = banana.run(api_key, model_key, model_inputs) |
|
|
|
|
|
|
|
|
image_byte_string = out["modelOutputs"][0]["images"] |
|
|
image_encoded = image_byte_string[0].encode("utf-8") |
|
|
image_bytes = BytesIO(base64.b64decode(image_encoded)) |
|
|
image = Image.open(image_bytes) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return image |
|
|
|
|
|
|
|
|
def generator(prompt): |
|
|
return stable_diffusion_txt2img(prompt, api_key, model_key, model_inputs), stable_diffusion_txt2img(prompt, api_key, model_key, model_inputs) |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
prompt = gr.Textbox(label="Prompt") |
|
|
submit = gr.Button(label="Generate") |
|
|
image1 = gr.Image() |
|
|
image2 = gr.Image() |
|
|
|
|
|
submit.click(generator, inputs=[prompt], outputs=[image1, image2], api_name="mmsd") |
|
|
|
|
|
demo.launch() |
|
|
|