Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,30 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
|
3 |
+
# gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA").launch()
|
4 |
+
|
5 |
import gradio as gr
|
6 |
+
import random
|
7 |
+
|
8 |
+
# 首先加载模型
|
9 |
+
model = gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA")
|
10 |
+
|
11 |
+
# 定义生成函数,并接收种子参数
|
12 |
+
def generate_image(prompt, seed=None):
|
13 |
+
if seed is None:
|
14 |
+
seed = random.randint(0, 1e6) # 随机生成种子
|
15 |
+
# 设置生成参数,包括种子
|
16 |
+
result = model(prompt=prompt, seed=seed)
|
17 |
+
return result
|
18 |
+
|
19 |
+
# 使用 Gradio Blocks 创建自定义界面
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("## 输入描述和种子以生成图像")
|
22 |
+
prompt = gr.Textbox(label="描述")
|
23 |
+
seed = gr.Number(label="种子 (可选)", value=None)
|
24 |
+
output_image = gr.Image()
|
25 |
+
|
26 |
+
generate_button = gr.Button("生成图像")
|
27 |
+
generate_button.click(generate_image, inputs=[prompt, seed], outputs=output_image)
|
28 |
|
29 |
+
# 启动 Gradio 应用
|
30 |
+
demo.launch()
|