File size: 3,419 Bytes
5e21310
a3f6596
 
5e21310
a3f6596
304ce55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3f6596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e21310
ad90047
a3f6596
ad90047
 
 
 
 
 
 
dca6db1
a6e26bb
ad90047
a6e26bb
ad90047
 
 
 
 
 
 
 
 
 
 
a3f6596
ad90047
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import gradio as gr
import subprocess
import os

def generate_image(
    face_image_path, 
    prompt, 
    negative_prompt, 
    adapter_strength_ratio, 
    identitynet_strength_ratio, 
    safety_checker,
    pose_image_path=None, 
    model="AlbedoBase XL V2", 
    enable_fast_mode=True, 
    lightning_steps="4step", 
    scheduler="DPMSolverMultistepScheduler", 
    pose=False, 
    pose_strength=0.5, 
    canny=False, 
    canny_strength=0.5, 
    depth_map=False, 
    depth_strength=0.5, 
    num_steps=25, 
    guidance_scale=7, 
    seed=0
):
    output_image_path = "result.jpg"
    
    command = [
        "python", "your_script_for_image_generation.py",
        f"--face_image_path={face_image_path}",
        f"--prompt={prompt}",
        f"--negative_prompt={negative_prompt}",
        f"--adapter_strength_ratio={adapter_strength_ratio}",
        f"--identitynet_strength_ratio={identitynet_strength_ratio}",
        f"--safety_checker={safety_checker}",
        f"--model={model}",
        f"--enable_fast_mode={enable_fast_mode}",
        f"--lightning_steps={lightning_steps}",
        f"--scheduler={scheduler}",
        f"--num_steps={num_steps}",
        f"--guidance_scale={guidance_scale}",
        f"--seed={seed}",
        f"--output={output_image_path}"
    ]
    
    if pose_image_path:
        command.append(f"--pose_image_path={pose_image_path}")
        command.append(f"--pose={pose}")
        command.append(f"--pose_strength={pose_strength}")
    
    if canny:
        command.append(f"--canny={canny}")
        command.append(f"--canny_strength={canny_strength}")
    
    if depth_map:
        command.append(f"--depth_map={depth_map}")
        command.append(f("--depth_strength={depth_strength}"))
    
    result = subprocess.run(command, capture_output=True, text=True)
    
    print("stdout:", result.stdout)
    print("stderr:", result.stderr)
    
    if result.returncode != 0:
        raise RuntimeError(result.stderr)
    
    if os.path.exists(output_image_path):
        return output_image_path
    else:
        raise RuntimeError("Failed to generate image.")

iface = gr.Interface(
    fn=generate_image,
    inputs=[
        gr.Image(type="filepath", label="Face Image Path"),
        gr.Textbox(label="Prompt"),
        gr.Textbox(label="Negative Prompt"),
        gr.Slider(0.0, 1.0, 0.8, label="Adapter Strength Ratio"),
        gr.Slider(0.0, 1.0, 0.8, label="IdentityNet Strength Ratio"),
        gr.Checkbox(True, label="Safety Checker"),
        gr.Image(type="filepath", label="Pose Image Path"),
        gr.Dropdown(["AlbedoBase XL V2", "Juggernaut XL V8"], value="AlbedoBase XL V2", label="Model"),
        gr.Checkbox(True, label="Enable Fast Mode"),
        gr.Dropdown(["2step", "4step", "8step"], value="4step", label="Lightning Steps"),
        gr.Textbox("DPMSolverMultistepScheduler", label="Scheduler"),
        gr.Checkbox(False, label="Pose"),
        gr.Slider(0.0, 1.5, 0.5, label="Pose Strength"),
        gr.Checkbox(False, label="Canny"),
        gr.Slider(0.0, 1.5, 0.5, label="Canny Strength"),
        gr.Checkbox(False, label="Depth Map"),
        gr.Slider(0.0, 1.5, 0.5, label="Depth Strength"),
        gr.Slider(1, 50, 25, label="Number of Steps"),
        gr.Slider(1, 10, 7, label="Guidance Scale"),
        gr.Number(0, label="Seed")
    ],
    outputs=gr.Image(type="filepath", label="Generated Image")
)

iface.launch()