cleanup
Browse files- app.py +0 -9
- background_removal.py +0 -29
app.py
CHANGED
@@ -11,8 +11,6 @@ from base_utils import (
|
|
11 |
parse_url,
|
12 |
)
|
13 |
|
14 |
-
# from background_removal import remove_bg
|
15 |
-
|
16 |
pdf_to_img = gr.Interface(
|
17 |
convert_pdf_to_image, gr.File(), gr.Gallery(), api_name="pdf_to_img"
|
18 |
)
|
@@ -69,12 +67,6 @@ url_parser = gr.Interface(
|
|
69 |
api_name="url_to_text",
|
70 |
)
|
71 |
|
72 |
-
# rmbg = gr.Interface(
|
73 |
-
# remove_bg,
|
74 |
-
# inputs=["image"],
|
75 |
-
# outputs=["image"],
|
76 |
-
# api_name="rmbg",
|
77 |
-
# )
|
78 |
|
79 |
demo = gr.TabbedInterface(
|
80 |
[
|
@@ -97,7 +89,6 @@ demo = gr.TabbedInterface(
|
|
97 |
"Extract PPTX Text",
|
98 |
"Extract text from URL",
|
99 |
"Extract Json",
|
100 |
-
# "Remove Background",
|
101 |
],
|
102 |
)
|
103 |
|
|
|
11 |
parse_url,
|
12 |
)
|
13 |
|
|
|
|
|
14 |
pdf_to_img = gr.Interface(
|
15 |
convert_pdf_to_image, gr.File(), gr.Gallery(), api_name="pdf_to_img"
|
16 |
)
|
|
|
67 |
api_name="url_to_text",
|
68 |
)
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
demo = gr.TabbedInterface(
|
72 |
[
|
|
|
89 |
"Extract PPTX Text",
|
90 |
"Extract text from URL",
|
91 |
"Extract Json",
|
|
|
92 |
],
|
93 |
)
|
94 |
|
background_removal.py
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
import spaces
|
2 |
-
from loadimg import load_img
|
3 |
-
import torch
|
4 |
-
from torchvision import transforms
|
5 |
-
# Load BiRefNet with weights
|
6 |
-
from transformers import AutoModelForImageSegmentation
|
7 |
-
birefnet = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet', trust_remote_code=True)
|
8 |
-
|
9 |
-
@spaces.GPU
|
10 |
-
def remove_bg(imagepath):
|
11 |
-
# Data settings
|
12 |
-
image_size = (1024, 1024)
|
13 |
-
transform_image = transforms.Compose([
|
14 |
-
transforms.Resize(image_size),
|
15 |
-
transforms.ToTensor(),
|
16 |
-
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
17 |
-
])
|
18 |
-
|
19 |
-
image = load_img(imagepath).convert("RGB")
|
20 |
-
input_images = transform_image(image).unsqueeze(0).to('cuda')
|
21 |
-
|
22 |
-
# Prediction
|
23 |
-
with torch.no_grad():
|
24 |
-
preds = birefnet(input_images)[-1].sigmoid().cpu()
|
25 |
-
pred = preds[0].squeeze()
|
26 |
-
pred_pil = transforms.ToPILImage()(pred)
|
27 |
-
mask = pred_pil.resize(image.size)
|
28 |
-
image.putalpha(mask)
|
29 |
-
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|