Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,15 +20,37 @@ def predict_depth(image):
|
|
| 20 |
-50, # Frame's near plane offset
|
| 21 |
api_name="/submit_depth_fn"
|
| 22 |
)
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Gradio Interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=predict_depth,
|
| 28 |
inputs=gr.Image(type='filepath', label="Upload your image"),
|
| 29 |
-
outputs=gr.Image(type='
|
| 30 |
title="Depth Map Generator",
|
| 31 |
-
description="Upload an image to receive a depth map."
|
| 32 |
)
|
| 33 |
|
| 34 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
-50, # Frame's near plane offset
|
| 21 |
api_name="/submit_depth_fn"
|
| 22 |
)
|
| 23 |
+
# Assuming the API returns a filepath or you save the result to a file
|
| 24 |
+
output_file_path = save_image_to_file(response['image']) # Implement this function based on your API's response
|
| 25 |
+
return output_file_path
|
| 26 |
|
| 27 |
# Gradio Interface
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=predict_depth,
|
| 30 |
inputs=gr.Image(type='filepath', label="Upload your image"),
|
| 31 |
+
outputs=gr.Image(type='filepath', label="Depth Map Image"),
|
| 32 |
title="Depth Map Generator",
|
| 33 |
+
description="Upload an image to receive a depth map file."
|
| 34 |
)
|
| 35 |
|
| 36 |
iface.launch()
|
| 37 |
+
|
| 38 |
+
def save_image_to_file(image_data):
|
| 39 |
+
# Assuming 'image_data' is the image data in a compatible format
|
| 40 |
+
# You would save the image to a file and return the path
|
| 41 |
+
import matplotlib.pyplot as plt
|
| 42 |
+
import matplotlib.image as mpimg
|
| 43 |
+
import numpy as np
|
| 44 |
+
import tempfile
|
| 45 |
+
import os
|
| 46 |
+
|
| 47 |
+
# Create a temporary file
|
| 48 |
+
fd, path = tempfile.mkstemp(suffix=".png")
|
| 49 |
+
try:
|
| 50 |
+
# Assume image_data is a numpy array
|
| 51 |
+
img = np.array(image_data).astype(np.uint8)
|
| 52 |
+
plt.imsave(path, img)
|
| 53 |
+
finally:
|
| 54 |
+
os.close(fd)
|
| 55 |
+
|
| 56 |
+
return path
|