File size: 780 Bytes
0899ac5
 
 
 
 
 
 
6d26283
 
0899ac5
 
 
6d26283
0899ac5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52ca3ee
 
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
29
30
31
32
import torch
from diffusers import StableDiffusionPipeline
import gradio as gr


model_id = "stabilityai/stable-diffusion-2-1"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
#pipe = pipe.to("cuda")
pipe = pipe.to("cpu")


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


title = " Image Generator"
description = """
This app generates images based on text prompts using the Stable Diffusion model.
"""

interface = gr.Interface(
    fn=generate_image,
    inputs=gr.Textbox(label="Enter your text prompt", placeholder="Describe the image you want to generate"),
    outputs=gr.Image(label="Generated Image"),
    title=title,
    description=description,
)

if __name__ == "__main__":
    interface.launch()