ToddEverett commited on
Commit
4d28cf8
·
verified ·
1 Parent(s): cafec31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -39
app.py CHANGED
@@ -1,41 +1,3 @@
1
  import gradio as gr
2
- from diffusers import DiffusionPipeline
3
 
4
- # 加载模型到 CPU
5
- model_repo_id = "stabilityai/stable-diffusion-3.5-large"
6
- pipe = DiffusionPipeline.from_pretrained(model_repo_id)
7
- pipe.to("cpu") # 使用 CPU
8
-
9
- # 定义图像生成函数,允许自定义宽度和高度
10
- def generate_image(prompt, width=1024, height=768, guidance_scale=7.5, num_inference_steps=40):
11
- image = pipe(
12
- prompt=prompt,
13
- width=width,
14
- height=height,
15
- guidance_scale=guidance_scale,
16
- num_inference_steps=num_inference_steps
17
- ).images[0]
18
- return image
19
-
20
- # 设置 Gradio 界面
21
- with gr.Blocks() as demo:
22
- gr.Markdown(" # Stable Diffusion 3.5 - 自定义宽高比例")
23
-
24
- with gr.Row():
25
- prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
26
-
27
- # 用户自定义宽度和高度
28
- width = gr.Slider(label="Width", minimum=512, maximum=1024, step=64, value=1024)
29
- height = gr.Slider(label="Height", minimum=512, maximum=1024, step=64, value=768)
30
-
31
- guidance_scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=15.0, step=0.1, value=7.5)
32
- num_inference_steps = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=50, step=1, value=40)
33
-
34
- output_image = gr.Image(label="Generated Image")
35
-
36
- # 点击按钮生成图像
37
- generate_btn = gr.Button("Generate")
38
- generate_btn.click(generate_image, inputs=[prompt, width, height, guidance_scale, num_inference_steps], outputs=output_image)
39
-
40
- # 启动 Gradio 界面
41
- demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ gr.load("models/stabilityai/stable-diffusion-3.5-large").launch()