gengs commited on
Commit
4cec43c
1 Parent(s): 83c0970

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -1,14 +1,26 @@
1
  import gradio as gr
 
 
2
 
3
  # 加载模型并配置
4
- model = gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA")
5
- # .launch()
 
 
6
 
7
- # 定义图像生成函数,添加seed参数
8
  def generate_image(prompt, seed):
9
- # 调用模型的predict方法并传递种子
10
- result = model.predict(prompt=prompt, seed=seed)
11
- return result
 
 
 
 
 
 
 
 
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: