Spaces:
Runtime error
Runtime error
TK156
commited on
Commit
·
d2d0263
1
Parent(s):
4f55111
fix: Space安定化のため最小限Interface構成
Browse files- Gradio Interfaceに戻す
- numpy/pillow依存関係削除
- 基本的な画像入出力のみ
- 接続テスト優先
- app.py +13 -52
- requirements.txt +1 -3
app.py
CHANGED
|
@@ -1,61 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
from PIL import Image
|
| 4 |
|
| 5 |
def create_depth_map(image):
|
| 6 |
-
"""
|
| 7 |
if image is None:
|
| 8 |
return None, None
|
| 9 |
-
|
| 10 |
-
try:
|
| 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, :, 1] = int(128 * (1 - ratio)) # 緑
|
| 23 |
-
depth_map[y, :, 2] = int(255 * (1 - ratio)) # 青
|
| 24 |
-
|
| 25 |
-
depth_image = Image.fromarray(depth_map)
|
| 26 |
-
return image, depth_image
|
| 27 |
-
|
| 28 |
-
except Exception as e:
|
| 29 |
-
print(f"Error: {e}")
|
| 30 |
-
return image, image
|
| 31 |
|
| 32 |
-
# Gradio
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
gr.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
with gr.Column():
|
| 44 |
-
output_original = gr.Image(label="元画像")
|
| 45 |
-
output_depth = gr.Image(label="深度マップ")
|
| 46 |
-
|
| 47 |
-
# 画像変更時に自動処理
|
| 48 |
-
input_image.change(
|
| 49 |
-
fn=create_depth_map,
|
| 50 |
-
inputs=input_image,
|
| 51 |
-
outputs=[output_original, output_depth]
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
gr.Markdown("""
|
| 55 |
-
### 📝 使い方
|
| 56 |
-
- 画像をアップロードすると自動で深度マップが生成されます
|
| 57 |
-
- 青=遠い部分、赤=近い部分
|
| 58 |
-
""")
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def create_depth_map(image):
|
| 4 |
+
"""画像処理: 元画像をそのまま返して接続テスト"""
|
| 5 |
if image is None:
|
| 6 |
return None, None
|
| 7 |
+
return image, image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# シンプルなGradio Interface
|
| 10 |
+
demo = gr.Interface(
|
| 11 |
+
fn=create_depth_map,
|
| 12 |
+
inputs=gr.Image(type="pil", label="入力画像"),
|
| 13 |
+
outputs=[
|
| 14 |
+
gr.Image(label="元画像"),
|
| 15 |
+
gr.Image(label="深度マップ")
|
| 16 |
+
],
|
| 17 |
+
title="🌊 深度推定 API",
|
| 18 |
+
description="画像をアップロードしてテスト"
|
| 19 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,3 +1 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
numpy
|
| 3 |
-
pillow
|
|
|
|
| 1 |
+
gradio
|
|
|
|
|
|