fffiloni commited on
Commit
59299a4
1 Parent(s): cd9f57a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -66,17 +66,19 @@ def run_inference(temp_dir):
66
 
67
  def process_image(input_url):
68
  # Remove background
69
- removed_bg_path, temp_dir = remove_background(input_url)
 
 
 
70
 
71
- if isinstance(removed_bg_path, str) and removed_bg_path.startswith("Error"):
72
- return removed_bg_path
73
 
74
  # Run inference
75
  output_images = run_inference(temp_dir)
76
 
77
  if isinstance(output_images, str) and output_images.startswith("Error"):
78
  shutil.rmtree(temp_dir)
79
- return output_images
80
 
81
  # Prepare outputs for display
82
  results = []
 
66
 
67
  def process_image(input_url):
68
  # Remove background
69
+ result = remove_background(input_url)
70
+
71
+ if isinstance(result, str) and result.startswith("Error"):
72
+ raise gr.Error(f"{result}") # Return the error message if something went wrong
73
 
74
+ removed_bg_path, temp_dir = result # Unpack only if successful
 
75
 
76
  # Run inference
77
  output_images = run_inference(temp_dir)
78
 
79
  if isinstance(output_images, str) and output_images.startswith("Error"):
80
  shutil.rmtree(temp_dir)
81
+ raise gr.Error(f"{output_images}") # Return the error message if inference failed
82
 
83
  # Prepare outputs for display
84
  results = []