Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from transformers import AutoModelForImageSegmentation
|
|
4 |
from PIL import Image
|
5 |
from torchvision import transforms
|
6 |
import gradio as gr
|
7 |
-
import os
|
8 |
|
9 |
# Load the model from Hugging Face
|
10 |
birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/BiRefNet_lite', trust_remote_code=True)
|
@@ -20,9 +19,9 @@ transform_image = transforms.Compose([
|
|
20 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
21 |
])
|
22 |
|
23 |
-
def extract_objects(
|
24 |
-
# Open all images from the uploaded
|
25 |
-
images = [Image.open(
|
26 |
|
27 |
start_time = time.time()
|
28 |
inputs = []
|
@@ -64,7 +63,7 @@ def extract_objects(files):
|
|
64 |
f"Total request time: {total_time:.2f} s\n"
|
65 |
f"Inference time (batch): {inference_time:.2f} s\n"
|
66 |
f"Pre/Post-processing time: {prep_post_time:.2f} s\n"
|
67 |
-
"Per-image post-processing times:\n" +
|
68 |
"\n".join([f" Image {i+1}: {t:.2f} s" for i, t in enumerate(image_times)])
|
69 |
)
|
70 |
|
@@ -72,7 +71,7 @@ def extract_objects(files):
|
|
72 |
|
73 |
iface = gr.Interface(
|
74 |
fn=extract_objects,
|
75 |
-
inputs=gr.Files(label="Upload Multiple Images", type="
|
76 |
outputs=[gr.Gallery(label="Processed Images"), gr.Textbox(label="Timing Info")],
|
77 |
title="BiRefNet Bulk Background Removal",
|
78 |
description="Upload multiple images and process them in one request. Timing information for the full request and per-image processing is provided."
|
|
|
4 |
from PIL import Image
|
5 |
from torchvision import transforms
|
6 |
import gradio as gr
|
|
|
7 |
|
8 |
# Load the model from Hugging Face
|
9 |
birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/BiRefNet_lite', trust_remote_code=True)
|
|
|
19 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
20 |
])
|
21 |
|
22 |
+
def extract_objects(filepaths):
|
23 |
+
# Open all images from the uploaded file paths
|
24 |
+
images = [Image.open(path).convert("RGB") for path in filepaths]
|
25 |
|
26 |
start_time = time.time()
|
27 |
inputs = []
|
|
|
63 |
f"Total request time: {total_time:.2f} s\n"
|
64 |
f"Inference time (batch): {inference_time:.2f} s\n"
|
65 |
f"Pre/Post-processing time: {prep_post_time:.2f} s\n"
|
66 |
+
"Per-image post-processing times:\n" +
|
67 |
"\n".join([f" Image {i+1}: {t:.2f} s" for i, t in enumerate(image_times)])
|
68 |
)
|
69 |
|
|
|
71 |
|
72 |
iface = gr.Interface(
|
73 |
fn=extract_objects,
|
74 |
+
inputs=gr.Files(label="Upload Multiple Images", type="filepath", file_count="multiple"),
|
75 |
outputs=[gr.Gallery(label="Processed Images"), gr.Textbox(label="Timing Info")],
|
76 |
title="BiRefNet Bulk Background Removal",
|
77 |
description="Upload multiple images and process them in one request. Timing information for the full request and per-image processing is provided."
|