|
import gradio as gr |
|
import random |
|
import os |
|
import io, base64 |
|
from PIL import Image |
|
import numpy |
|
import shortuuid |
|
|
|
latent = gr.Interface.load("spaces/multimodalart/latentdiffusion") |
|
rudalle = gr.Interface.load("spaces/multimodalart/rudalle") |
|
|
|
|
|
|
|
|
|
def text2image_latent(text,steps,width,height,images,diversity): |
|
results = latent(text, steps, width, height, images, diversity) |
|
image_paths = [] |
|
image_arrays = [] |
|
for image in results[1]: |
|
image_str = image[0] |
|
image_str = image_str.replace("data:image/png;base64,","") |
|
decoded_bytes = base64.decodebytes(bytes(image_str, "utf-8")) |
|
img = Image.open(io.BytesIO(decoded_bytes)) |
|
|
|
url = shortuuid.uuid() |
|
temp_dir = './tmp' |
|
if not os.path.exists(temp_dir): |
|
os.makedirs(temp_dir, exist_ok=True) |
|
image_path = f'{temp_dir}/{url}.png' |
|
img.save(f'{temp_dir}/{url}.png') |
|
image_paths.append(image_path) |
|
return(results[0],image_paths) |
|
|
|
def text2image_rudalle(text,aspect,model): |
|
image = rudalle(text,aspect,model)[0] |
|
return(image) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css_mt = {"margin-top": "1em"} |
|
|
|
empty = gr.outputs.HTML() |
|
mindseye = gr.Blocks() |
|
|
|
with mindseye: |
|
gr.Markdown("<h1>MindsEye Lite <small><small>run multiple text-to-image models in one place</small></small></h1><p>MindsEye Lite orchestrates multiple text-to-image Hugging Face Spaces in one convenient space, so you can try different models. This work carries the spirit of <a href='https://multimodal.art/mindseye' target='_blank'>MindsEye Beta</a>, a tool to run multiple models with a single UI, but adjusted to the current hardware limitations of Spaces. MindsEye Lite was created by <a style='color: rgb(99, 102, 241);font-weight:bold' href='https://twitter.com/multimodalart' target='_blank'>@multimodalart</a>, keep up with the <a style='color: rgb(99, 102, 241);' href='https://multimodal.art/news' target='_blank'>latest multimodal ai art news here</a> and consider <a style='color: rgb(99, 102, 241);' href='https://www.patreon.com/multimodalart' target='_blank'>supporting us on Patreon</a></div></p>") |
|
|
|
text = gr.inputs.Textbox(placeholder="Try writing something..", label="Prompt", default="A mecha robot in a favela") |
|
|
|
with gr.Column(): |
|
with gr.Row(): |
|
with gr.Tabs(): |
|
with gr.TabItem("Latent Diffusion"): |
|
steps = gr.inputs.Slider(label="Steps - more steps can increase quality but will take longer to generate",default=45,maximum=50,minimum=1,step=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mindseye.launch(share=False) |