File size: 1,518 Bytes
2385429 4cec43c 22a2ff4 4dd0da4 4cec43c 22a2ff4 4cec43c 83c0970 4cec43c 22a2ff4 83c0970 22a2ff4 83c0970 2385429 83c0970 4dd0da4 83c0970 4dd0da4 83c0970 4dd0da4 83c0970 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
import torch
from diffusers import StableDiffusion3Pipeline
# 加载模型并配置
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Photorealistic-LoRA", weight_name="Photorealistic-SD3.5-Large-LoRA.safetensors")
pipe.fuse_lora(lora_scale=1.0)
# pipe.to("cuda")
# 定义图像生成函数,添加种子参数
def generate_image(prompt, seed):
# 设置种子
generator = torch.manual_seed(seed)
# 使用模型生成图像
image = pipe(prompt=prompt,
num_inference_steps=24,
guidance_scale=4.0,
width=960, height=1280,
generator=generator).images[0]
return image
# 创建Gradio界面
with gr.Blocks() as demo:
gr.Markdown("## Stable Diffusion Image Generation with Seed Control")
# 输入框:提示文本
prompt_input = gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography")
# 滑块:种子
seed_input = gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)
# 输出图像
output_image = gr.Image(type="pil", label="Generated Image")
# 按钮触发事件
generate_btn = gr.Button("Generate Image")
generate_btn.click(generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
# 启动Gradio应用
demo.launch() |