sab commited on
Commit
e01ff34
1 Parent(s): 37755b5
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -13,6 +13,10 @@ from dotenv import load_dotenv
13
  # Carica le variabili di ambiente dal file .env
14
  load_dotenv()
15
 
 
 
 
 
16
  def numpy_to_pil(image):
17
  """Convert a numpy array to a PIL Image."""
18
  if image.dtype == np.uint8: # Most common case
@@ -34,7 +38,10 @@ def process_image(image):
34
  result = response.json()
35
  processed_image_b64 = result["processed_image"]
36
  processed_image = Image.open(BytesIO(base64.b64decode(processed_image_b64)))
37
- return [image, processed_image] # Return the original and processed images
 
 
 
38
 
39
 
40
  # Carica l'esempio di immagine
@@ -45,7 +52,7 @@ output_slider = ImageSlider(label="Processed photo", type="pil")
45
  demo = gr.Interface(
46
  fn=process_image,
47
  inputs=image,
48
- outputs=output_slider,
49
  title="Magic Eraser",
50
  examples=[["elephant.jpg"]] # Esempio locale
51
  )
 
13
  # Carica le variabili di ambiente dal file .env
14
  load_dotenv()
15
 
16
+ output_folder = 'output_images'
17
+ if not os.path.exists(output_folder):
18
+ os.makedirs(output_folder)
19
+
20
  def numpy_to_pil(image):
21
  """Convert a numpy array to a PIL Image."""
22
  if image.dtype == np.uint8: # Most common case
 
38
  result = response.json()
39
  processed_image_b64 = result["processed_image"]
40
  processed_image = Image.open(BytesIO(base64.b64decode(processed_image_b64)))
41
+ #return [image, processed_image] # Return the original and processed image
42
+ image_path = os.path.join(output_folder, "no_bg_image.png")
43
+ processed_image.save(image_path)
44
+ return (processed_image, image), image_path
45
 
46
 
47
  # Carica l'esempio di immagine
 
52
  demo = gr.Interface(
53
  fn=process_image,
54
  inputs=image,
55
+ outputs=[output_slider, gr.File(label="output png file")],
56
  title="Magic Eraser",
57
  examples=[["elephant.jpg"]] # Esempio locale
58
  )