Spaces:
Runtime error
Runtime error
File size: 1,377 Bytes
2e78bab b899d5f 2e78bab b899d5f 2e78bab b899d5f d1fb809 b899d5f ee72b4f b899d5f d1fb809 2e78bab b899d5f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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() |