codic commited on
Commit
ca2bd17
·
verified ·
1 Parent(s): 35db94c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -25,7 +25,18 @@ def process_image(image_path, depth_map_path=None):
25
 
26
  # Handle background removal via Gradio Client using file path (as string)
27
  result = client.predict(str(image_path), api_name="/png") # Convert to string
28
- subject_image = Image.open(result[0]) # Processed PNG with transparent background
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  if depth_map_path:
31
  # Load and resize the user-provided depth map to match the RGB image size
 
25
 
26
  # Handle background removal via Gradio Client using file path (as string)
27
  result = client.predict(str(image_path), api_name="/png") # Convert to string
28
+
29
+ # Check the result to determine how to handle it
30
+ if isinstance(result, list) and len(result) > 0:
31
+ # If the first element is a path or a URL, handle it accordingly
32
+ if isinstance(result[0], str):
33
+ subject_image = Image.open(result[0]) # Attempt to open as file path
34
+ else:
35
+ # If it's not a string, assume it's binary data
36
+ subject_image = Image.open(BytesIO(result[0])) # Use BytesIO to open image data
37
+ else:
38
+ print("Unexpected result format:", result)
39
+ return None
40
 
41
  if depth_map_path:
42
  # Load and resize the user-provided depth map to match the RGB image size