Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import os
|
|
8 |
OUTPUT_DIR = "outputs"
|
9 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
10 |
|
11 |
-
# Funzione per rimozione sfondo
|
12 |
def remove_background(image: Image.Image):
|
13 |
if image is None:
|
14 |
return None, None
|
@@ -18,7 +18,7 @@ def remove_background(image: Image.Image):
|
|
18 |
output.save(output_path)
|
19 |
return output, output_path
|
20 |
|
21 |
-
# Carica immagini dalla cartella
|
22 |
GALLERY_DIR = "gallery"
|
23 |
gallery_files = sorted([
|
24 |
os.path.join(GALLERY_DIR, f)
|
@@ -34,7 +34,7 @@ def load_gallery_image(evt: gr.SelectData):
|
|
34 |
return Image.open(image_path)
|
35 |
return None
|
36 |
|
37 |
-
# Interfaccia
|
38 |
with gr.Blocks(title="Rimozione Sfondo") as demo:
|
39 |
demo.css = """
|
40 |
#orange-button {
|
@@ -43,20 +43,20 @@ with gr.Blocks(title="Rimozione Sfondo") as demo:
|
|
43 |
}
|
44 |
"""
|
45 |
|
46 |
-
gr.Markdown("#
|
47 |
-
gr.Markdown("Carica un'immagine o
|
48 |
|
49 |
with gr.Row():
|
50 |
image_input = gr.Image(label="Immagine", type="pil", sources=["upload", "webcam"])
|
51 |
-
gallery = gr.Gallery(label="Galleria
|
52 |
|
53 |
output_image = gr.Image(type="pil", label="Risultato")
|
54 |
-
output_file = gr.File(label="Scarica
|
55 |
|
56 |
-
#
|
57 |
gallery.select(fn=load_gallery_image, outputs=image_input)
|
58 |
|
59 |
-
btn = gr.Button("Rimuovi Sfondo", elem_id="orange-button")
|
60 |
btn.click(fn=remove_background, inputs=image_input, outputs=[output_image, output_file])
|
61 |
|
62 |
if __name__ == "__main__":
|
|
|
8 |
OUTPUT_DIR = "outputs"
|
9 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
10 |
|
11 |
+
# Funzione per la rimozione dello sfondo
|
12 |
def remove_background(image: Image.Image):
|
13 |
if image is None:
|
14 |
return None, None
|
|
|
18 |
output.save(output_path)
|
19 |
return output, output_path
|
20 |
|
21 |
+
# Carica le immagini dalla cartella gallery
|
22 |
GALLERY_DIR = "gallery"
|
23 |
gallery_files = sorted([
|
24 |
os.path.join(GALLERY_DIR, f)
|
|
|
34 |
return Image.open(image_path)
|
35 |
return None
|
36 |
|
37 |
+
# Interfaccia di gradio con i css per il bottone
|
38 |
with gr.Blocks(title="Rimozione Sfondo") as demo:
|
39 |
demo.css = """
|
40 |
#orange-button {
|
|
|
43 |
}
|
44 |
"""
|
45 |
|
46 |
+
gr.Markdown("# Rimuovi lo sfondo dalla tua immagine")
|
47 |
+
gr.Markdown("Carica un'immagine personale, cattura un'immagine dalla tua webcam o scegline una dalla galleria.")
|
48 |
|
49 |
with gr.Row():
|
50 |
image_input = gr.Image(label="Immagine", type="pil", sources=["upload", "webcam"])
|
51 |
+
gallery = gr.Gallery(label="Galleria immagini", value=gallery_files, columns=5, rows=1, height="auto")
|
52 |
|
53 |
output_image = gr.Image(type="pil", label="Risultato")
|
54 |
+
output_file = gr.File(label="Scarica il file")
|
55 |
|
56 |
+
# Seleziona un'immagine dalla galleria
|
57 |
gallery.select(fn=load_gallery_image, outputs=image_input)
|
58 |
|
59 |
+
btn = gr.Button("Rimuovi lo Sfondo", elem_id="orange-button")
|
60 |
btn.click(fn=remove_background, inputs=image_input, outputs=[output_image, output_file])
|
61 |
|
62 |
if __name__ == "__main__":
|