Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -23,38 +23,37 @@ if uploaded_file is not None:
|
|
23 |
image = Image.open(uploaded_file)
|
24 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
st.
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
# This could be extended with AR-based libraries or Unity integration in a full-scale app.
|
|
|
23 |
image = Image.open(uploaded_file)
|
24 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
25 |
|
26 |
+
# Add Generate button
|
27 |
+
if st.button("Generate"):
|
28 |
+
# Process image with DepthPro for depth estimation
|
29 |
+
inputs = image_processor(images=image, return_tensors="pt").to(device)
|
30 |
+
with torch.no_grad():
|
31 |
+
outputs = model(**inputs)
|
32 |
+
|
33 |
+
# Post-process depth output
|
34 |
+
post_processed_output = image_processor.post_process_depth_estimation(
|
35 |
+
outputs, target_sizes=[(image.height, image.width)],
|
36 |
+
)
|
37 |
+
|
38 |
+
depth = post_processed_output[0]["predicted_depth"]
|
39 |
+
depth = (depth - depth.min()) / (depth.max() - depth.min())
|
40 |
+
depth = depth * 255.
|
41 |
+
depth = depth.detach().cpu().numpy()
|
42 |
+
depth_image = Image.fromarray(depth.astype("uint8"))
|
43 |
+
|
44 |
+
st.subheader("Depth Map")
|
45 |
+
st.image(depth_image, caption="Estimated Depth Map", use_column_width=True)
|
46 |
+
|
47 |
+
# Colorize the depth map to make it more visible
|
48 |
+
colormap = depth_image.convert("RGB")
|
49 |
+
st.subheader("Colorized Depth Map")
|
50 |
+
st.image(colormap, caption="Colorized Depth Map", use_column_width=True)
|
51 |
+
|
52 |
+
# Option to save depth image
|
53 |
+
if st.button('Save Depth Image'):
|
54 |
+
depth_image.save('depth_image.png')
|
55 |
+
st.success("Depth image saved successfully!")
|
56 |
+
|
57 |
+
# Option for interactive painting (Placeholder)
|
58 |
+
st.subheader("Interactive Depth-based Painting (Demo Placeholder)")
|
59 |
+
st.write("This feature will allow users to paint on surfaces based on depth. For now, we can show the depth and its effects.")
|
|