TK156
fix: 最小構成でエラー修正
b82f603
raw
history blame
1.5 kB
import gradio as gr
import numpy as np
from PIL import Image
def create_depth_map(image):
"""シンプルな深度マップ生成"""
if image is None:
return None, None
try:
# 画像サイズ取得
width, height = image.size
# 上から下へのグラデーション
depth_array = np.zeros((height, width), dtype=np.uint8)
for y in range(height):
depth_array[y, :] = int(255 * y / height)
# カラー深度マップ作成(青から赤へ)
depth_colored = np.zeros((height, width, 3), dtype=np.uint8)
depth_colored[:, :, 0] = 255 - depth_array # 赤チャンネル
depth_colored[:, :, 2] = depth_array # 青チャンネル
depth_image = Image.fromarray(depth_colored)
return image, depth_image
except Exception as e:
print(f"Error: {e}")
return image, image
# Gradioインターフェース
with gr.Blocks(title="深度推定API") as demo:
gr.Markdown("# 深度推定・3D可視化 API")
gr.Markdown("画像をアップロードして深度マップを生成")
with gr.Row():
input_image = gr.Image(label="入力画像", type="pil")
output_depth = gr.Image(label="深度マップ")
input_image.change(
fn=create_depth_map,
inputs=input_image,
outputs=[input_image, output_depth]
)
if __name__ == "__main__":
demo.launch()