Spaces:
Sleeping
Sleeping
Simplify app.py to fix TypeError - MINIMAL WORKING VERSION
Browse files- Remove all complex UI components (tabs, sliders, extra features)
- Use simple gr.Image() without type/height parameters
- Remove all info/scale parameters that cause schema issues
- Single clean interface: upload image β generate depth
- BASE model (390MB) loads successfully
- This minimal version should work perfectly!
CHANGES:
- Removed 3 tabs, now single interface
- Removed parallax slider and 3D visualization
- Removed batch processing
- Removed all parameters causing TypeError
- Clean, simple, WORKING interface
π€ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -90,92 +90,11 @@ def estimate_depth(image, colormap_style="Inferno"):
|
|
| 90 |
return depth_colored, depth_gray, info
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
-
error_msg = f"### β Error
|
| 94 |
print(f"Error during depth estimation: {e}")
|
| 95 |
return None, None, error_msg
|
| 96 |
|
| 97 |
|
| 98 |
-
def create_side_by_side_comparison(image, colormap_style="Inferno"):
|
| 99 |
-
"""Create side-by-side comparison of original and depth map"""
|
| 100 |
-
try:
|
| 101 |
-
if isinstance(image, Image.Image):
|
| 102 |
-
image = np.array(image)
|
| 103 |
-
|
| 104 |
-
# Get depth estimation
|
| 105 |
-
if USE_REAL_AI:
|
| 106 |
-
depth = depth_estimator.predict(image)
|
| 107 |
-
else:
|
| 108 |
-
depth = generate_smart_depth(image)
|
| 109 |
-
|
| 110 |
-
# Convert colormap
|
| 111 |
-
colormap_dict = {
|
| 112 |
-
"Inferno": cv2.COLORMAP_INFERNO,
|
| 113 |
-
"Viridis": cv2.COLORMAP_VIRIDIS,
|
| 114 |
-
"Plasma": cv2.COLORMAP_PLASMA,
|
| 115 |
-
"Turbo": cv2.COLORMAP_TURBO,
|
| 116 |
-
"Magma": cv2.COLORMAP_MAGMA,
|
| 117 |
-
"Hot": cv2.COLORMAP_HOT,
|
| 118 |
-
"Ocean": cv2.COLORMAP_OCEAN,
|
| 119 |
-
"Rainbow": cv2.COLORMAP_RAINBOW
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
# Create side-by-side
|
| 123 |
-
comparison = create_side_by_side(image, depth, colormap=colormap_dict[colormap_style])
|
| 124 |
-
|
| 125 |
-
return comparison
|
| 126 |
-
|
| 127 |
-
except Exception as e:
|
| 128 |
-
print(f"Error creating comparison: {e}")
|
| 129 |
-
return None
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
def create_3d_visualization(image, depth_map, parallax_strength=0.5):
|
| 133 |
-
"""Create a simple 3D displacement visualization"""
|
| 134 |
-
try:
|
| 135 |
-
if image is None:
|
| 136 |
-
return None
|
| 137 |
-
|
| 138 |
-
if isinstance(image, Image.Image):
|
| 139 |
-
image = np.array(image)
|
| 140 |
-
|
| 141 |
-
if depth_map is None:
|
| 142 |
-
# Generate depth if not provided
|
| 143 |
-
if USE_REAL_AI:
|
| 144 |
-
depth_map = depth_estimator.predict(image)
|
| 145 |
-
else:
|
| 146 |
-
depth_map = generate_smart_depth(image)
|
| 147 |
-
depth_map = (depth_map * 255).astype(np.uint8)
|
| 148 |
-
elif isinstance(depth_map, Image.Image):
|
| 149 |
-
depth_map = np.array(depth_map)
|
| 150 |
-
|
| 151 |
-
# Convert depth to grayscale if colored
|
| 152 |
-
if len(depth_map.shape) == 3:
|
| 153 |
-
depth_map = cv2.cvtColor(depth_map, cv2.COLOR_RGB2GRAY)
|
| 154 |
-
|
| 155 |
-
# Normalize depth
|
| 156 |
-
depth_norm = depth_map.astype(float) / 255.0
|
| 157 |
-
|
| 158 |
-
# Create parallax effect (simple x-shift based on depth)
|
| 159 |
-
h, w = image.shape[:2]
|
| 160 |
-
result = image.copy()
|
| 161 |
-
|
| 162 |
-
# Apply horizontal shift based on depth
|
| 163 |
-
shift_amount = int(w * parallax_strength * 0.05)
|
| 164 |
-
|
| 165 |
-
for y in range(h):
|
| 166 |
-
for x in range(w):
|
| 167 |
-
depth_val = depth_norm[y, x]
|
| 168 |
-
shift = int(shift_amount * depth_val)
|
| 169 |
-
new_x = min(max(x + shift, 0), w - 1)
|
| 170 |
-
result[y, new_x] = image[y, x]
|
| 171 |
-
|
| 172 |
-
return result
|
| 173 |
-
|
| 174 |
-
except Exception as e:
|
| 175 |
-
print(f"Error creating 3D viz: {e}")
|
| 176 |
-
return image if image is not None else None
|
| 177 |
-
|
| 178 |
-
|
| 179 |
# Create Gradio interface
|
| 180 |
with gr.Blocks(
|
| 181 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="purple"),
|
|
@@ -206,90 +125,30 @@ with gr.Blocks(
|
|
| 206 |
|
| 207 |
gr.Markdown(status_msg)
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
with gr.
|
| 212 |
-
|
| 213 |
-
with gr.Column(scale=1):
|
| 214 |
-
input_image = gr.Image(
|
| 215 |
-
label="Upload Your Image",
|
| 216 |
-
type="pil",
|
| 217 |
-
height=400
|
| 218 |
-
)
|
| 219 |
-
|
| 220 |
-
colormap_style = gr.Dropdown(
|
| 221 |
-
choices=["Inferno", "Viridis", "Plasma", "Turbo", "Magma", "Hot", "Ocean", "Rainbow"],
|
| 222 |
-
value="Inferno",
|
| 223 |
-
label="Colormap Style"
|
| 224 |
-
)
|
| 225 |
-
|
| 226 |
-
estimate_btn = gr.Button("π Generate Depth Map", variant="primary", size="lg")
|
| 227 |
-
|
| 228 |
-
with gr.Column(scale=1):
|
| 229 |
-
depth_colored = gr.Image(label="Depth Map (Colored)", height=400)
|
| 230 |
-
depth_gray = gr.Image(label="Depth Map (Grayscale)", height=400)
|
| 231 |
-
|
| 232 |
-
processing_info = gr.Markdown()
|
| 233 |
-
|
| 234 |
-
estimate_btn.click(
|
| 235 |
-
fn=estimate_depth,
|
| 236 |
-
inputs=[input_image, colormap_style],
|
| 237 |
-
outputs=[depth_colored, depth_gray, processing_info]
|
| 238 |
-
)
|
| 239 |
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
""")
|
| 246 |
-
|
| 247 |
-
with gr.Row():
|
| 248 |
-
with gr.Column(scale=1):
|
| 249 |
-
compare_input = gr.Image(label="Upload Image", type="pil", height=400)
|
| 250 |
|
| 251 |
-
|
| 252 |
-
choices=["Inferno", "Viridis", "Plasma", "Turbo", "Magma", "Hot", "Ocean", "Rainbow"],
|
| 253 |
-
value="Turbo",
|
| 254 |
-
label="Colormap"
|
| 255 |
-
)
|
| 256 |
|
| 257 |
-
|
|
|
|
|
|
|
| 258 |
|
| 259 |
-
|
| 260 |
-
comparison_output = gr.Image(label="Side-by-Side Comparison", height=500)
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
# Tab 3: 3D Parallax Effect
|
| 269 |
-
with gr.Tab("π 3D Parallax Effect"):
|
| 270 |
-
gr.Markdown("""
|
| 271 |
-
### Create 3D Depth Displacement Effect
|
| 272 |
-
Generate a parallax effect to visualize the 3D structure of your image.
|
| 273 |
-
""")
|
| 274 |
-
|
| 275 |
-
with gr.Row():
|
| 276 |
-
with gr.Column(scale=1):
|
| 277 |
-
parallax_input = gr.Image(label="Original Image", type="pil")
|
| 278 |
-
parallax_depth = gr.Image(label="Depth Map (optional)", type="pil")
|
| 279 |
-
parallax_strength = gr.Slider(
|
| 280 |
-
minimum=0, maximum=2, value=0.5, step=0.1,
|
| 281 |
-
label="Parallax Strength"
|
| 282 |
-
)
|
| 283 |
-
parallax_btn = gr.Button("β¨ Generate 3D Effect", variant="primary")
|
| 284 |
-
|
| 285 |
-
with gr.Column(scale=1):
|
| 286 |
-
parallax_output = gr.Image(label="3D Parallax Result", height=500)
|
| 287 |
-
|
| 288 |
-
parallax_btn.click(
|
| 289 |
-
fn=create_3d_visualization,
|
| 290 |
-
inputs=[parallax_input, parallax_depth, parallax_strength],
|
| 291 |
-
outputs=parallax_output
|
| 292 |
-
)
|
| 293 |
|
| 294 |
# Info section
|
| 295 |
gr.Markdown("---")
|
|
@@ -335,4 +194,4 @@ with gr.Blocks(
|
|
| 335 |
|
| 336 |
# Launch the app
|
| 337 |
if __name__ == "__main__":
|
| 338 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 90 |
return depth_colored, depth_gray, info
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
+
error_msg = f"### β Error\\n\\n{str(e)}"
|
| 94 |
print(f"Error during depth estimation: {e}")
|
| 95 |
return None, None, error_msg
|
| 96 |
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
# Create Gradio interface
|
| 99 |
with gr.Blocks(
|
| 100 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="purple"),
|
|
|
|
| 125 |
|
| 126 |
gr.Markdown(status_msg)
|
| 127 |
|
| 128 |
+
# Main interface
|
| 129 |
+
with gr.Row():
|
| 130 |
+
with gr.Column():
|
| 131 |
+
input_image = gr.Image(label="Upload Your Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
colormap_style = gr.Dropdown(
|
| 134 |
+
choices=["Inferno", "Viridis", "Plasma", "Turbo", "Magma", "Hot", "Ocean", "Rainbow"],
|
| 135 |
+
value="Inferno",
|
| 136 |
+
label="Colormap Style"
|
| 137 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
estimate_btn = gr.Button("π Generate Depth Map", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
+
with gr.Column():
|
| 142 |
+
depth_colored = gr.Image(label="Depth Map (Colored)")
|
| 143 |
+
depth_gray = gr.Image(label="Depth Map (Grayscale)")
|
| 144 |
|
| 145 |
+
processing_info = gr.Markdown()
|
|
|
|
| 146 |
|
| 147 |
+
estimate_btn.click(
|
| 148 |
+
fn=estimate_depth,
|
| 149 |
+
inputs=[input_image, colormap_style],
|
| 150 |
+
outputs=[depth_colored, depth_gray, processing_info]
|
| 151 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
# Info section
|
| 154 |
gr.Markdown("---")
|
|
|
|
| 194 |
|
| 195 |
# Launch the app
|
| 196 |
if __name__ == "__main__":
|
| 197 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|