shukdevdatta123 commited on
Commit
d959f41
·
verified ·
1 Parent(s): 67a6705

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -35
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
- # Process image with DepthPro for depth estimation
27
- inputs = image_processor(images=image, return_tensors="pt").to(device)
28
- with torch.no_grad():
29
- outputs = model(**inputs)
30
-
31
- # Post-process depth output
32
- post_processed_output = image_processor.post_process_depth_estimation(
33
- outputs, target_sizes=[(image.height, image.width)],
34
- )
35
-
36
- depth = post_processed_output[0]["predicted_depth"]
37
- depth = (depth - depth.min()) / (depth.max() - depth.min())
38
- depth = depth * 255.
39
- depth = depth.detach().cpu().numpy()
40
- depth_image = Image.fromarray(depth.astype("uint8"))
41
-
42
- st.subheader("Depth Map")
43
- st.image(depth_image, caption="Estimated Depth Map", use_column_width=True)
44
-
45
- # Colorize the depth map to make it more visible
46
- colormap = depth_image.convert("RGB")
47
- st.subheader("Colorized Depth Map")
48
- st.image(colormap, caption="Colorized Depth Map", use_column_width=True)
49
-
50
- # Option to save depth image
51
- if st.button('Save Depth Image'):
52
- depth_image.save('depth_image.png')
53
- st.success("Depth image saved successfully!")
54
-
55
- # Option for interactive painting (Placeholder)
56
- st.subheader("Interactive Depth-based Painting (Demo Placeholder)")
57
- st.write("This feature will allow users to paint on surfaces based on depth. For now, we can show the depth and its effects.")
58
-
59
- # Placeholder for future interactive painting functionality.
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.")