Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"[Errno 13] Permission denied" build safetensors via api /faceswaplab/build #84

Open
godsgo opened this issue Aug 31, 2023 · 1 comment

Comments

@godsgo
Copy link

godsgo commented Aug 31, 2023

Hello, thankyou for greate job, but i have some trouble with api, when i build safetensors via /faceswaplab/build server, send me error
"[Errno 13] Permission denied" model has created but not save, only save preview PNG file with swaped face in D:\SD_port\tmp\ folder

I use portable version of automatic1111 can you help me?

there are error code from automatic console
`2023-08-31 06:33:15,525 - FaceSwapLab - STATUS - Build api_ckpt with 7 images
2023-08-31 06:33:18,487 - FaceSwapLab - STATUS - Source Gender 0
2023-08-31 06:33:18,496 - FaceSwapLab - STATUS - Target faces count : 1
2023-08-31 06:33:18,497 - FaceSwapLab - STATUS - swap face 0
2023-08-31 06:33:19,019 - FaceSwapLab - STATUS - ********************************************************************************
2023-08-31 06:33:19,029 - FaceSwapLab - STATUS - Inswapper
2023-08-31 06:33:19,033 - FaceSwapLab - STATUS - Upscale with Lanczos scale = 4
2023-08-31 06:33:19,039 - FaceSwapLab - STATUS - Restore face with CodeFormer
2023-08-31 06:33:19,508 - FaceSwapLab - STATUS - sharpen
2023-08-31 06:33:19,511 - FaceSwapLab - STATUS - improved_mask
2023-08-31 06:33:19,577 - FaceSwapLab - STATUS - ********************************************************************************
2023-08-31 06:33:19,716 - FaceSwapLab - ERROR - Error loading checkpoint, after creation could not open file <D:\SD_port\tmp\tmp4gpb3bvj.safetensors> in read-only mode; error code: <32>
Traceback (most recent call last):
File "D:\SD_port\extensions\sd-webui-faceswaplab\scripts\faceswaplab_swapping\face_checkpoints.py", line 129, in build_face_checkpoint_and_save
data = load_face(file_path)
File "D:\SD_port\extensions\sd-webui-faceswaplab\scripts\faceswaplab_swapping\face_checkpoints.py", line 194, in load_face
with safe_open(filename, framework="pt", device="cpu") as f:
RuntimeError: could not open file <D:\SD_port\tmp\tmp4gpb3bvj.safetensors> in read-only mode; error code: <32>
D:\SD_port\tmp\tmp4gpb3bvj.safetensors
*** API error: POST: http://127.0.0.1:7860/faceswaplab/build {'error': 'PermissionError', 'detail': '', 'body': '', 'errors': "[Errno 13] Permission denied: 'D:\\SD_port\\tmp\\tmp4gpb3bvj.safetensors'"}
Traceback (most recent call last):
File "D:\SD_port\venv\lib\site-packages\anyio\streams\memory.py", line 94, in receive
return self.receive_nowait()
File "D:\SD_port\venv\lib\site-packages\anyio\streams\memory.py", line 89, in receive_nowait
raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\base.py", line 78, in call_next
    message = await recv_stream.receive()
  File "D:\SD_port\venv\lib\site-packages\anyio\streams\memory.py", line 114, in receive
    raise EndOfStream
anyio.EndOfStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\SD_port\modules\api\api.py", line 152, in exception_handling
    return await call_next(request)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
    raise app_exc
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\base.py", line 108, in __call__
    response = await self.dispatch_func(request, call_next)
  File "D:\SD_port\modules\api\api.py", line 116, in log_and_time
    res: Response = await call_next(req)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
    raise app_exc
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "D:\SD_port\venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "D:\SD_port\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
    raise e
  File "D:\SD_port\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "D:\SD_port\venv\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "D:\SD_port\venv\lib\site-packages\starlette\routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "D:\SD_port\venv\lib\site-packages\starlette\routing.py", line 66, in app
    response = await func(request)
  File "D:\SD_port\venv\lib\site-packages\fastapi\routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "D:\SD_port\venv\lib\site-packages\fastapi\routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "D:\SD_port\extensions\sd-webui-faceswaplab\scripts\faceswaplab_api\faceswaplab_api.py", line 161, in build
    return api_utils.safetensors_to_base64(temp_file.name)
  File "D:\SD_port\extensions\sd-webui-faceswaplab\client_api\api_utils.py", line 275, in safetensors_to_base64
    file_bytes = file.read()
PermissionError: [Errno 13] Permission denied: 'D:\\SD_port\\tmp\\tmp4gpb3bvj.safetensors'`
@godsgo
Copy link
Author

godsgo commented Aug 31, 2023

i test your code and safetensors file is created, but only if i change path or name of file. My test stop at safetensors_to_base64 in api_utils.py i am sorry i am newbie, "safetensors_to_base64" cannot open file

file was deleted by 'tempfile' i set to delete=False and it work, code in faceswaplab_api.py

@app.post( "/faceswaplab/build", tags=["faceswaplab"], description="Build a face checkpoint using base64 images, return base64 satetensors", ) async def build(base64_images: List[str]) -> Optional[str]: if len(base64_images) > 0: pil_images = [base64_to_pil(img) for img in base64_images] with tempfile.NamedTemporaryFile( **delete=True,** suffix=".safetensors" ) as temp_file: build_face_checkpoint_and_save( images=pil_images, name="api_ckpt", overwrite=True, path=temp_file.name, ) return api_utils.safetensors_to_base64(temp_file.name) return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant