resemble-ai / resemble-enhance

AI powered speech denoising and enhancement
https://huggingface.co/spaces/ResembleAI/resemble-enhance
MIT License
1.09k stars 103 forks source link

Windows posixpath error #9

Open SoftologyPro opened 6 months ago

SoftologyPro commented 6 months ago

Setup a test environment (voc_resembleenhance) and started the UI. Weeb page opens. I select a noisy wav and it opens and plays OK. Then when I click Submit the UI shows Error in both output spots. I get this posixpath error on the command line. Linux specific? Any fix for Windows?

Traceback (most recent call last):
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\queueing.py", line 456, in call_prediction
    output = await route_utils.call_process_api(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\route_utils.py", line 232, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\blocks.py", line 1522, in process_api
    result = await self.call_function(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\blocks.py", line 1144, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\anyio\_backends\_asyncio.py", line 2134, in run_sync_in_worker_thread
    return await future
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\anyio\_backends\_asyncio.py", line 851, in run
    result = context.run(func, *args)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\utils.py", line 674, in wrapper
    response = f(*args, **kwargs)
  File "D:\Tests\Resemble Enhance\app.py", line 24, in _fn
    wav1, new_sr = denoise(dwav, sr, device)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "D:\Tests\Resemble Enhance\resemble_enhance\enhancer\inference.py", line 29, in denoise
    enhancer = load_enhancer(run_dir, device)
  File "D:\Tests\Resemble Enhance\resemble_enhance\enhancer\inference.py", line 17, in load_enhancer
    hp = HParams.load(run_dir)
  File "D:\Tests\Resemble Enhance\resemble_enhance\hparams.py", line 109, in load
    hps.append(cls.from_yaml(run_dir / "hparams.yaml"))
  File "D:\Tests\Resemble Enhance\resemble_enhance\hparams.py", line 94, in from_yaml
    return cls(**dict(OmegaConf.merge(cls(), OmegaConf.load(path))))
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\omegaconf\omegaconf.py", line 190, in load
    obj = yaml.load(f, Loader=get_yaml_loader())
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\__init__.py", line 81, in load
    return loader.get_single_data()
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 51, in get_single_data
    return self.construct_document(node)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 60, in construct_document
    for dummy in generator:
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\omegaconf\_utils.py", line 151, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 143, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 100, in construct_object
    data = constructor(self, node)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\omegaconf\_utils.py", line 183, in <lambda>
    lambda loader, node: pathlib.PosixPath(*loader.construct_sequence(node)),
  File "D:\Python\lib\pathlib.py", line 962, in __new__
    raise NotImplementedError("cannot instantiate %r on your system"
NotImplementedError: cannot instantiate 'PosixPath' on your system
Traceback (most recent call last):
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\queueing.py", line 456, in call_prediction
    output = await route_utils.call_process_api(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\route_utils.py", line 232, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\blocks.py", line 1522, in process_api
    result = await self.call_function(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\blocks.py", line 1144, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\anyio\_backends\_asyncio.py", line 2134, in run_sync_in_worker_thread
    return await future
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\anyio\_backends\_asyncio.py", line 851, in run
    result = context.run(func, *args)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\utils.py", line 674, in wrapper
    response = f(*args, **kwargs)
  File "D:\Tests\Resemble Enhance\app.py", line 24, in _fn
    wav1, new_sr = denoise(dwav, sr, device)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "D:\Tests\Resemble Enhance\resemble_enhance\enhancer\inference.py", line 29, in denoise
    enhancer = load_enhancer(run_dir, device)
  File "D:\Tests\Resemble Enhance\resemble_enhance\enhancer\inference.py", line 17, in load_enhancer
    hp = HParams.load(run_dir)
  File "D:\Tests\Resemble Enhance\resemble_enhance\hparams.py", line 109, in load
    hps.append(cls.from_yaml(run_dir / "hparams.yaml"))
  File "D:\Tests\Resemble Enhance\resemble_enhance\hparams.py", line 94, in from_yaml
    return cls(**dict(OmegaConf.merge(cls(), OmegaConf.load(path))))
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\omegaconf\omegaconf.py", line 190, in load
    obj = yaml.load(f, Loader=get_yaml_loader())
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\__init__.py", line 81, in load
    return loader.get_single_data()
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 51, in get_single_data
    return self.construct_document(node)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 60, in construct_document
    for dummy in generator:
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\omegaconf\_utils.py", line 151, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 143, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\yaml\constructor.py", line 100, in construct_object
    data = constructor(self, node)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\omegaconf\_utils.py", line 183, in <lambda>
    lambda loader, node: pathlib.PosixPath(*loader.construct_sequence(node)),
  File "D:\Python\lib\pathlib.py", line 962, in __new__
    raise NotImplementedError("cannot instantiate %r on your system"
NotImplementedError: cannot instantiate 'PosixPath' on your system

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\queueing.py", line 501, in process_events
    response = await self.call_prediction(awake_events, batch)
  File "D:\Tests\Resemble Enhance\voc_resembleenhance\lib\site-packages\gradio\queueing.py", line 465, in call_prediction
    raise Exception(str(error) if show_error else None) from error
Katehuuh commented 6 months ago

Same pathlib module problem PosixPath on Windows.

darkzbaron commented 6 months ago

Got it working using by modifying site-packages\omegaconf_utils.py

1) Insert from pathlib import Path 2) Replace line 184 with lambda loader, node: Path(*loader.construct_sequence(node)),

Please adjust the code so that it works on windows without the fix.

Also, you can find deepspeed wheel on that repo fom @daswer123 https://github.com/daswer123/resemble-enhance-windows/

SoftologyPro commented 6 months ago
1. Insert `from pathlib import Path`

2. Replace line 184 with `lambda loader, node: Path(*loader.construct_sequence(node)),`

Can we get this as an official fix for a future version? Although modifying anything under site-packages means the end user needs to do it once the environment is setup.

FoxBuchele commented 3 weeks ago

I've discovered the 'core issue' here - there's nothing actually wrong with the code. The fix mentioned above will technically allow it to work, but patches over the problem.

The real issue is in a completely separate repo: https://huggingface.co/ResembleAI/resemble-enhance/blob/main/enhancer_stage2/hparams.yaml

It's caused by this PosixPath suffix, in the hparams.yaml file in that repo, highlighted in the image below.

image

Explanation:

The resemble-enhance repo on huggingface linked above is downloaded to the system when the enhancer is run:

https://github.com/resemble-ai/resemble-enhance/blob/d1c1e4b12f1577869d8c11ad7345b31f2f281814/resemble_enhance/enhancer/download.py#L22

However, the hparams.yaml in the hf repo specifies that the path MUST be a PosixPath path, instead of 'Path', which just picks based on your OS.

The good news: The fix for this is pretty easy, and doesn't require any special programming knowledge!

Windows Fix:

  1. Open the folder where resemble_enhance is located (depending on how you have it installed - though you should clone the source at this point if you haven't yet - then install it from wherever you cloned the repo with 'pip install -e').
  2. Open the 'model_repo' directory (next to data, denoiser, enhancer, and utils folder - doesn't exist in the repo and is created at runtime when the model is downloaded - if you don't see this folder yet, attempt to enhance some audio, wait for it to error, then check again and the folder should exist)
  3. Inside you should see an 'enhancer_stage2' directory. Open that directory.
  4. Open hparams.yaml
  5. Change the three instances of 'PosixPath' to 'Path'.
  6. Save hparams.yaml

Enjoy! 🥳

I've made a pull request on huggingface.

https://huggingface.co/ResembleAI/resemble-enhance/discussions/3