Very fast streamlit demo

#11
by macadeliccc - opened

This demo is pretty self explanatory but I figured I would just submit this here rather than a pull request seeing as they have a demo provided.

However, if you do not want to use the provided interface or just want to test it very quickly here is this streamlit script:

import streamlit as st
from diffusers import AutoPipelineForText2Image
import torch
import os
import time
import random

st.title("SDXL Turbo")

if not os.path.exists('outputs'):
    os.makedirs('outputs')



@st

	.cache_resource
def load_model():
    device = "cuda" if torch.cuda.is_available() else "cpu"
    pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16").to(device)
    return pipe

pipe = load_model()

prompt = st.sidebar.text_area("Enter a prompt:", "A cinematic shot of a baby raccoon wearing an intricate Italian priest robe.", height=1)
num_inference_steps = st.sidebar.slider("Number of inference steps", 1, 10, 1)
guidance_scale = st.sidebar.slider("Guidance scale", 0.0, 2.0, 0.0)

if st.sidebar.button('Generate Image'):
    with st.spinner('Generating image...'):
        # Generate the image
        image = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale).images[0]

        # Generate a unique filename
        timestamp = int(time.time())
        random_number = random.randint(0, 99999)
        filename = f"outputs/image_{timestamp}_{random_number}.png"

        # Save the image
        image.save(filename)

        # Display the image
        st.image(filename, caption='Generated Image')

Sign up or log in to comment