brilam / remove-bg Goto Github PK
View Code? Open in Web Editor NEWA Python API wrapper for removing background using remove.bg's API
License: MIT License
A Python API wrapper for removing background using remove.bg's API
License: MIT License
when running rembg s
cmd it throws this error
also I have installed websocket
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Python310\Scripts\rembg.exe_main.py", line 7, in
File "C:\Python310\lib\site-packages\click\core.py", line 1130, in call
return self.main(*args, **kwargs)
File "C:\Python310\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Python310\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Python310\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Python310\lib\site-packages\click\core.py", line 760, in invoke
return _callback(*args, **kwargs)
File "C:\Python310\lib\site-packages\rembg\cli.py", line 419, in s
uvicorn.run(app, host="0.0.0.0", port=port, log_level=log_level)
File "C:\Python310\lib\site-packages\uvicorn\main.py", line 576, in run
server.run()
File "C:\Python310\lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "C:\Python310\lib\site-packages\uvicorn\server.py", line 67, in serve
config.load()
File "C:\Python310\lib\site-packages\uvicorn\config.py", line 471, in load
ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])
File "C:\Python310\lib\site-packages\uvicorn\importer.py", line 24, in import_from_string
raise exc from None
File "C:\Python310\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Python310\lib\importlib_init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\Python310\lib\site-packages\uvicorn\protocols\websockets\auto.py", line 17, in
from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol
File "C:\Python310\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 9, in
from websockets.datastructures import Headers
ModuleNotFoundError: No module named 'websockets.datastructures'
Hi, i am looking for some features that API provides, but this library doesn't. Would you merge my pull request? Thanks.
What if i want to apply it on a all images in a folder?!
Hi, I'm trying to use the removebg package as part of my camera capture python script. My question is if I have to keep requesting new API Key everytime I run the script? Thanks
File "C:\Theodore\programFiles\Python27\Lib\site-packages\removebg_init_.py", line 1, in
from removebg.removebg import RemoveBg
ImportError: No module named removebg
【Solution】
change the package path in init.py can correct it.
from removebg.removebg import RemoveBg =>
from .removebg import RemoveBg
Does this library support zip format as the image output? Let me know so that i can contribute something
Add a func in removebg.py:
def remove_background_and_save_img(self, img_file_path,save_path, size="regular", bg_color=None):
"""
Removes the background given an image file and outputs the file as the original file name with "no_bg.png"
appended to it.
:param img_file_path: the path to the image file
:param size: the size of the output image (regular = 0.25 MP, hd = 4 MP, 4k = up to 10 MP)
"""
# Open image file to send information post request and send the post request
img_file = open(img_file_path, 'rb')
response = requests.post(
API_ENDPOINT,
files={'image_file': img_file},
data={
'size': size,
'bg_color': bg_color
},
headers={'X-Api-Key': self.__api_key})
response.raise_for_status()
# print(f'input_file:{img_file.name}')
st1=img_file.name.split('.')[0]
st2=st1.split("/")[-1]
# print(f'st2:{st2}')
save_path=os.path.join(save_path,st2)
print('save bg removed',save_path)
self.__output_file__(response, save_path + "_no_bg.png")
firstly, works well. After weekends,it report:" requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.remove.bg/v1.0/removebg "
Could u pls tell why
I tried to use "new_file_name" to define the output path like,
rmbg.remove_background_from_img_file(img_file_path=img_p, new_file_name=out_path)
but it shows me this error. What is the problem?
What's the difference between auto
, full
, and 4k
of size param?
Looking forward to adding the ability to add a background color
It does't make a img file in my Linux
It doesn't seem to work?
from removebg import RemoveBg
rmbg = RemoveBg("CYoE87mDaDA9jcb3nKSHG5c7", "error.log") # 引号内是你获取的API
rmbg.remove_background_from_img_file("bus.jpg",bg_color="green") #图片地址
The code can be executed, but the generated picture cannot be opened, how to solve it, thank you!
sir, can you give me an example of new_file_name
use online API ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.