import gradio as gr import numpy as np from PIL import Image def create_simple_depth_map(image): """シンプルなグラデーション深度マップを作成""" if image is None: return None, None try: # 画像サイズ取得 width, height = image.size # 上から下へのグラデーション(上=青/遠い、下=赤/近い) depth_array = np.zeros((height, width, 3), dtype=np.uint8) for y in range(height): ratio = y / height # 青から赤へのグラデーション depth_array[y, :, 0] = int(255 * ratio) # 赤チャンネル depth_array[y, :, 2] = int(255 * (1 - ratio)) # 青チャンネル depth_image = Image.fromarray(depth_array) return image, depth_image except Exception as e: print(f"Error: {e}") return image, image # Gradioインターフェース demo = gr.Interface( fn=create_simple_depth_map, inputs=gr.Image(type="pil", label="入力画像"), outputs=[ gr.Image(label="元画像"), gr.Image(label="深度マップ") ], title="🌊 深度推定 API", description="画像をアップロードして深度マップを生成します(上=遠い/青、下=近い/赤)" ) if __name__ == "__main__": demo.launch()