parasmech's picture
Update app.py
52ca3ee verified
raw
history blame contribute delete
780 Bytes
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()