Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,6 +62,11 @@ PROMPTS = {
|
|
| 62 |
"right": "Move the camera to a side view (profile) from the right so the full body of the character is visible. Background is plain white."
|
| 63 |
}
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def generate_single_view(input_images, prompt, seed, num_inference_steps, true_guidance_scale):
|
| 66 |
"""単一視点画像生成"""
|
| 67 |
generator = torch.Generator(device=device).manual_seed(seed)
|
|
@@ -99,13 +104,14 @@ def concat_images_horizontally(images, bg_color=(255, 255, 255)):
|
|
| 99 |
@spaces.GPU(duration=300)
|
| 100 |
def generate_turnaround(
|
| 101 |
image,
|
|
|
|
| 102 |
seed=42,
|
| 103 |
randomize_seed=False,
|
| 104 |
true_guidance_scale=1.0,
|
| 105 |
num_inference_steps=4,
|
| 106 |
progress=gr.Progress(track_tqdm=True),
|
| 107 |
):
|
| 108 |
-
"""4視点+横連結PNG
|
| 109 |
if randomize_seed:
|
| 110 |
seed = random.randint(0, MAX_SEED)
|
| 111 |
if image is None:
|
|
@@ -118,17 +124,23 @@ def generate_turnaround(
|
|
| 118 |
|
| 119 |
pil_images = [input_image]
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
progress(0.25, desc="正面生成中...")
|
| 122 |
-
front = generate_single_view(pil_images,
|
| 123 |
|
| 124 |
progress(0.5, desc="背面生成中...")
|
| 125 |
-
back = generate_single_view([front],
|
| 126 |
|
| 127 |
progress(0.75, desc="左側面生成中...")
|
| 128 |
-
left = generate_single_view([front],
|
| 129 |
|
| 130 |
progress(1.0, desc="右側面生成中...")
|
| 131 |
-
right = generate_single_view([front],
|
| 132 |
|
| 133 |
concat = concat_images_horizontally([front, right, back, left])
|
| 134 |
return front, back, left, right, concat, seed, "✅ PNG形式で4視点+連結画像を生成しました"
|
|
@@ -145,6 +157,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 145 |
|
| 146 |
with gr.Column(elem_id="col-container"):
|
| 147 |
input_image = gr.Image(label="入力画像", type="pil", height=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
run_button = gr.Button("🎨 生成開始", variant="primary")
|
| 149 |
status_text = gr.Textbox(label="ステータス", interactive=False)
|
| 150 |
|
|
@@ -164,9 +183,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 164 |
true_guidance_scale = gr.Slider(label="True guidance scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
|
| 165 |
num_inference_steps = gr.Slider(label="生成ステップ数", minimum=1, maximum=40, step=1, value=4)
|
| 166 |
|
|
|
|
| 167 |
run_button.click(
|
| 168 |
fn=generate_turnaround,
|
| 169 |
-
inputs=[input_image, seed, randomize_seed, true_guidance_scale, num_inference_steps],
|
| 170 |
outputs=[result_front, result_back, result_left, result_right, result_concat, seed, status_text],
|
| 171 |
)
|
| 172 |
|
|
|
|
| 62 |
"right": "Move the camera to a side view (profile) from the right so the full body of the character is visible. Background is plain white."
|
| 63 |
}
|
| 64 |
|
| 65 |
+
def _append_prompt(base: str, extra: str) -> str:
|
| 66 |
+
"""末尾にユーザー指定のプロンプトを追記(空なら変更なし)"""
|
| 67 |
+
extra = (extra or "").strip()
|
| 68 |
+
return (base if not extra else f"{base} {extra}").strip()
|
| 69 |
+
|
| 70 |
def generate_single_view(input_images, prompt, seed, num_inference_steps, true_guidance_scale):
|
| 71 |
"""単一視点画像生成"""
|
| 72 |
generator = torch.Generator(device=device).manual_seed(seed)
|
|
|
|
| 104 |
@spaces.GPU(duration=300)
|
| 105 |
def generate_turnaround(
|
| 106 |
image,
|
| 107 |
+
extra_prompt="", # ← 追加: ユーザー追記用プロンプト
|
| 108 |
seed=42,
|
| 109 |
randomize_seed=False,
|
| 110 |
true_guidance_scale=1.0,
|
| 111 |
num_inference_steps=4,
|
| 112 |
progress=gr.Progress(track_tqdm=True),
|
| 113 |
):
|
| 114 |
+
"""4視点+横連結PNG生成(ユーザー追記プロンプト対応)"""
|
| 115 |
if randomize_seed:
|
| 116 |
seed = random.randint(0, MAX_SEED)
|
| 117 |
if image is None:
|
|
|
|
| 124 |
|
| 125 |
pil_images = [input_image]
|
| 126 |
|
| 127 |
+
# 各プロンプト末尾に追記
|
| 128 |
+
p_front = _append_prompt(PROMPTS["front"], extra_prompt)
|
| 129 |
+
p_back = _append_prompt(PROMPTS["back"], extra_prompt)
|
| 130 |
+
p_left = _append_prompt(PROMPTS["left"], extra_prompt)
|
| 131 |
+
p_right = _append_prompt(PROMPTS["right"], extra_prompt)
|
| 132 |
+
|
| 133 |
progress(0.25, desc="正面生成中...")
|
| 134 |
+
front = generate_single_view(pil_images, p_front, seed, num_inference_steps, true_guidance_scale)
|
| 135 |
|
| 136 |
progress(0.5, desc="背面生成中...")
|
| 137 |
+
back = generate_single_view([front], p_back, seed+1, num_inference_steps, true_guidance_scale)
|
| 138 |
|
| 139 |
progress(0.75, desc="左側面生成中...")
|
| 140 |
+
left = generate_single_view([front], p_left, seed+2, num_inference_steps, true_guidance_scale)
|
| 141 |
|
| 142 |
progress(1.0, desc="右側面生成中...")
|
| 143 |
+
right = generate_single_view([front], p_right, seed+3, num_inference_steps, true_guidance_scale)
|
| 144 |
|
| 145 |
concat = concat_images_horizontally([front, right, back, left])
|
| 146 |
return front, back, left, right, concat, seed, "✅ PNG形式で4視点+連結画像を生成しました"
|
|
|
|
| 157 |
|
| 158 |
with gr.Column(elem_id="col-container"):
|
| 159 |
input_image = gr.Image(label="入力画像", type="pil", height=500)
|
| 160 |
+
# ← 追加: 追記プロンプト欄
|
| 161 |
+
extra_prompt = gr.Textbox(
|
| 162 |
+
label="追加プロンプト(各視点プロンプトの末尾に追記)",
|
| 163 |
+
placeholder="例: high detail, anime style, soft lighting, 4k, pastel colors",
|
| 164 |
+
lines=2
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
run_button = gr.Button("🎨 生成開始", variant="primary")
|
| 168 |
status_text = gr.Textbox(label="ステータス", interactive=False)
|
| 169 |
|
|
|
|
| 183 |
true_guidance_scale = gr.Slider(label="True guidance scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
|
| 184 |
num_inference_steps = gr.Slider(label="生成ステップ数", minimum=1, maximum=40, step=1, value=4)
|
| 185 |
|
| 186 |
+
# 入力の並びに extra_prompt を追加
|
| 187 |
run_button.click(
|
| 188 |
fn=generate_turnaround,
|
| 189 |
+
inputs=[input_image, extra_prompt, seed, randomize_seed, true_guidance_scale, num_inference_steps],
|
| 190 |
outputs=[result_front, result_back, result_left, result_right, result_concat, seed, status_text],
|
| 191 |
)
|
| 192 |
|