Update app.py
Browse files
app.py
CHANGED
@@ -22,30 +22,43 @@ def generate_image(prompt, seed):
|
|
22 |
generator = torch.manual_seed(seed)
|
23 |
|
24 |
# 使用模型生成图像
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
|
|
|
|
31 |
return image
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# 创建Gradio界面
|
34 |
-
with gr.Blocks() as demo:
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
# 启动Gradio应用
|
51 |
-
demo.launch()
|
|
|
22 |
generator = torch.manual_seed(seed)
|
23 |
|
24 |
# 使用模型生成图像
|
25 |
+
result = pipe(prompt=prompt,
|
26 |
+
num_inference_steps=24,
|
27 |
+
guidance_scale=4.0,
|
28 |
+
width=960, height=1280,
|
29 |
+
generator=generator)
|
30 |
|
31 |
+
# 确保返回 PIL 图像
|
32 |
+
image = result.images[0]
|
33 |
return image
|
34 |
|
35 |
+
# 创建Gradio界面(使用 Interface)
|
36 |
+
def gradio_interface():
|
37 |
+
with gr.Interface(fn=generate_image,
|
38 |
+
inputs=[gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography"),
|
39 |
+
gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)],
|
40 |
+
outputs=gr.Image(type="pil", label="Generated Image")) as demo:
|
41 |
+
demo.launch()
|
42 |
+
|
43 |
+
# 启动Gradio应用
|
44 |
+
gradio_interface()
|
45 |
+
|
46 |
# 创建Gradio界面
|
47 |
+
# with gr.Blocks() as demo:
|
48 |
+
# gr.Markdown("## Stable Diffusion Image Generation with Seed Control")
|
49 |
|
50 |
+
# # 输入框:提示文本
|
51 |
+
# prompt_input = gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography")
|
52 |
|
53 |
+
# # 滑块:种子
|
54 |
+
# seed_input = gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)
|
55 |
|
56 |
+
# # 输出图像
|
57 |
+
# output_image = gr.Image(type="pil", label="Generated Image")
|
58 |
|
59 |
+
# # 按钮触发事件
|
60 |
+
# generate_btn = gr.Button("Generate Image")
|
61 |
+
# generate_btn.click(fn=generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
|
62 |
|
63 |
+
# # 启动Gradio应用
|
64 |
+
# demo.launch()
|