github-actions[bot] commited on
Commit ·
e429bd1
1
Parent(s): b4c840d
Deploy from GitHub Actions: 384de8fb9abdf39acb6709c3d26936ede947d83d
Browse files- Dockerfile +4 -3
- package.json +2 -2
- src/download_model.py +4 -0
- main.py → src/main.py +5 -2
Dockerfile
CHANGED
|
@@ -3,7 +3,6 @@ FROM python:3.13-slim
|
|
| 3 |
ENV PORT=7860
|
| 4 |
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
-
libgl1 \
|
| 7 |
libglib2.0-0 \
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
|
@@ -21,10 +20,12 @@ COPY --chown=user requirements.txt requirements.txt
|
|
| 21 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 22 |
pip install --no-cache-dir -r requirements.txt
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
COPY --chown=user . $HOME/app
|
| 27 |
|
| 28 |
EXPOSE ${PORT}
|
| 29 |
|
| 30 |
-
CMD ["/bin/sh", "-c", "exec uvicorn main:app --host 0.0.0.0 --port $PORT"]
|
|
|
|
| 3 |
ENV PORT=7860
|
| 4 |
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
| 6 |
libglib2.0-0 \
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
|
|
|
| 20 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 21 |
pip install --no-cache-dir -r requirements.txt
|
| 22 |
|
| 23 |
+
COPY --chown=user src/download_model.py src/download_model.py
|
| 24 |
+
|
| 25 |
+
RUN python src/download_model.py
|
| 26 |
|
| 27 |
COPY --chown=user . $HOME/app
|
| 28 |
|
| 29 |
EXPOSE ${PORT}
|
| 30 |
|
| 31 |
+
CMD ["/bin/sh", "-c", "exec uvicorn src.main:app --host 0.0.0.0 --port $PORT"]
|
package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
| 3 |
"version": "0.0.1",
|
| 4 |
"private": true,
|
| 5 |
"scripts": {
|
| 6 |
-
"dev": "venv\\Scripts\\activate && uvicorn main:app --reload --port 8000",
|
| 7 |
-
"start": "source venv/bin/activate && uvicorn main:app --port 8000",
|
| 8 |
"setup": "pip install -r requirements.txt"
|
| 9 |
}
|
| 10 |
}
|
|
|
|
| 3 |
"version": "0.0.1",
|
| 4 |
"private": true,
|
| 5 |
"scripts": {
|
| 6 |
+
"dev": "venv\\Scripts\\activate && uvicorn src.main:app --reload --port 8000",
|
| 7 |
+
"start": "source venv/bin/activate && uvicorn src.main:app --port 8000",
|
| 8 |
"setup": "pip install -r requirements.txt"
|
| 9 |
}
|
| 10 |
}
|
src/download_model.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rembg import new_session
|
| 2 |
+
|
| 3 |
+
if __name__ == "__main__":
|
| 4 |
+
new_session("birefnet-general")
|
main.py → src/main.py
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File, Response, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
-
from rembg import remove
|
| 4 |
from PIL import Image, UnidentifiedImageError
|
| 5 |
import io
|
| 6 |
import os
|
|
@@ -11,6 +11,9 @@ logger = logging.getLogger(__name__)
|
|
| 11 |
|
| 12 |
app = FastAPI(title="NoBG API")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
origins = os.getenv("ALLOWED_ORIGINS", "*").split(",")
|
| 15 |
|
| 16 |
app.add_middleware(
|
|
@@ -32,7 +35,7 @@ def remove_background(file: UploadFile = File(...)):
|
|
| 32 |
|
| 33 |
try:
|
| 34 |
input_image = Image.open(file.file)
|
| 35 |
-
output_image = remove(input_image)
|
| 36 |
img_byte_arr = io.BytesIO()
|
| 37 |
output_image.save(img_byte_arr, format="PNG")
|
| 38 |
img_byte_arr.seek(0)
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File, Response, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from rembg import remove, new_session
|
| 4 |
from PIL import Image, UnidentifiedImageError
|
| 5 |
import io
|
| 6 |
import os
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI(title="NoBG API")
|
| 13 |
|
| 14 |
+
model_name = "birefnet-general"
|
| 15 |
+
session = new_session(model_name)
|
| 16 |
+
|
| 17 |
origins = os.getenv("ALLOWED_ORIGINS", "*").split(",")
|
| 18 |
|
| 19 |
app.add_middleware(
|
|
|
|
| 35 |
|
| 36 |
try:
|
| 37 |
input_image = Image.open(file.file)
|
| 38 |
+
output_image = remove(input_image, session=session)
|
| 39 |
img_byte_arr = io.BytesIO()
|
| 40 |
output_image.save(img_byte_arr, format="PNG")
|
| 41 |
img_byte_arr.seek(0)
|