| import os |
| import torch |
| from diffusers import StableDiffusionPipeline |
| import gradio as gr |
|
|
| |
| os.environ["HF_HOME"] = "/tmp" |
|
|
| |
| model_id = "stabilityai/sd-turbo" |
|
|
| |
| pipe = StableDiffusionPipeline.from_pretrained( |
| model_id, |
| torch_dtype=torch.float16 |
| ) |
| pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
| def generate(prompt): |
| image = pipe(prompt).images[0] |
| return image |
|
|
| |
| iface = gr.Interface( |
| fn=generate, |
| inputs=gr.Textbox(label="Enter your prompt"), |
| outputs=gr.Image(type="pil"), |
| title="Stable Diffusion Demo", |
| description="Enter a text prompt and generate an AI image!" |
| ) |
|
|
| iface.launch() |
|
|