Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,7 +91,7 @@ def generate_single_view(input_images, prompt, seed, num_inference_steps, true_g
|
|
| 91 |
# --- Main Inference Function ---
|
| 92 |
@spaces.GPU(duration=300)
|
| 93 |
def generate_turnaround(
|
| 94 |
-
|
| 95 |
seed=42,
|
| 96 |
randomize_seed=False,
|
| 97 |
true_guidance_scale=1.0,
|
|
@@ -104,23 +104,21 @@ def generate_turnaround(
|
|
| 104 |
if randomize_seed:
|
| 105 |
seed = random.randint(0, MAX_SEED)
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
| 109 |
-
if images is not None:
|
| 110 |
-
for item in images:
|
| 111 |
-
try:
|
| 112 |
-
if isinstance(item[0], Image.Image):
|
| 113 |
-
pil_images.append(item[0].convert("RGB"))
|
| 114 |
-
elif isinstance(item[0], str):
|
| 115 |
-
pil_images.append(Image.open(item[0]).convert("RGB"))
|
| 116 |
-
elif hasattr(item, "name"):
|
| 117 |
-
pil_images.append(Image.open(item.name).convert("RGB"))
|
| 118 |
-
except Exception:
|
| 119 |
-
continue
|
| 120 |
-
|
| 121 |
-
if not pil_images:
|
| 122 |
return None, None, None, None, seed, "エラー: 入力画像をアップロードしてください"
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
# 1. 正面立ち絵を生成
|
| 125 |
progress(0.25, desc="正面立ち絵を生成中...")
|
| 126 |
front_image = generate_single_view(pil_images, PROMPTS["front"], seed, num_inference_steps, true_guidance_scale)
|
|
@@ -164,7 +162,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 164 |
|
| 165 |
with gr.Column(elem_id="col-container"):
|
| 166 |
with gr.Row():
|
| 167 |
-
|
| 168 |
label="入力画像(キャラクター画像をアップロード)",
|
| 169 |
show_label=True,
|
| 170 |
type="pil",
|
|
@@ -219,7 +217,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 219 |
run_button.click(
|
| 220 |
fn=generate_turnaround,
|
| 221 |
inputs=[
|
| 222 |
-
|
| 223 |
seed,
|
| 224 |
randomize_seed,
|
| 225 |
true_guidance_scale,
|
|
@@ -229,5 +227,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 229 |
)
|
| 230 |
|
| 231 |
if __name__ == "__main__":
|
| 232 |
-
|
| 233 |
demo.launch()
|
|
|
|
| 91 |
# --- Main Inference Function ---
|
| 92 |
@spaces.GPU(duration=300)
|
| 93 |
def generate_turnaround(
|
| 94 |
+
image,
|
| 95 |
seed=42,
|
| 96 |
randomize_seed=False,
|
| 97 |
true_guidance_scale=1.0,
|
|
|
|
| 104 |
if randomize_seed:
|
| 105 |
seed = random.randint(0, MAX_SEED)
|
| 106 |
|
| 107 |
+
# 入力画像の確認
|
| 108 |
+
if image is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
return None, None, None, None, seed, "エラー: 入力画像をアップロードしてください"
|
| 110 |
|
| 111 |
+
# PIL画像として処理
|
| 112 |
+
if isinstance(image, Image.Image):
|
| 113 |
+
input_image = image.convert("RGB")
|
| 114 |
+
else:
|
| 115 |
+
try:
|
| 116 |
+
input_image = Image.open(image).convert("RGB")
|
| 117 |
+
except:
|
| 118 |
+
return None, None, None, None, seed, "エラー: 画像の読み込みに失敗しました"
|
| 119 |
+
|
| 120 |
+
pil_images = [input_image]
|
| 121 |
+
|
| 122 |
# 1. 正面立ち絵を生成
|
| 123 |
progress(0.25, desc="正面立ち絵を生成中...")
|
| 124 |
front_image = generate_single_view(pil_images, PROMPTS["front"], seed, num_inference_steps, true_guidance_scale)
|
|
|
|
| 162 |
|
| 163 |
with gr.Column(elem_id="col-container"):
|
| 164 |
with gr.Row():
|
| 165 |
+
input_image = gr.Image(
|
| 166 |
label="入力画像(キャラクター画像をアップロード)",
|
| 167 |
show_label=True,
|
| 168 |
type="pil",
|
|
|
|
| 217 |
run_button.click(
|
| 218 |
fn=generate_turnaround,
|
| 219 |
inputs=[
|
| 220 |
+
input_image,
|
| 221 |
seed,
|
| 222 |
randomize_seed,
|
| 223 |
true_guidance_scale,
|
|
|
|
| 227 |
)
|
| 228 |
|
| 229 |
if __name__ == "__main__":
|
|
|
|
| 230 |
demo.launch()
|