37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from diffusers.models import AutoencoderKL
|
|
from diffusers import StableDiffusionPipeline
|
|
import gradio as gr
|
|
from gradio.themes.utils import sizes
|
|
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
|
block_label_text_color = '#4D63FF',
|
|
block_title_text_color = '#4D63FF',
|
|
button_primary_text_color = '#4D63FF',
|
|
button_primary_background_fill='#FFFFFF',
|
|
button_primary_border_color='#4D63FF',
|
|
button_primary_background_fill_hover='#EDEFFF',
|
|
)
|
|
|
|
|
|
model = "CompVis/stable-diffusion-v1-4"
|
|
vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse")
|
|
pipe = StableDiffusionPipeline.from_pretrained(model, vae=vae)
|
|
|
|
def text2image(prompt):
|
|
image = pipe(prompt).images[0]
|
|
|
|
return image
|
|
|
|
|
|
demo = gr.Interface(fn=text2image,
|
|
inputs='text',
|
|
outputs='image',
|
|
theme = theme,
|
|
css = "footer {visibility: hidden}",
|
|
allow_flagging = "never",
|
|
examples = ['a photo of an astronaut riding a horse on mars'])
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
demo.queue(concurrency_count=10).launch(server_name = "0.0.0.0")
|