Spaces:
Runtime error
Runtime error
TK156
commited on
Commit
·
7ef81f1
1
Parent(s):
6767397
fix: 最小限構成でSpace復旧
Browse files- gradioのみの依存関係
- 最もシンプルなInterface
- 画像をそのまま返すテスト
- エラー原因を除去
- app.py +16 -105
- requirements.txt +1 -3
app.py
CHANGED
|
@@ -1,112 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import io
|
| 5 |
-
import base64
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
"""
|
| 9 |
if image is None:
|
| 10 |
return None, None
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
max_size = 512
|
| 15 |
-
original_size = image.size
|
| 16 |
-
if max(original_size) > max_size:
|
| 17 |
-
ratio = max_size / max(original_size)
|
| 18 |
-
new_size = (int(original_size[0] * ratio), int(original_size[1] * ratio))
|
| 19 |
-
image = image.resize(new_size, Image.Resampling.LANCZOS)
|
| 20 |
-
|
| 21 |
-
# RGB変換(必要に応じて)
|
| 22 |
-
if image.mode != 'RGB':
|
| 23 |
-
image = image.convert('RGB')
|
| 24 |
-
|
| 25 |
-
# 高品質グラデーション深度マップ生成
|
| 26 |
-
img_array = np.array(image)
|
| 27 |
-
height, width = img_array.shape[:2]
|
| 28 |
-
|
| 29 |
-
# マルチレイヤー深度マップ
|
| 30 |
-
depth_map = np.zeros((height, width, 3), dtype=np.uint8)
|
| 31 |
-
|
| 32 |
-
# 垂直グラデーション + ノイズ効果
|
| 33 |
-
for y in range(height):
|
| 34 |
-
ratio = y / height
|
| 35 |
-
noise = np.random.normal(0, 0.05, width) # 軽微なノイズ
|
| 36 |
-
depth_ratio = np.clip(ratio + noise, 0, 1)
|
| 37 |
-
|
| 38 |
-
# より自然な色遷移
|
| 39 |
-
depth_map[y, :, 0] = (255 * depth_ratio).astype(np.uint8) # 赤
|
| 40 |
-
depth_map[y, :, 1] = (128 * (1 - depth_ratio * 0.5)).astype(np.uint8) # 緑
|
| 41 |
-
depth_map[y, :, 2] = (255 * (1 - depth_ratio)).astype(np.uint8) # 青
|
| 42 |
-
|
| 43 |
-
depth_image = Image.fromarray(depth_map)
|
| 44 |
-
|
| 45 |
-
return image, depth_image
|
| 46 |
-
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"Error in depth estimation: {e}")
|
| 49 |
-
return image, image
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
</div>
|
| 63 |
-
""")
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
with gr.Column(scale=1):
|
| 67 |
-
input_image = gr.Image(
|
| 68 |
-
label="📸 入力画像",
|
| 69 |
-
type="pil",
|
| 70 |
-
height=300
|
| 71 |
-
)
|
| 72 |
-
gr.HTML("""
|
| 73 |
-
<div style="margin-top: 10px; font-size: 12px; color: #666;">
|
| 74 |
-
📋 対応形式: JPEG, PNG, WebP<br>
|
| 75 |
-
⚡ 最大サイズ: 512px (自動最適化)
|
| 76 |
-
</div>
|
| 77 |
-
""")
|
| 78 |
-
|
| 79 |
-
with gr.Column(scale=2):
|
| 80 |
-
with gr.Tabs():
|
| 81 |
-
with gr.Tab("🖼️ 元画像"):
|
| 82 |
-
output_original = gr.Image(label="元画像", height=300)
|
| 83 |
-
with gr.Tab("🗺️ 深度マップ"):
|
| 84 |
-
output_depth = gr.Image(label="深度マップ", height=300)
|
| 85 |
-
|
| 86 |
-
# リアルタイム処理
|
| 87 |
-
input_image.change(
|
| 88 |
-
fn=create_optimized_depth_map,
|
| 89 |
-
inputs=input_image,
|
| 90 |
-
outputs=[output_original, output_depth],
|
| 91 |
-
show_progress="minimal" # パフォーマンス向上
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
gr.HTML("""
|
| 95 |
-
<div style="margin-top: 20px; padding: 15px; background: #f0f8ff; border-radius: 8px;">
|
| 96 |
-
<h3>📝 使用方法</h3>
|
| 97 |
-
<ul>
|
| 98 |
-
<li>🔵 <strong>青色</strong>: 遠い距離の物体</li>
|
| 99 |
-
<li>🔴 <strong>赤色</strong>: 近い距離の物体</li>
|
| 100 |
-
<li>⚡ 画像は自動で最適サイズに調整されます</li>
|
| 101 |
-
<li>🎯 リアルタイム処理で瞬時に結果表示</li>
|
| 102 |
-
</ul>
|
| 103 |
-
</div>
|
| 104 |
-
""")
|
| 105 |
|
| 106 |
-
|
| 107 |
-
demo.launch(
|
| 108 |
-
server_name="0.0.0.0",
|
| 109 |
-
server_port=7860,
|
| 110 |
-
show_error=True,
|
| 111 |
-
quiet=False
|
| 112 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def depth_estimation(image):
|
| 4 |
+
"""最もシンプルな深度推定テスト"""
|
| 5 |
if image is None:
|
| 6 |
return None, None
|
| 7 |
|
| 8 |
+
# まずは画像をそのまま返すテスト
|
| 9 |
+
return image, image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# 最小限のGradio Interface
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
fn=depth_estimation,
|
| 14 |
+
inputs=gr.Image(type="pil"),
|
| 15 |
+
outputs=[
|
| 16 |
+
gr.Image(label="元画像"),
|
| 17 |
+
gr.Image(label="深度マップ")
|
| 18 |
+
],
|
| 19 |
+
title="深度推定 API",
|
| 20 |
+
description="テスト中"
|
| 21 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
numpy
|
| 3 |
-
pillow
|
|
|
|
| 1 |
+
gradio
|
|
|
|
|
|