File size: 595 Bytes
22e1d99
390b720
 
22e1d99
390b720
22e1d99
390b720
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline

model_id = "runwayml/stable-diffusion-v1-5"

pipe = StableDiffusionPipeline.from_pretrained(
    model_id,
    torch_dtype=torch.float32
)
pipe = pipe.to("cpu")

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

interface = gr.Interface(
    fn=generate_image,
    inputs=gr.Textbox(label="Enter text prompt"),
    outputs=gr.Image(label="Generated Image"),
    title="Text to Image Generator",
    description="Generate images from text using Stable Diffusion"
)

interface.launch()