Spaces:
Paused
Paused
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() | |