Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,30 @@
|
|
| 1 |
import torch
|
| 2 |
-
import gradio as gr
|
| 3 |
from diffusers import StableDiffusionPipeline
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 8 |
-
pipeline.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return image
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
gr.Markdown("Nhập mô tả để tạo ảnh theo phong cách kinh dị của Junji Ito!")
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
guidance_scale = gr.Slider(1, 10, value=7.5, step=0.1, label="Guidance Scale")
|
| 25 |
-
btn = gr.Button("Generate Image")
|
| 26 |
-
with gr.Column():
|
| 27 |
-
output_image = gr.Image(label="Generated Image")
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
if __name__ == "__main__":
|
| 33 |
-
demo.launch()
|
|
|
|
| 1 |
import torch
|
|
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
model_id = "stabilityai/stable-diffusion-2-1"
|
| 6 |
+
lora_id = "cocktailpeanut/itojunjilora"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Load Stable Diffusion
|
| 9 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 10 |
+
pipe.to("cuda")
|
|
|
|
| 11 |
|
| 12 |
+
# Load LoRA
|
| 13 |
+
pipe.load_lora_weights(lora_id)
|
| 14 |
+
pipe.fuse_lora()
|
|
|
|
| 15 |
|
| 16 |
+
# Function to generate image
|
| 17 |
+
def generate_image(prompt):
|
| 18 |
+
image = pipe(prompt).images[0]
|
| 19 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Gradio UI
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=generate_image,
|
| 24 |
+
inputs=gr.Textbox(label="Prompt"),
|
| 25 |
+
outputs=gr.Image(label="Generated Image"),
|
| 26 |
+
title="LoRA Stable Diffusion",
|
| 27 |
+
description="Nhập mô tả hình ảnh để tạo ra với LoRA."
|
| 28 |
+
)
|
| 29 |
|
| 30 |
+
interface.launch()
|
|
|
|
|
|