Daniel Gatis 3 years ago
parent
commit
c4ec5ed09f
3 changed files with 19 additions and 8 deletions
  1. 5 2
      README.md
  2. 11 4
      rembg/cli.py
  3. 3 2
      requirements.txt

+ 5 - 2
README.md

@@ -34,8 +34,7 @@ Rembg is a tool to remove images background. That is it.
   <img src="https://raw.githubusercontent.com/danielgatis/rembg/master/examples/girl-3.out.png" width="100" />
 </p>
 
-#### *** If you want to remove background from videos try this this fork: https://github.com/ecsplendid/rembg-greenscreen ***
-
+**If this project has helped you in any way, please consider making a [donation](https://www.buymeacoffee.com/danielgatis).**
 
 ### Installation
 
@@ -167,6 +166,10 @@ curl -s http://input.png | rembg i -a -ae 15 > output.png
     </tbody>
 </table>
 
+### In the cloud
+
+Please contact me at [email protected] if you need help to put it on the cloud.
+
 ### References
 
 - https://arxiv.org/pdf/2005.09007.pdf

+ 11 - 4
rembg/cli.py

@@ -3,11 +3,13 @@ import sys
 from enum import Enum
 from typing import IO, Optional
 
+import aiohttp
 import click
 import filetype
 import onnxruntime as ort
 import requests
 import uvicorn
+from asyncer import asyncify
 from fastapi import Depends, FastAPI, File, Query
 from starlette.responses import Response
 from tqdm import tqdm
@@ -270,12 +272,17 @@ def s(port: int, log_level: str):
         )
 
     @app.get("/")
-    def get_index(url: str, commons: CommonQueryParams = Depends()):
-        return im_without_bg(requests.get(url).content, commons)
+    async def get_index(url: str, commons: CommonQueryParams = Depends()):
+        async with aiohttp.ClientSession() as session:
+            async with session.get(url) as response:
+                file = await response.read()
+                return await asyncify(im_without_bg)(file, commons)
 
     @app.post("/")
-    def post_index(file: bytes = File(...), commons: CommonQueryParams = Depends()):
-        return im_without_bg(file, commons)
+    async def post_index(
+        file: bytes = File(...), commons: CommonQueryParams = Depends()
+    ):
+        return await asyncify(im_without_bg)(file, commons)
 
     uvicorn.run(app, host="0.0.0.0", port=port, log_level=log_level)
 

+ 3 - 2
requirements.txt

@@ -1,3 +1,6 @@
+aiohttp==3.8.1
+asyncer==0.0.1
+click==8.0.3
 fastapi==0.72.0
 filetype==1.0.9
 gdown==4.2.0
@@ -5,9 +8,7 @@ numpy==1.22.1
 pillow==9.0.0
 pymatting==1.1.5
 python-multipart==0.0.5
-requests==2.27.1
 scikit-image==0.19.1
 scipy==1.7.3
 tqdm==4.62.3
 uvicorn==0.17.0
-click==8.0.3