guohp123456 commited on
Commit
a968241
·
verified ·
1 Parent(s): a9d7745

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import torch
4
+ from diffusers import DiffusionPipeline
5
+ from utils import generate_canny
6
+
7
+ # 加载模型
8
+ pipe = DiffusionPipeline.from_pretrained(
9
+ "stabilityai/stable-diffusion-3.5-large-controlnet-canny",
10
+ torch_dtype=torch.float16,
11
+ variant="fp16"
12
+ ).to("cuda")
13
+
14
+ # 推理函数
15
+ def infer(image: Image.Image, prompt: str, neg_prompt: str = "bad face, blurry, text, watermark") -> Image.Image:
16
+ control = generate_canny(image)
17
+ result = pipe(
18
+ prompt=prompt,
19
+ negative_prompt=neg_prompt,
20
+ controlnet_conditioning_image=control,
21
+ num_inference_steps=30,
22
+ guidance_scale=9.0,
23
+ ).images[0]
24
+ return result
25
+
26
+ # Gradio 界面
27
+ demo = gr.Interface(
28
+ fn=infer,
29
+ inputs=[
30
+ gr.Image(type="pil", label="上传原图(自动转边缘图)"),
31
+ gr.Textbox(lines=2, label="Prompt(描述服装/风格)", value="a woman wearing a spring coat, photorealistic, soft lighting, 8k"),
32
+ gr.Textbox(lines=1, label="Negative Prompt", value="bad face, cropped, lowres, extra limbs")
33
+ ],
34
+ outputs=gr.Image(type="pil", label="生成结果"),
35
+ title="👗 ControlNet-Canny 高质量穿搭图生成器(SD3.5)",
36
+ description="上传图像 + 输入Prompt,即可生成结构一致的高清穿搭图(Stable Diffusion 3.5 + ControlNet)",
37
+ examples=[["example.jpg", "a fashion photo of a woman wearing a trench coat, full body, 8k"]],
38
+ )
39
+
40
+ demo.launch()