Spaces:
Runtime error
Runtime error
TK156
commited on
Commit
·
d1fb809
1
Parent(s):
2693362
fix: Space復旧のため最小構成に戻す
Browse files- Gradio Interfaceの最もシンプルな形
- 一つの依存関係のみ
- Space復旧優先
- app.py +13 -53
- requirements.txt +1 -3
app.py
CHANGED
@@ -1,63 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
from PIL import Image
|
4 |
|
5 |
-
def
|
6 |
"""シンプルな深度マップ生成"""
|
7 |
if image is None:
|
8 |
-
return None
|
9 |
|
10 |
-
|
11 |
-
# 画像をnumpy配列に変換
|
12 |
-
img_array = np.array(image)
|
13 |
-
height, width = img_array.shape[:2]
|
14 |
-
|
15 |
-
# 上から下へのグラデーション(上=遠い/青、下=近い/赤)
|
16 |
-
depth_map = np.zeros((height, width, 3), dtype=np.uint8)
|
17 |
-
|
18 |
-
for y in range(height):
|
19 |
-
ratio = y / height
|
20 |
-
# 青から赤へのグラデーション
|
21 |
-
depth_map[y, :, 0] = int(255 * ratio) # 赤
|
22 |
-
depth_map[y, :, 2] = int(255 * (1 - ratio)) # 青
|
23 |
-
|
24 |
-
return Image.fromarray(depth_map)
|
25 |
-
|
26 |
-
except Exception as e:
|
27 |
-
print(f"Error: {e}")
|
28 |
-
return image
|
29 |
|
30 |
# Gradioインターフェース
|
31 |
-
|
32 |
-
|
33 |
-
gr.
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
)
|
42 |
-
with gr.Column():
|
43 |
-
output_depth = gr.Image(
|
44 |
-
label="深度マップ(上=遠い/青、下=近い/赤)",
|
45 |
-
height=300
|
46 |
-
)
|
47 |
-
|
48 |
-
# 画像変更時に自動処理
|
49 |
-
input_image.change(
|
50 |
-
fn=create_depth_map,
|
51 |
-
inputs=input_image,
|
52 |
-
outputs=output_depth
|
53 |
-
)
|
54 |
-
|
55 |
-
gr.Markdown("""
|
56 |
-
### 📝 使い方
|
57 |
-
1. 画像をアップロードまたはドラッグ&ドロップ
|
58 |
-
2. 深度マップが自動生成されます
|
59 |
-
3. 青=遠い部分、赤=近い部分
|
60 |
-
""")
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
def process_depth(image):
|
4 |
"""シンプルな深度マップ生成"""
|
5 |
if image is None:
|
6 |
+
return None, None
|
7 |
|
8 |
+
return image, image # とりあえず同じ画像を返す
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Gradioインターフェース
|
11 |
+
demo = gr.Interface(
|
12 |
+
fn=process_depth,
|
13 |
+
inputs=gr.Image(type="pil"),
|
14 |
+
outputs=[
|
15 |
+
gr.Image(label="元画像"),
|
16 |
+
gr.Image(label="深度マップ")
|
17 |
+
],
|
18 |
+
title="深度推定API",
|
19 |
+
description="画像をアップロードして深度マップを生成"
|
20 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1 @@
|
|
1 |
-
gradio
|
2 |
-
numpy
|
3 |
-
pillow
|
|
|
1 |
+
gradio
|
|
|
|