| import gradio as gr |
| from diffusers import StableDiffusionPipeline |
| import torch |
|
|
| from transformers import logging |
| logging.set_verbosity_error() |
| |
| from diffusers import StableDiffusionPipeline |
|
|
| |
| model_id = "ImageInception/stable-diffusion-finetuned" |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) |
|
|
| |
| device = "cuda" if torch.cuda.is_available() else "cpu" |
| pipe.to(device) |
|
|
| print(f"Using device: {device}") |
|
|
|
|
| |
| def generate_image(prompt): |
| image = pipe(prompt).images[0] |
| return image |
|
|
| |
| interface = gr.Interface( |
| fn=generate_image, |
| inputs=gr.Textbox(label="Enter your prompt"), |
| outputs=gr.Image(label="Generated Image"), |
| ) |
|
|
| |
| interface.launch() |
|
|