gengs's picture
Update app.py
22a2ff4 verified
raw
history blame
928 Bytes
# import gradio as gr
# gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA").launch()
import gradio as gr
import random
# 首先加载模型
model = gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA")
# 定义生成函数,并接收种子参数
def generate_image(prompt, seed=None):
if seed is None:
seed = random.randint(0, 1e6) # 随机生成种子
# 设置生成参数,包括种子
result = model(prompt=prompt, seed=seed)
return result
# 使用 Gradio Blocks 创建自定义界面
with gr.Blocks() as demo:
gr.Markdown("## 输入描述和种子以生成图像")
prompt = gr.Textbox(label="描述")
seed = gr.Number(label="种子 (可选)", value=None)
output_image = gr.Image()
generate_button = gr.Button("生成图像")
generate_button.click(generate_image, inputs=[prompt, seed], outputs=output_image)
# 启动 Gradio 应用
demo.launch()