Skip to content

Commit cb2afde

Browse files
author
Julie Kwok
committed
Add ability to specify file path for .transparent-background dir where config is stored
1 parent 8b6d913 commit cb2afde

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ You need to install `zenity` to open files and directories on Linux
7878
sudo apt install zenity
7979
```
8080

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

92-
#### Install from github
92+
#### Install from Github
9393
```bash
9494
pip install --extra-index-url https://download.pytorch.org/whl/cu118 git+https://github.com/plemeri/transparent-background.git
9595
```
@@ -117,8 +117,8 @@ pip install torch torchvision torchaudio --index-url https://download.pytorch.or
117117
### [New] Configuration
118118

119119
`transparent-background` now supports external configuration rather than hard coded assets (e.g., checkpoint download url).
120-
* The config file will be added in your home directory `~/.transparent-background/config.yaml`
121-
* You may change the `url` argument to your google drive download link. (Please note that only google drive is supported.)
120+
* 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`.
121+
* You may change the `url` argument to your Google Drive download link. (Please note that only Google Drive is supported.)
122122
* You may change the `md5` argument to your file's md5 checksum. Or, set `md5` to `NULL` to skip verification.
123123
* 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))
124124
```yaml

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
with open("README.md", "r", encoding='utf-8') as fh:
66
long_description = fh.read()
77

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

1113
setuptools.setup(
1214
name="transparent-background",

transparent_background/Remover.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def __init__(self, mode="base", jit=False, device=None, ckpt=None, fast=None):
4040
ckpt (str, optional): specifying model checkpoint. find downloaded checkpoint or try download if not specified.
4141
fast (bool, optional, DEPRECATED): replaced by mode argument. use fast mode if True.
4242
"""
43-
home_dir = os.path.expanduser(os.path.join("~", ".transparent-background"))
43+
file_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
44+
home_dir = os.path.join(file_path, ".transparent-background")
4445
os.makedirs(home_dir, exist_ok=True)
4546

4647
if not os.path.isfile(os.path.join(home_dir, "config.yaml")):

transparent_background/gui.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'abort':False,
3636
}
3737

38+
3839
def main(page):
3940
def theme_changed(e):
4041
page.theme_mode = (
@@ -72,7 +73,6 @@ def color_changed(e):
7273
output_text.value = 'Type: {}, Mode: {}, Device: {}'.format(options['output_type'], options['color'], options['device'])
7374
page.update()
7475

75-
7676
def pick_files_result(e: FilePickerResultEvent):
7777
file_path.update()
7878
options['source'] = e.files[0].path if e.files else 'Not Selected'
@@ -133,8 +133,8 @@ def click_abort(e):
133133
ft.dropdown.Option("custom"),
134134
],
135135
)
136-
type_dropdown.value=options['output_type']
137-
136+
type_dropdown.value = options['output_type']
137+
138138
mode_dropdown = ft.Dropdown(
139139
label='mode',
140140
width=150,
@@ -168,13 +168,14 @@ def click_abort(e):
168168
r_field.value=str(options['r'])
169169
g_field.value=str(options['g'])
170170
b_field.value=str(options['b'])
171-
171+
172172
# ft.Image(src='figures/logo.png', width=100, height=100)
173173

174+
file_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
174175
page.add(
175176
ft.Row(
176177
[
177-
ft.Image(src=os.path.join(os.path.abspath(os.path.expanduser('~')), '.transparent-background', 'logo.png'), width=100, height=100),
178+
ft.Image(src=os.path.join(file_path, '.transparent-background', 'logo.png'), width=100, height=100),
178179
ft.Column(
179180
[
180181
ft.Row([c, output_text]),
@@ -263,6 +264,7 @@ def click_abort(e):
263264
)
264265
)
265266

267+
266268
def gui():
267269
ft.app(target=main)
268270

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

277+
275278
if __name__ == "__main__":
276279
gui()

0 commit comments

Comments
 (0)