ascarlettvfx commited on
Commit
c9aa520
1 Parent(s): 80345dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from gradio_client import Client, handle_file
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
- # Convert the PIL Image or numpy array to bytes and save temporarily
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 # Get the path of the saved file
17
 
18
- # Call the API with necessary parameters using the file path
19
  result = client.predict(
20
- handle_file(tmp_path), # Pass the file path
21
  20, # Ensemble size
22
- 10, # Denoising steps
23
- "recommended", # Processing resolution
 
 
 
 
 
 
 
 
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
- depth_image_url = result['depth_outputs'][0] # Assuming the result is a URL to the image
30
- response = requests.get(depth_image_url) # Download the image
31
- depth_image = Image.open(io.BytesIO(response.content))
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"