Spaces:
Runtime error
Runtime error
TK156
commited on
Commit
·
b899d5f
1
Parent(s):
105fc53
feat: グラデーション深度マップ機能を追加
Browse files- 画像アップロード対応
- 上から下へのグラデーション深度マップ
- 2つの出力(元画像と深度マップ)
- numpy, pillowを最小限追加
- app.py +37 -6
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,12 +1,43 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
|
|
6 |
demo = gr.Interface(
|
7 |
-
fn=
|
8 |
-
inputs="
|
9 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
10 |
)
|
11 |
|
12 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
|
5 |
+
def create_simple_depth_map(image):
|
6 |
+
"""シンプルなグラデーション深度マップを作成"""
|
7 |
+
if image is None:
|
8 |
+
return None, None
|
9 |
+
|
10 |
+
try:
|
11 |
+
# 画像サイズ取得
|
12 |
+
width, height = image.size
|
13 |
+
|
14 |
+
# 上から下へのグラデーション(上=青/遠い、下=赤/近い)
|
15 |
+
depth_array = np.zeros((height, width, 3), dtype=np.uint8)
|
16 |
+
|
17 |
+
for y in range(height):
|
18 |
+
ratio = y / height
|
19 |
+
# 青から赤へのグラデーション
|
20 |
+
depth_array[y, :, 0] = int(255 * ratio) # 赤チャンネル
|
21 |
+
depth_array[y, :, 2] = int(255 * (1 - ratio)) # 青チャンネル
|
22 |
+
|
23 |
+
depth_image = Image.fromarray(depth_array)
|
24 |
+
return image, depth_image
|
25 |
+
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Error: {e}")
|
28 |
+
return image, image
|
29 |
|
30 |
+
# Gradioインターフェース
|
31 |
demo = gr.Interface(
|
32 |
+
fn=create_simple_depth_map,
|
33 |
+
inputs=gr.Image(type="pil", label="入力画像"),
|
34 |
+
outputs=[
|
35 |
+
gr.Image(label="元画像"),
|
36 |
+
gr.Image(label="深度マップ")
|
37 |
+
],
|
38 |
+
title="深度推定 API",
|
39 |
+
description="画像をアップロードして深度マップを生成します(上=遠い/青、下=近い/赤)"
|
40 |
)
|
41 |
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
gradio
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
pillow
|