全新基于fastapi设计japi的架构
0
.env.example
Normal file
0
Dockerfile
Normal file
0
app/__init__.py
Normal file
0
app/api/__init__.py
Normal file
0
app/api/deps.py
Normal file
0
app/api/v1/__init__.py
Normal file
0
app/api/v1/endpoints/__init__.py
Normal file
0
app/api/v1/endpoints/items.py
Normal file
0
app/api/v1/endpoints/users.py
Normal file
0
app/api/v1/router.py
Normal file
0
app/core/__init__.py
Normal file
0
app/core/config.py
Normal file
0
app/core/logging.py
Normal file
0
app/core/security.py
Normal file
0
app/main.py
Normal file
0
app/middleware/__init__.py
Normal file
0
app/middleware/auth.py
Normal file
0
app/middleware/logging.py
Normal file
0
app/schemas/__init__.py
Normal file
0
app/schemas/base.py
Normal file
0
app/schemas/request.py
Normal file
0
app/services/backend/__init__.py
Normal file
0
app/services/jingrow/__init__.py
Normal file
0
app/services/jingrow/auth.py
Normal file
0
app/services/jingrow/billing.py
Normal file
0
app/services/jingrow/client.py
Normal file
0
app/utils/__init__.py
Normal file
0
app/utils/utils.py
Normal file
0
docker-compose.yml
Normal file
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
8
requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
requests>=2.31.0
|
||||
Pillow>=10.0.0
|
||||
torch>=2.0.0
|
||||
transformers>=4.30.0
|
||||
fastapi>=0.104.0
|
||||
uvicorn>=0.23.2
|
||||
python-multipart>=0.0.6
|
||||
pydantic>=2.4.2
|
||||
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 1005 KiB |
@ -1,4 +0,0 @@
|
||||
requests>=2.31.0
|
||||
Pillow>=10.0.0
|
||||
torch>=2.0.0
|
||||
transformers>=4.30.0
|
||||
106
task/rmbg.py
@ -1,106 +0,0 @@
|
||||
import os
|
||||
import gradio as gr
|
||||
from gradio_imageslider import ImageSlider
|
||||
from loadimg import load_img
|
||||
import spaces
|
||||
from transformers import AutoModelForImageSegmentation
|
||||
import torch
|
||||
from torchvision import transforms
|
||||
|
||||
torch.set_float32_matmul_precision(["high", "highest"][0])
|
||||
|
||||
birefnet = AutoModelForImageSegmentation.from_pretrained(
|
||||
"briaai/RMBG-2.0", trust_remote_code=True
|
||||
)
|
||||
birefnet.to("cuda")
|
||||
transform_image = transforms.Compose(
|
||||
[
|
||||
transforms.Resize((1024, 1024)),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
||||
]
|
||||
)
|
||||
|
||||
output_folder = 'output_images'
|
||||
if not os.path.exists(output_folder):
|
||||
os.makedirs(output_folder)
|
||||
|
||||
def fn(image):
|
||||
im = load_img(image, output_type="pil")
|
||||
im = im.convert("RGB")
|
||||
origin = im.copy()
|
||||
image = process(im)
|
||||
image_path = os.path.join(output_folder, "no_bg_image.png")
|
||||
image.save(image_path)
|
||||
return (image, origin), image_path
|
||||
|
||||
@spaces.GPU
|
||||
def process(image):
|
||||
image_size = image.size
|
||||
input_images = transform_image(image).unsqueeze(0).to("cuda")
|
||||
# Prediction
|
||||
with torch.no_grad():
|
||||
preds = birefnet(input_images)[-1].sigmoid().cpu()
|
||||
pred = preds[0].squeeze()
|
||||
pred_pil = transforms.ToPILImage()(pred)
|
||||
mask = pred_pil.resize(image_size)
|
||||
image.putalpha(mask)
|
||||
return image
|
||||
|
||||
def process_file(f):
|
||||
name_path = f.rsplit(".",1)[0]+".png"
|
||||
im = load_img(f, output_type="pil")
|
||||
im = im.convert("RGB")
|
||||
transparent = process(im)
|
||||
transparent.save(name_path)
|
||||
return name_path
|
||||
|
||||
slider1 = ImageSlider(label="RMBG-2.0", type="pil")
|
||||
slider2 = ImageSlider(label="RMBG-2.0", type="pil")
|
||||
image = gr.Image(label="Upload an image")
|
||||
image2 = gr.Image(label="Upload an image",type="filepath")
|
||||
text = gr.Textbox(label="Paste an image URL")
|
||||
png_file = gr.File(label="output png file")
|
||||
|
||||
|
||||
chameleon = load_img("giraffe.jpg", output_type="pil")
|
||||
|
||||
url = "http://farm9.staticflickr.com/8488/8228323072_76eeddfea3_z.jpg"
|
||||
|
||||
tab1 = gr.Interface(
|
||||
fn, inputs=image, outputs=[slider1, gr.File(label="output png file")], examples=[chameleon], api_name="image"
|
||||
)
|
||||
|
||||
tab2 = gr.Interface(fn, inputs=text, outputs=[slider2, gr.File(label="output png file")], examples=[url], api_name="text")
|
||||
tab3 = gr.Interface(process_file, inputs=image2, outputs=png_file, examples=["giraffe.jpg"], api_name="png")
|
||||
|
||||
|
||||
demo = gr.TabbedInterface(
|
||||
[tab1, tab2], ["input image", "input url"], title = (
|
||||
"RMBG-2.0 for background removal <br>"
|
||||
"<span style='font-size:16px; font-weight:300;'>"
|
||||
"Background removal model developed by "
|
||||
"<a href='https://bria.ai' target='_blank'>BRIA.AI</a>, trained on a carefully selected dataset,<br> "
|
||||
"and is available as an open-source model for non-commercial use.</span><br>"
|
||||
"<span style='font-size:16px; font-weight:500;'> For testing upload your image and wait.<br>"
|
||||
"<a href='https://go.bria.ai/3ZCBTLH' target='_blank'>Commercial use license</a> | "
|
||||
"<a href='https://huggingface.co/briaai/RMBG-2.0' target='_blank'>Model card</a> | "
|
||||
"<a href='https://blog.bria.ai/brias-new-state-of-the-art-remove-background-2.0-outperforms-the-competition' target='_blank'>Blog</a>"
|
||||
"</span><br>"
|
||||
"<span style='font-size:16px; font-weight:300;'>"
|
||||
"API Endpoint available on: "
|
||||
"<a href='https://platform.bria.ai/console/api/image-editing' target='_blank'>Bria.ai</a>, "
|
||||
"<a href='https://fal.ai/models/fal-ai/bria/background/remove' target='_blank'>fal.ai</a><br>"
|
||||
"ComfyUI node is available here: "
|
||||
"<a href='https://github.com/Bria-AI/ComfyUI-BRIA-API' target='_blank'>ComfyUI Node</a><br>"
|
||||
"Purchase commercial weigths for commercial use: "
|
||||
"<a href='https://go.bria.ai/3D5EGp0' target='_blank'>here</a>"
|
||||
"</span>"
|
||||
)
|
||||
|
||||
|
||||
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.launch(show_error=True)
|
||||