| import torch |
| from diffusers import StableDiffusionPipeline |
| import gradio as gr |
|
|
| model_id = "stabilityai/stable-diffusion-2-1" |
| lora_id = "cocktailpeanut/itojunjilora" |
|
|
| |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) |
| pipe.to("cuda") |
|
|
| |
| pipe.load_lora_weights(lora_id) |
| pipe.fuse_lora() |
|
|
| |
| def generate_image(prompt): |
| image = pipe(prompt).images[0] |
| return image |
|
|
| |
| interface = gr.Interface( |
| fn=generate_image, |
| inputs=gr.Textbox(label="Prompt"), |
| outputs=gr.Image(label="Generated Image"), |
| title="LoRA Stable Diffusion", |
| description="Nháºp mô tả hình ảnh để tạo ra vá»›i LoRA." |
| ) |
|
|
| interface.launch() |
|
|