Skip to content

Commit

Permalink
Merge pull request #75 from kwokster10/add-support-for-custom-home-dir
Browse files Browse the repository at this point in the history
Add support for custom home dir
  • Loading branch information
plemeri authored Aug 22, 2024
2 parents 7926cd2 + cb2afde commit 7a9bd3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ You need to install `zenity` to open files and directories on Linux
sudo apt install zenity
```

### Install `transperent-background`
### Install `transparent-background`
* Note: please specify `extra-index-url` as below if you want to use gpu, particularly on Windows.
#### Install from `pypi`
```bash
Expand All @@ -90,7 +90,7 @@ pip install --extra-index-url https://download.pytorch.org/whl/cu118 transparent
pip install transparent-background[webcam] # with webcam dependency
```

#### Install from github
#### Install from Github
```bash
pip install --extra-index-url https://download.pytorch.org/whl/cu118 git+https://github.com/plemeri/transparent-background.git
```
Expand All @@ -102,11 +102,24 @@ cd transparent-backbround
pip --extra-index-url https://download.pytorch.org/whl/cu118 install .
```

#### Install CPU version only
```bash
# On Windows
pip install transparent-background
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio

# On Linux
pip install transparent-background
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
```

### [New] Configuration

`transparent-background` now supports external configuration rather than hard coded assets (e.g., checkpoint download url).
* The config file will be added in your home directory `~/.transparent-background/config.yaml`
* You may change the `url` argument to your google drive download link. (Please note that only google drive is supported.)
* The config file will be added in your home directory `~/.transparent-background/config.yaml` by default. The directory location can be customized by setting the desired file path under the environment variable `TRANSPARENT_BACKGROUND_FILE_PATH`.
* You may change the `url` argument to your Google Drive download link. (Please note that only Google Drive is supported.)
* You may change the `md5` argument to your file's md5 checksum. Or, set `md5` to `NULL` to skip verification.
* You may add `http_proxy` argument to specify the proxy address as you need. If your internet connection is behind a HTTP proxy (e.g. `http://192.168.1.80:8080`), you can set this argument. (Contributed by [bombless](https://github.com/bombless))
```yaml
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
with open("README.md", "r", encoding='utf-8') as fh:
long_description = fh.read()

os.makedirs(os.path.join(os.path.abspath(os.path.expanduser('~')), '.transparent-background'), exist_ok=True)
shutil.copyfile('figures/logo.png', os.path.join(os.path.abspath(os.path.expanduser('~')), '.transparent-background', 'logo.png'))

file_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
os.makedirs(os.path.join(file_path, '.transparent-background'), exist_ok=True)
shutil.copyfile('figures/logo.png', os.path.join(file_path, '.transparent-background', 'logo.png'))

setuptools.setup(
name="transparent-background",
Expand Down
3 changes: 2 additions & 1 deletion transparent_background/Remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self, mode="base", jit=False, device=None, ckpt=None, fast=None):
ckpt (str, optional): specifying model checkpoint. find downloaded checkpoint or try download if not specified.
fast (bool, optional, DEPRECATED): replaced by mode argument. use fast mode if True.
"""
home_dir = os.path.expanduser(os.path.join("~", ".transparent-background"))
file_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
home_dir = os.path.join(file_path, ".transparent-background")
os.makedirs(home_dir, exist_ok=True)

if not os.path.isfile(os.path.join(home_dir, "config.yaml")):
Expand Down
13 changes: 8 additions & 5 deletions transparent_background/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'abort':False,
}


def main(page):
def theme_changed(e):
page.theme_mode = (
Expand Down Expand Up @@ -72,7 +73,6 @@ def color_changed(e):
output_text.value = 'Type: {}, Mode: {}, Device: {}'.format(options['output_type'], options['color'], options['device'])
page.update()


def pick_files_result(e: FilePickerResultEvent):
file_path.update()
options['source'] = e.files[0].path if e.files else 'Not Selected'
Expand Down Expand Up @@ -133,8 +133,8 @@ def click_abort(e):
ft.dropdown.Option("custom"),
],
)
type_dropdown.value=options['output_type']
type_dropdown.value = options['output_type']

mode_dropdown = ft.Dropdown(
label='mode',
width=150,
Expand Down Expand Up @@ -168,13 +168,14 @@ def click_abort(e):
r_field.value=str(options['r'])
g_field.value=str(options['g'])
b_field.value=str(options['b'])

# ft.Image(src='figures/logo.png', width=100, height=100)

file_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
page.add(
ft.Row(
[
ft.Image(src=os.path.join(os.path.abspath(os.path.expanduser('~')), '.transparent-background', 'logo.png'), width=100, height=100),
ft.Image(src=os.path.join(file_path, '.transparent-background', 'logo.png'), width=100, height=100),
ft.Column(
[
ft.Row([c, output_text]),
Expand Down Expand Up @@ -263,6 +264,7 @@ def click_abort(e):
)
)


def gui():
ft.app(target=main)

Expand All @@ -272,5 +274,6 @@ def gui():
if os.path.isfile('.preview_out.png'):
os.remove('.preview_out.png')


if __name__ == "__main__":
gui()

0 comments on commit 7a9bd3a

Please sign in to comment.