Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
-
from
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
|
6 |
-
# 模型和 LoRA
|
7 |
base_model = "stabilityai/stable-diffusion-xl-base-1.0" # 基礎模型
|
8 |
-
|
|
|
9 |
|
10 |
# 嘗試加載到 GPU,如果不可用則回退到 CPU
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -15,8 +16,9 @@ dtype = torch.float16 if device == "cuda" else torch.float32
|
|
15 |
pipe = StableDiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype)
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
20 |
|
21 |
# 測試生成函數
|
22 |
def generate_image(prompt, width, height, steps, guidance_scale):
|
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
|
6 |
+
# 模型和 LoRA 存儲庫信息
|
7 |
base_model = "stabilityai/stable-diffusion-xl-base-1.0" # 基礎模型
|
8 |
+
repo_id = "hyder133/chiikawa_stype" # Hugging Face 存儲庫 ID
|
9 |
+
lora_filename = "tkw1.safetensors" # LoRA 權重文件名
|
10 |
|
11 |
# 嘗試加載到 GPU,如果不可用則回退到 CPU
|
12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
16 |
pipe = StableDiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype)
|
17 |
pipe = pipe.to(device)
|
18 |
|
19 |
+
# 下載並加載 LoRA 權重
|
20 |
+
lora_file_path = hf_hub_download(repo_id=repo_id, filename=lora_filename)
|
21 |
+
pipe.load_lora_weights(lora_file_path)
|
22 |
|
23 |
# 測試生成函數
|
24 |
def generate_image(prompt, width, height, steps, guidance_scale):
|