user-agent commited on
Commit
1a1c89b
·
verified ·
1 Parent(s): 461565d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -31,18 +31,18 @@ def process(image: Image.Image) -> Image.Image:
31
  input_tensor = transform_image(image).unsqueeze(0).to(device)
32
 
33
  with torch.no_grad():
34
- # RMBG v1.4 returns a tuple, we need the first element
35
  preds = model(input_tensor)
36
 
37
- # Handle different return types
38
- if isinstance(preds, tuple):
39
- pred = preds[0] # Take first element if tuple
40
- elif isinstance(preds, list):
41
- pred = preds[-1] # Take last element if list
 
42
  else:
43
  pred = preds
44
 
45
- # Apply sigmoid and move to CPU
46
  mask = pred.sigmoid().cpu()
47
 
48
  # Process the mask
@@ -91,7 +91,6 @@ def handler(image=None, image_url=None, batch_urls=None) -> Union[str, List[str]
91
 
92
  except Exception as e:
93
  print("General error:", e)
94
- # Add debug info
95
  import traceback
96
  traceback.print_exc()
97
 
 
31
  input_tensor = transform_image(image).unsqueeze(0).to(device)
32
 
33
  with torch.no_grad():
 
34
  preds = model(input_tensor)
35
 
36
+ # Handle list output - extract the tensor from the list
37
+ if isinstance(preds, list):
38
+ # Usually the mask is the last or first element
39
+ pred = preds[-1] if len(preds) > 0 else preds[0]
40
+ elif isinstance(preds, tuple):
41
+ pred = preds[0]
42
  else:
43
  pred = preds
44
 
45
+ # Now apply sigmoid to the tensor
46
  mask = pred.sigmoid().cpu()
47
 
48
  # Process the mask
 
91
 
92
  except Exception as e:
93
  print("General error:", e)
 
94
  import traceback
95
  traceback.print_exc()
96