File size: 619 Bytes
7ae9ffe
 
 
6ab683a
 
7ae9ffe
6ab683a
 
 
 
 
7ae9ffe
 
6ab683a
7ae9ffe
 
6ab683a
 
 
 
7ae9ffe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


import gradio as gr
import torch
from diffusers import StableDiffusionPipeline

# Load the model (make sure to run this only if GPU available or set to CPU explicitly)
model_id = "CompVis/stable-diffusion-v1-4"

pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
pipe = pipe.to("cpu")  # or "cuda" if GPU available

def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

gr.Interface(fn=generate_image,
             inputs=gr.Textbox(label="Enter a prompt"),
             outputs=gr.Image(type="pil"),
             title="Text to Image Generator").launch()