Update app.py
Browse files
app.py
CHANGED
@@ -3,15 +3,18 @@ import torch
|
|
3 |
from diffusers import StableDiffusion3Pipeline
|
4 |
import os
|
5 |
from huggingface_hub import login
|
|
|
|
|
6 |
hf_token = os.environ.get("HF_TOKEN")
|
7 |
login(token=hf_token)
|
8 |
|
9 |
-
|
10 |
# 加载模型并配置
|
11 |
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
|
12 |
pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Photorealistic-LoRA", weight_name="Photorealistic-SD3.5-Large-LoRA.safetensors")
|
13 |
pipe.fuse_lora(lora_scale=1.0)
|
14 |
-
|
|
|
|
|
15 |
|
16 |
# 定义图像生成函数,添加种子参数
|
17 |
def generate_image(prompt, seed):
|
@@ -42,7 +45,7 @@ with gr.Blocks() as demo:
|
|
42 |
|
43 |
# 按钮触发事件
|
44 |
generate_btn = gr.Button("Generate Image")
|
45 |
-
generate_btn.click(generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
|
46 |
|
47 |
# 启动Gradio应用
|
48 |
demo.launch()
|
|
|
3 |
from diffusers import StableDiffusion3Pipeline
|
4 |
import os
|
5 |
from huggingface_hub import login
|
6 |
+
|
7 |
+
# 获取Hugging Face Token
|
8 |
hf_token = os.environ.get("HF_TOKEN")
|
9 |
login(token=hf_token)
|
10 |
|
|
|
11 |
# 加载模型并配置
|
12 |
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
|
13 |
pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Photorealistic-LoRA", weight_name="Photorealistic-SD3.5-Large-LoRA.safetensors")
|
14 |
pipe.fuse_lora(lora_scale=1.0)
|
15 |
+
|
16 |
+
# 如果有GPU,转移到GPU
|
17 |
+
pipe.to("cuda")
|
18 |
|
19 |
# 定义图像生成函数,添加种子参数
|
20 |
def generate_image(prompt, seed):
|
|
|
45 |
|
46 |
# 按钮触发事件
|
47 |
generate_btn = gr.Button("Generate Image")
|
48 |
+
generate_btn.click(fn=generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
|
49 |
|
50 |
# 启动Gradio应用
|
51 |
demo.launch()
|