import torch import spaces import gradio as gr from diffusers import StableDiffusionPipeline repo = "Tramac/style-portrait-v1-5" # Ensure model and scheduler are initialized in GPU-enabled function if torch.cuda.is_available(): pipeline = StableDiffusionPipeline.from_pretrained( repo, torch_dtype=torch.float16, variant="fp16" ).to("cuda") @spaces.GPU(enable_queue=True) def generate_image(prompt, neg_prompt): results = pipeline( prompt=prompt, negative_prompt=neg_prompt, height=832, width=512, num_inference_steps=20, ) return results.images[0] with gr.Blocks() as demo: gr.HTML("