codic commited on
Commit
13e279a
·
verified ·
1 Parent(s): c455f34

fixing the handel error

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -20,20 +20,26 @@ feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
20
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
21
  background_removal_client = Client("not-lain/background-removal")
22
 
23
- def remove_background_with_api(image):
24
- # Step 1: Use the `not-lain/background-removal` API
25
- result_url = background_removal_client.predict(
26
- f=handle_file(image),
 
 
 
 
 
 
27
  api_name="/png"
28
  )
29
-
30
  # Step 2: Download the image returned by the API
31
  response = requests.get(result_url)
32
  foreground = Image.open(BytesIO(response.content)).convert("RGBA")
33
-
34
  # Step 3: Apply `rmbg` for additional cleanup
35
  cleaned_foreground = remove(foreground)
36
-
37
  return Image.fromarray(np.array(cleaned_foreground)).convert("RGB")
38
 
39
  def process_image(image_path, depth_map_path=None):
 
20
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
21
  background_removal_client = Client("not-lain/background-removal")
22
 
23
+
24
+ def remove_background(image):
25
+ # Convert the PIL image to a byte stream
26
+ img_bytes = BytesIO()
27
+ image.save(img_bytes, format="PNG")
28
+ img_bytes.seek(0)
29
+
30
+ # Step 1: Remove background using the Gradio API
31
+ result_url = bg_removal_client.predict(
32
+ f=img_bytes,
33
  api_name="/png"
34
  )
35
+
36
  # Step 2: Download the image returned by the API
37
  response = requests.get(result_url)
38
  foreground = Image.open(BytesIO(response.content)).convert("RGBA")
39
+
40
  # Step 3: Apply `rmbg` for additional cleanup
41
  cleaned_foreground = remove(foreground)
42
+
43
  return Image.fromarray(np.array(cleaned_foreground)).convert("RGB")
44
 
45
  def process_image(image_path, depth_map_path=None):