parasmech's picture
main file updated
0899ac5 verified
raw
history blame
756 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")
def generate_image(prompt):
with torch.autocast("cuda"):
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,
)
gr.launch()