gengs commited on
Commit
4dd0da4
1 Parent(s): 0d6f448

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -1,26 +1,30 @@
1
  import gradio as gr
2
- import random
3
 
4
- # 加载 Hugging Face 模型,返回 Gradio Blocks 对象
5
  model = gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA")
6
 
7
- # 定义生成函数,使用 predict() 方法并传入 seed 参数
8
- def generate_image(prompt, seed=None):
9
- if seed is None:
10
- seed = random.randint(0, 1e6) # 如果用户未指定种子,则生成随机数
11
- # 将 prompt 和 seed 作为列表传入 predict 方法
12
- result = model.predict(prompt, seed)
13
  return result
14
 
15
- # 使用 Gradio Blocks 创建界面
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
- generate_button = gr.Button("生成图像")
23
- generate_button.click(generate_image, inputs=[prompt, seed], outputs=output_image)
24
 
25
- # 启动 Gradio 应用
 
 
 
 
 
 
 
 
 
 
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()