Spaces:
Paused
Paused
File size: 1,803 Bytes
0541a7c 1629b71 0541a7c 1629b71 0541a7c 23a6378 0541a7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import gradio as gr
import spaces
from diffusers import StableDiffusionPipeline, AutoencoderKL
import os
import torch
from PIL import Image
import random
# SAFETY_CHECKER = os.environ.get("SAFETY_CHECKER", "0") == "1"
# Constants
repo = "IDKiro/sdxs-512-0.9"
# Ensure model and scheduler are initialized in GPU-enabled function
if torch.cuda.is_available():
weight_type = torch.float32
pipe = StableDiffusionPipeline.from_pretrained(repo, torch_dtype=weight_type)
# pipe.vae = AutoencoderKL.from_pretrained("IDKiro/sdxs-512-0.9/vae_large") # use original VAE
pipe.to("cuda")
# Function
@spaces.GPU(enable_queue=True)
def generate_image(prompt):
seed = random.randint(-100000,100000)
results = pipe(
prompt,
num_inference_steps=1,
guidance_scale=0,
generator=torch.Generator(device="cuda").manual_seed(seed)
)
return results.images[0]
# Gradio Interface
description = """
This demo utilizes the SDXS model
"""
with gr.Blocks(css="style.css") as demo:
gr.HTML("<h1><center>Text-to-Image with SDXS (sdxs-512-0.9) ⚡</center></h1>")
gr.Markdown(description)
with gr.Group():
with gr.Row():
prompt = gr.Textbox(label='Enter your prompt (English)', scale=8, value="portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour")
submit = gr.Button(scale=1, variant='primary')
img = gr.Image(label='SDXS Generated Image')
prompt.submit(fn=generate_image,
inputs=[prompt],
outputs=img,
)
submit.click(fn=generate_image,
inputs=[prompt],
outputs=img,
)
demo.queue().launch() |