File size: 639 Bytes
19f9a8b
4398c5e
 
 
 
 
 
 
19f9a8b
 
 
4398c5e
 
 
 
 
19f9a8b
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Replace ALL code with this updated version
from diffusers import StableDiffusionPipeline
import torch
import random

def generate_image(prompt):
    pipe = StableDiffusionPipeline.from_pretrained(
        "stabilityai/stable-diffusion-2-1",
        torch_dtype=torch.float16,
        use_safetensors=True,  # Add this
        variant="fp16"         # Add this
    )
    
    seed = random.randint(0, 1000000)
    generator = torch.Generator().manual_seed(seed)
    
    image = pipe(
        prompt,
        generator=generator,
        num_inference_steps=25
    ).images[0]
    return image

# Rest of your Gradio code remains the same