import gradio as gr
from diffusers import StableDiffusionPipeline
import torch


model_id = "CompVis/stable-diffusion-v1-4"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")


def text2image(prompt):
    image = pipe(prompt).images[0]

    return image


demo = gr.Interface(fn=text2image,
                    inputs='text',
                    outputs='image',
                    title = "text2image",
                    examples = ['a photo of an astronaut riding a horse on mars'])


if __name__ == "__main__":
    demo.queue(concurrency_count=3).launch(server_name = "0.0.0.0", server_port = 7014)
