Spaces:
Sleeping
Sleeping
ascarlettvfx
commited on
Commit
•
1491886
1
Parent(s):
e7f42e5
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio_client import Client,
|
3 |
|
4 |
def predict_depth(image):
|
5 |
-
client = Client("prs-eth/marigold")
|
6 |
-
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
1, # Ensemble size
|
11 |
-
10, # Number of denoising steps
|
12 |
-
"0", # Processing resolution
|
13 |
-
file('path_to_sample_file_1.pdf'), # Sample file path for depth (16-bit)
|
14 |
-
file('path_to_sample_file_2.pdf'), # Sample file path for depth (32-bit)
|
15 |
-
file('path_to_sample_file_3.pdf'), # Sample file path for depth (color)
|
16 |
-
0.5, # Relative position of the near plane
|
17 |
-
0.9, # Relative position of the far plane
|
18 |
-
10, # Embossing level
|
19 |
-
2, # Smoothing filter size
|
20 |
-
-50, # Frame's near plane offset
|
21 |
api_name="/submit_depth_fn"
|
22 |
)
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
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.
|
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
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client, handle_file
|
3 |
|
4 |
def predict_depth(image):
|
5 |
+
client = Client("prs-eth/marigold")
|
6 |
+
|
7 |
+
# Prepare the API call with the necessary parameters
|
8 |
+
result = client.predict(
|
9 |
+
handle_file(image), # Image file path
|
10 |
+
1, # Example value for 'Ensemble size'
|
11 |
+
10, # Example value for 'Number of denoising steps'
|
12 |
+
"0", # Processing resolution choice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
api_name="/submit_depth_fn"
|
14 |
)
|
15 |
+
|
16 |
+
# Process the API response assuming it directly returns a file path for the depth map
|
17 |
+
if result and result[0]: # Assuming the API returns the image path as the first item in a tuple
|
18 |
+
output_file_path = result[0] # Directly use the returned file path
|
19 |
+
return output_file_path # Return the path to the output file for download
|
20 |
+
return "No depth output available"
|
21 |
|
22 |
# Gradio Interface
|
23 |
iface = gr.Interface(
|
24 |
fn=predict_depth,
|
25 |
inputs=gr.Image(type='filepath', label="Upload your image"),
|
26 |
+
outputs=gr.File(label="Download Depth Map"),
|
27 |
title="Depth Map Generator",
|
28 |
description="Upload an image to receive a depth map file."
|
29 |
)
|
30 |
|
31 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|