Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
|
4 |
-
#
|
5 |
model = gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA")
|
6 |
|
7 |
-
#
|
8 |
-
def generate_image(prompt, seed
|
9 |
-
|
10 |
-
|
11 |
-
# 将 prompt 和 seed 作为列表传入 predict 方法
|
12 |
-
result = model.predict(prompt, seed)
|
13 |
return result
|
14 |
|
15 |
-
#
|
16 |
with gr.Blocks() as demo:
|
17 |
-
gr.Markdown("##
|
18 |
-
prompt = gr.Textbox(label="描述")
|
19 |
-
seed = gr.Number(label="种子 (可选)", value=None)
|
20 |
-
output_image = gr.Image()
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
# 加载模型并配置
|
4 |
model = gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA")
|
5 |
|
6 |
+
# 定义图像生成函数,添加seed参数
|
7 |
+
def generate_image(prompt, seed):
|
8 |
+
# 调用模型的predict方法并传递种子
|
9 |
+
result = model.predict(prompt=prompt, seed=seed)
|
|
|
|
|
10 |
return result
|
11 |
|
12 |
+
# 创建Gradio界面
|
13 |
with gr.Blocks() as demo:
|
14 |
+
gr.Markdown("## Stable Diffusion Image Generation with Seed Control")
|
|
|
|
|
|
|
15 |
|
16 |
+
# 输入框:提示文本
|
17 |
+
prompt_input = gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography")
|
18 |
|
19 |
+
# 滑块:种子
|
20 |
+
seed_input = gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)
|
21 |
+
|
22 |
+
# 输出图像
|
23 |
+
output_image = gr.Image(type="pil", label="Generated Image")
|
24 |
+
|
25 |
+
# 按钮触发事件
|
26 |
+
generate_btn = gr.Button("Generate Image")
|
27 |
+
generate_btn.click(generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
|
28 |
+
|
29 |
+
# 启动Gradio应用
|
30 |
demo.launch()
|