|
|
import torch |
|
|
from diffusers import StableDiffusionPipeline |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
model_id = "runwayml/stable-diffusion-v1-5" |
|
|
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) |
|
|
pipe.to("cuda") |
|
|
|
|
|
|
|
|
def generate_image(prompt): |
|
|
image = pipe(prompt).images[0] |
|
|
return image |
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=generate_image, |
|
|
inputs="text", |
|
|
outputs="image", |
|
|
title="Text-to-Image Generator", |
|
|
description="Enter a text prompt to generate an image using Stable Diffusion." |
|
|
) |
|
|
|
|
|
|
|
|
interface.launch() |
|
|
|