Slicelayers commited on
Commit
f989429
·
verified ·
1 Parent(s): 4f56a3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -10,7 +10,7 @@ import time
10
  import asyncio
11
  import os
12
  import cv2
13
- import httpx # ★★★ 変更点: httpx を追加
14
 
15
  # --- 定数とAPI設定 (Constants and API Configuration) ---
16
 
@@ -131,16 +131,16 @@ async def nano_banana_completion_api(base_image: Image.Image, prompt: str) -> Im
131
 
132
  # --- メイン処理ロジック (Main Processing Logic) ---
133
 
134
- # ★★★ 変更点: 引数を(オリジナル画像, マスク画像)のタプルに変更 ★★★
135
  async def segment_and_inpaint(image_data_tuple: tuple, inpaint_prompt: str):
136
  """
137
  アップロードされた一枚絵とブラシで描かれたマスクを受け取り、
138
  マスクされた領域を分割し、欠損部分をAI補完する関数。
139
  """
140
- if image_data_tuple is None or len(image_data_tuple) < 2:
141
  return None, None, None, "エラー: 画像がアップロードされていないか、分割したいパーツをブラシで描画してください。", None
142
 
143
- # Gradioのsketchツールは (画像データ, マスクデータ) のタプルを返す
 
144
  original_rgba_np, sketch_mask_np = image_data_tuple
145
 
146
  # PIL Image (元の画像) を取得
@@ -237,7 +237,6 @@ theme = gr.themes.Soft(
237
  secondary_hue="blue",
238
  neutral_hue="gray",
239
  )
240
- # .set() メソッドは削除済み
241
 
242
  with gr.Blocks(theme=theme, title="Live2D素材自動分割・補完アプリ") as demo:
243
  gr.Markdown(
@@ -252,12 +251,11 @@ with gr.Blocks(theme=theme, title="Live2D素材自動分割・補完アプリ")
252
 
253
  with gr.Row():
254
  with gr.Column(scale=1):
255
- # ★★★ 変更点: 入力を手動ブラシモードに移行 ★★★
256
  input_image = gr.Image(
257
- type="numpy", # NumPy配列で (画像, マスク) タプルを受け取る
258
  label="① 分割したいパーツをブラシで塗る (例: 前髪)",
259
  height=400,
260
- tool="sketch" # 描画ツールを有効化
261
  )
262
  inpaint_prompt = gr.Textbox(
263
  label="② AI補完プロンプト(オプション)",
@@ -269,8 +267,7 @@ with gr.Blocks(theme=theme, title="Live2D素材自動分割・補完アプリ")
269
  gr.Markdown(
270
  """
271
  ### 📌 開発のポイント
272
- * このバージョンでは、自動分割シミュレーション(ブラー円)を廃止し、**ユーザーがブラシで描いた領域**を分離パーツとして扱います。
273
- * 分離されたパーツの下は透明な穴となるため、AIがその部分の「欠損」を元の絵柄に合わせて補完します。
274
  """
275
  )
276
 
 
10
  import asyncio
11
  import os
12
  import cv2
13
+ import httpx
14
 
15
  # --- 定数とAPI設定 (Constants and API Configuration) ---
16
 
 
131
 
132
  # --- メイン処理ロジック (Main Processing Logic) ---
133
 
 
134
  async def segment_and_inpaint(image_data_tuple: tuple, inpaint_prompt: str):
135
  """
136
  アップロードされた一枚絵とブラシで描かれたマスクを受け取り、
137
  マスクされた領域を分割し、欠損部分をAI補完する関数。
138
  """
139
+ if image_data_tuple is None:
140
  return None, None, None, "エラー: 画像がアップロードされていないか、分割したいパーツをブラシで描画してください。", None
141
 
142
+ # Gradioのtype="sketch"は (画像データ, マスクデータ) のタプルを返す
143
+ # NOTE: type="sketch"の出力構造は (元の画像 (np.array), マスク画像 (np.array)) です。
144
  original_rgba_np, sketch_mask_np = image_data_tuple
145
 
146
  # PIL Image (元の画像) を取得
 
237
  secondary_hue="blue",
238
  neutral_hue="gray",
239
  )
 
240
 
241
  with gr.Blocks(theme=theme, title="Live2D素材自動分割・補完アプリ") as demo:
242
  gr.Markdown(
 
251
 
252
  with gr.Row():
253
  with gr.Column(scale=1):
254
+ # ★★★ 修正箇所: tool="sketch" を type="sketch" に変更し、互換性を確保 ★★★
255
  input_image = gr.Image(
256
+ type="sketch", # 描画ツールを有効化し、(画像, マスク) タプルを出力
257
  label="① 分割したいパーツをブラシで塗る (例: 前髪)",
258
  height=400,
 
259
  )
260
  inpaint_prompt = gr.Textbox(
261
  label="② AI補完プロンプト(オプション)",
 
267
  gr.Markdown(
268
  """
269
  ### 📌 開発のポイント
270
+ * この機能は、ユーザーがブラシで描いた領域を分離パーツとして扱い、その下をAIで補完することで、Live2Dモデリングのコアとなる**「欠損補完」**を実現します。
 
271
  """
272
  )
273