Spaces:
Sleeping
Sleeping
ascarlettvfx
commited on
Commit
•
c9aa520
1
Parent(s):
80345dd
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio_client import Client,
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
import io
|
@@ -8,27 +8,33 @@ import tempfile
|
|
8 |
def process_image(image):
|
9 |
client = Client("prs-eth/marigold")
|
10 |
|
11 |
-
#
|
12 |
-
if isinstance(image, np.ndarray):
|
13 |
-
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
14 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpeg") as tmp:
|
15 |
image.save(tmp, format='JPEG')
|
16 |
-
tmp_path = tmp.name
|
17 |
|
18 |
-
# Call the API with necessary parameters
|
19 |
result = client.predict(
|
20 |
-
|
21 |
20, # Ensemble size
|
22 |
-
10, #
|
23 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
api_name="/submit_depth_fn"
|
25 |
)
|
26 |
|
27 |
# Handle the returned file path for the depth image
|
28 |
if result and 'depth_outputs' in result:
|
29 |
-
|
30 |
-
|
31 |
-
depth_image
|
32 |
return depth_image
|
33 |
else:
|
34 |
return "No depth output received or error in processing"
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client, file
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
import io
|
|
|
8 |
def process_image(image):
|
9 |
client = Client("prs-eth/marigold")
|
10 |
|
11 |
+
# Save the uploaded image temporarily
|
|
|
|
|
12 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpeg") as tmp:
|
13 |
image.save(tmp, format='JPEG')
|
14 |
+
tmp_path = tmp.name
|
15 |
|
16 |
+
# Call the API with necessary parameters
|
17 |
result = client.predict(
|
18 |
+
file(tmp_path), # filepath for 'Input Image' Image component
|
19 |
20, # Ensemble size
|
20 |
+
10, # Number of denoising steps
|
21 |
+
"0", # Processing resolution
|
22 |
+
file(tmp_path), # Placeholder for 'Predicted depth (16-bit)'
|
23 |
+
file(tmp_path), # Placeholder for 'Predicted depth (32-bit)'
|
24 |
+
file(tmp_path), # Placeholder for 'Predicted depth (red-near, blue-far)'
|
25 |
+
0, # Relative position of the near plane
|
26 |
+
0, # Relative position of the far plane
|
27 |
+
0, # Embossing level
|
28 |
+
1, # Size of the smoothing filter
|
29 |
+
-100, # Frame's near plane offset
|
30 |
api_name="/submit_depth_fn"
|
31 |
)
|
32 |
|
33 |
# Handle the returned file path for the depth image
|
34 |
if result and 'depth_outputs' in result:
|
35 |
+
depth_image_path = result['depth_outputs'][0] # Assuming the result is a local path to the image
|
36 |
+
depth_image = Image.open(depth_image_path)
|
37 |
+
depth_image.load() # Ensure the image is loaded completely
|
38 |
return depth_image
|
39 |
else:
|
40 |
return "No depth output received or error in processing"
|