Spaces:
Runtime error
Runtime error
File size: 768 Bytes
7a57063 2b8e7f7 7a57063 2b8e7f7 7a57063 2b8e7f7 7a57063 2b8e7f7 |
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 |
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline
# Load the Stable Diffusion model from Hugging Face
model_id = "stabilityai/stable-diffusion-3.5-large"
device = "cuda" if torch.cuda.is_available() else "cpu"
# Initialize the pipeline
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to(device)
# Define a function to generate images
def generate_image(prompt):
with torch.autocast(device):
image = pipe(prompt).images[0]
return image
# Set up the Gradio interface
interface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="Enter your prompt"),
outputs=gr.Image(label="Generated Image"),
title="Stable Diffusion 3.5 Demo"
)
interface.launch()
|