Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,26 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
# 加载模型并配置
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
def generate_image(prompt, seed):
|
9 |
-
#
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# 创建Gradio界面
|
14 |
with gr.Blocks() as demo:
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusion3Pipeline
|
4 |
|
5 |
# 加载模型并配置
|
6 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
|
7 |
+
pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Photorealistic-LoRA", weight_name="Photorealistic-SD3.5-Large-LoRA.safetensors")
|
8 |
+
pipe.fuse_lora(lora_scale=1.0)
|
9 |
+
# pipe.to("cuda")
|
10 |
|
11 |
+
# 定义图像生成函数,添加种子参数
|
12 |
def generate_image(prompt, seed):
|
13 |
+
# 设置种子
|
14 |
+
generator = torch.manual_seed(seed)
|
15 |
+
|
16 |
+
# 使用模型生成图像
|
17 |
+
image = pipe(prompt=prompt,
|
18 |
+
num_inference_steps=24,
|
19 |
+
guidance_scale=4.0,
|
20 |
+
width=960, height=1280,
|
21 |
+
generator=generator).images[0]
|
22 |
+
|
23 |
+
return image
|
24 |
|
25 |
# 创建Gradio界面
|
26 |
with gr.Blocks() as demo:
|