Skip to content

Commit

Permalink
Update version
Browse files Browse the repository at this point in the history
  • Loading branch information
taehun-kim2 committed Aug 22, 2024
1 parent 7a9bd3a commit d8761d4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pip install torch torchvision torchaudio --index-url https://download.pytorch.or
### [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` by default. The directory location can be customized by setting the desired file path under the environment variable `TRANSPARENT_BACKGROUND_FILE_PATH`.
* 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`. (Contributed by [kwokster10](https://github.com/kwokster10))
* 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))
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
with open("README.md", "r", encoding='utf-8') as fh:
long_description = fh.read()


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'))
cfg_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
os.makedirs(os.path.join(cfg_path, '.transparent-background'), exist_ok=True)

setuptools.setup(
name="transparent-background",
version="1.3.1",
version="1.3.2",
author="Taehun Kim",
author_email="[email protected]",
description="Make images with transparent background",
Expand Down
4 changes: 2 additions & 2 deletions transparent_background/Remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +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.
"""
file_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
home_dir = os.path.join(file_path, ".transparent-background")
cfg_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
home_dir = os.path.join(cfg_path, ".transparent-background")
os.makedirs(home_dir, exist_ok=True)

if not os.path.isfile(os.path.join(home_dir, "config.yaml")):
Expand Down
80 changes: 58 additions & 22 deletions transparent_background/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import torch
import logging

from transparent_background.utils import get_backend
from transparent_background.Remover import entry_point
from transparent_background.utils import *
from transparent_background.Remover import *

logging.basicConfig(level=logging.WARN)
logging.getLogger("flet_runtime").setLevel(logging.WARN)
Expand All @@ -35,6 +35,12 @@
'abort':False,
}

def is_float(str):
try:
tmp = float(str)
return True
except ValueError:
return False

def main(page):
def theme_changed(e):
Expand Down Expand Up @@ -62,17 +68,23 @@ def dropdown_changed(e):
options['use_custom']=False
page.remove_at(1)

output_text.value = 'Type: {}, Mode: {}, Device: {}'.format(options['output_type'], options['mode'], options['device'])
output_text.value = 'Type: {}, Mode: {}, Device: {}, Threshold: {}'.format(options['output_type'], options['mode'], options['device'], options['threshold'])
page.update()

def color_changed(e):
options['r'] = int(r_field.value) if len(r_field.value) > 0 and r_field.value.isdigit() else 0
options['g'] = int(g_field.value) if len(g_field.value) > 0 and g_field.value.isdigit() else 0
options['b'] = int(b_field.value) if len(b_field.value) > 0 and b_field.value.isdigit() else 0
options['color'] = str([options['r'], options['g'], options['b']])
output_text.value = 'Type: {}, Mode: {}, Device: {}'.format(options['output_type'], options['color'], options['device'])
output_text.value = 'Type: {}, Mode: {}, Device: {}, Threshold: {}'.format(options['output_type'], options['color'], options['device'], options['threshold'])
page.update()

def threshold_changed(e):
options['threshold'] = float(threshold_field.value) if len(threshold_field.value) > 0 and is_float(threshold_field.value) else None
options['threshold'] = None if is_float(options['threshold']) and (options['threshold'] < 0 or options['threshold'] > 1) else options['threshold']
output_text.value = 'Type: {}, Mode: {}, Device: {}, Threshold: {}'.format(options['output_type'], options['mode'], options['device'], options['threshold'])
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 @@ -115,7 +127,16 @@ def click_abort(e):
page.theme_mode = ft.ThemeMode.LIGHT
c = ft.Switch(label="Dark mode", on_change=theme_changed)

output_text = ft.Text()
output_text = ft.Text(color=ft.colors.BLACK)
output_text.value = 'Type: {}, Mode: {}, Device: {}, Threshold: {}'.format(options['output_type'], options['mode'], options['device'], options['threshold'])
output_text_container = ft.Container(
content=output_text,
margin=10,
padding=10,
bgcolor=ft.colors.GREEN_100,
border_radius=10,
)

jit_check = ft.Checkbox(label="use torchscript", value=False, on_change=checkbox_changed)

type_dropdown = ft.Dropdown(
Expand All @@ -135,16 +156,18 @@ def click_abort(e):
)
type_dropdown.value = options['output_type']

Remover() # init once

cfg_path = os.environ.get('TRANSPARENT_BACKGROUND_FILE_PATH', os.path.abspath(os.path.expanduser('~')))
home_dir = os.path.join(cfg_path, ".transparent-background")
configs = load_config(os.path.join(home_dir, "config.yaml"))

mode_dropdown = ft.Dropdown(
label='mode',
width=150,
hint_text='mode',
on_change=dropdown_changed,
options=[
ft.dropdown.Option("base"),
ft.dropdown.Option("base-nightly"),
ft.dropdown.Option("fast"),
],
options=[ft.dropdown.Option(key) for key in configs.keys()],
)
mode_dropdown.value = options['mode']

Expand All @@ -169,33 +192,46 @@ def click_abort(e):
g_field.value=str(options['g'])
b_field.value=str(options['b'])

# ft.Image(src='figures/logo.png', width=100, height=100)
threshold_field = ft.TextField(width=100, label='threshold', on_change=threshold_changed)
threshold_field.value = 'None'

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(file_path, '.transparent-background', 'logo.png'), width=100, height=100),
ft.Image(src='https://raw.githubusercontent.com/plemeri/transparent-background/main/figures/logo.png', width=100, height=100),
ft.Column(
[
ft.Row([c, output_text]),
ft.Row([type_dropdown, mode_dropdown, device_dropdown, jit_check])
ft.Row([c, output_text_container]),
ft.Row([type_dropdown, mode_dropdown, device_dropdown, threshold_field, jit_check])
]
)
]
)
)

# page.add(ft.Row([c, output_text]))
# page.add(ft.Row([type_dropdown, mode_dropdown, device_dropdown, jit_check]))

pick_files_dialog = FilePicker(on_result=pick_files_result)

get_directory_dialog = FilePicker(on_result=get_directory_result)
file_path = Text()
file_path = Text(color=ft.colors.BLACK)
file_path.value = 'Input file or directory will be displayed'
file_path_container = ft.Container(
content=file_path,
margin=10,
padding=10,
bgcolor=ft.colors.AMBER,
border_radius=10,
)

get_dest_dialog = FilePicker(on_result=get_dest_result)
dest_path = Text()
dest_path = Text(color=ft.colors.BLACK)
dest_path.value = 'Output file or directory will be displayed'
dest_path_container = ft.Container(
content=dest_path,
margin=10,
padding=10,
bgcolor=ft.colors.CYAN_200,
border_radius=10,
)

# hide all dialogs in overlay
page.overlay.extend([pick_files_dialog, get_directory_dialog, get_dest_dialog])
Expand All @@ -222,7 +258,7 @@ def click_abort(e):
on_click=lambda _: get_directory_dialog.get_directory_path(),
disabled=page.web,
),
file_path,
file_path_container,
]
),
Row(
Expand All @@ -233,7 +269,7 @@ def click_abort(e):
on_click=lambda _: get_dest_dialog.get_directory_path(),
disabled=page.web,
),
dest_path
dest_path_container
]
),
Row(
Expand Down

0 comments on commit d8761d4

Please sign in to comment.