From 3ddb9b3704c801a6b45b871c86ff127193d6a8f1 Mon Sep 17 00:00:00 2001 From: pramitchoudhary Date: Sun, 6 Nov 2022 21:35:45 -0800 Subject: [PATCH] Quick formatting update #5 --- img_styler/ui/app.py | 4 +- img_styler/ui/capture.py | 23 ++- img_styler/ui/common.py | 163 ++++++++++----- img_styler/ui/components.py | 396 +++++++++++++++++++++--------------- img_styler/utils/logger.py | 4 +- 5 files changed, 353 insertions(+), 237 deletions(-) diff --git a/img_styler/ui/app.py b/img_styler/ui/app.py index 9561a7e..c5551d0 100644 --- a/img_styler/ui/app.py +++ b/img_styler/ui/app.py @@ -22,8 +22,8 @@ async def serve(q: Q): log_args(q.args) - hash = q.args['#'] - if hash == 'home': + hash = q.args["#"] + if hash == "home": await home(q) # Initialization diff --git a/img_styler/ui/capture.py b/img_styler/ui/capture.py index c72f482..849225e 100644 --- a/img_styler/ui/capture.py +++ b/img_styler/ui/capture.py @@ -69,12 +69,12 @@ async def capture_img(q: Q): events_dict = expando_to_dict(q.events) _img = None - if 'the_plot' in events_dict.keys(): + if "the_plot" in events_dict.keys(): if q.events.the_plot.selected: - q.page['capture_img'].content = f'You selected {q.events.the_plot.selected}' - if 'video' in events_dict.keys(): + q.page["capture_img"].content = f"You selected {q.events.the_plot.selected}" + if "video" in events_dict.keys(): _img = q.events.video.click if q.events.video.click else None - if 'exit' in events_dict.keys(): + if "exit" in events_dict.keys(): q.args.exit_camera = True return _img @@ -82,15 +82,18 @@ async def capture_img(q: Q): def draw_boundary(img, x, y, w, h, text: str, image_scale=1): _img = Image.fromarray(img) draw = ImageDraw.Draw(_img) - pt_1 = (int(x * image_scale), int(y * image_scale), - int((x + w) * image_scale), int((y + h) * image_scale)) - draw.rounded_rectangle(pt_1, outline="yellow", - width=3, radius=7) + pt_1 = ( + int(x * image_scale), + int(y * image_scale), + int((x + w) * image_scale), + int((y + h) * image_scale), + ) + draw.rounded_rectangle(pt_1, outline="yellow", width=3, radius=7) - font = font_manager.FontProperties(family='sans-serif', weight='bold') + font = font_manager.FontProperties(family="sans-serif", weight="bold") file = font_manager.findfont(font) font = ImageFont.truetype(file, 24) constant = 5 - draw.text((x+w+constant, y), text, font=font, fill='blue') + draw.text((x + w + constant, y), text, font=font, fill="blue") return np.array(_img) diff --git a/img_styler/ui/common.py b/img_styler/ui/common.py index d420283..29d826b 100644 --- a/img_styler/ui/common.py +++ b/img_styler/ui/common.py @@ -15,33 +15,42 @@ get_processed_face_card, get_source_face_card, get_style_face_card, - get_user_title + get_user_title, ) async def update_faces(q: Q, save=False): - del q.page['prompt_form'] + del q.page["prompt_form"] if not q.client.source_face or not os.path.exists(q.client.source_face): q.client.source_face = random.choice(q.app.source_faces) - if q.client.task_choice == 'B': - q.page['source_face'] = get_source_face_card( - img2buf(q.client.source_face), type='jpg' + if q.client.task_choice == "B": + q.page["source_face"] = get_source_face_card( + img2buf(q.client.source_face), type="jpg" ) else: - txt_val = q.client.prompt_textbox if q.client.prompt_textbox else '' - q.page['source_face'] = get_source_face_card( - img2buf(q.client.source_face), type='jpg', height='520px', width='500px' + txt_val = q.client.prompt_textbox if q.client.prompt_textbox else "" + q.page["source_face"] = get_source_face_card( + img2buf(q.client.source_face), type="jpg", height="520px", width="500px" ) - if q.client.task_choice == 'D': - q.page['prompt_form'] = ui.form_card(ui.box('main', order=1, height='200px', width='900px'), items=[ - ui.copyable_text(name='prompt_textbox', label='Prompt (Express your creativity)', multiline=True, value=txt_val), - ui.button(name='prompt_apply', label='Apply')]) - - del q.page['style_face'] - if q.client.task_choice == 'B': - q.page['style_face'] = get_style_face_card( - img2buf(q.client.style_face), type='jpg' + if q.client.task_choice == "D": + q.page["prompt_form"] = ui.form_card( + ui.box("main", order=1, height="200px", width="900px"), + items=[ + ui.copyable_text( + name="prompt_textbox", + label="Prompt (Express your creativity)", + multiline=True, + value=txt_val, + ), + ui.button(name="prompt_apply", label="Apply"), + ], + ) + + del q.page["style_face"] + if q.client.task_choice == "B": + q.page["style_face"] = get_style_face_card( + img2buf(q.client.style_face), type="jpg" ) if save: await q.page.save() @@ -51,58 +60,104 @@ async def update_processed_face(q: Q, save=False): img_buf = img2buf(q.client.processedimg) if q.client.processedimg else None # Delete pages not needed. # It's cheap to create them. - del q.page['processed_face'] - del q.page['prompt_form'] + del q.page["processed_face"] + del q.page["prompt_form"] - if q.client.task_choice == 'B': - q.page['processed_face'] = get_processed_face_card(img_buf, type='jpg') + if q.client.task_choice == "B": + q.page["processed_face"] = get_processed_face_card(img_buf, type="jpg") else: - q.page['processed_face'] = get_processed_face_card( - img_buf, title="Fixed Image", type='jpg', layout_pos='middle_right', order=2 + q.page["processed_face"] = get_processed_face_card( + img_buf, title="Fixed Image", type="jpg", layout_pos="middle_right", order=2 ) - if q.client.task_choice == 'D': - q.page['prompt_form'] = ui.form_card(ui.box('main', order=1, height='320px', width='980px'), items=[ - ui.inline(items=[ - ui.checkbox(name='prompt_use_source_img', label='Use source image', - value=q.client.prompt_use_source_img, tooltip='Image-to-Image text-guided diffusion is applied by default.\ - If un-checked, default Text-to-Image diffusion is used.'), - ui.button(name='prompt_apply', label='Apply') - ]), - ui.textbox(name='prompt_textbox', label='Prompt', multiline=True, value=q.client.prompt_textbox), - ui.expander(name='expander', label='Settings', items=[ - ui.slider(name='diffusion_n_steps', label='Steps', min=10, max=150, value=q.client.diffusion_n_steps, - tooltip='No of steps for image synthesis.'), - ui.slider(name='prompt_guidance_scale', label='Guidance scale', min=3, max=20, step=0.5, value=q.client.prompt_guidance_scale, - tooltip='No of steps for image synthesis.')]), - ]) + if q.client.task_choice == "D": + q.page["prompt_form"] = ui.form_card( + ui.box("main", order=1, height="320px", width="980px"), + items=[ + ui.inline( + items=[ + ui.checkbox( + name="prompt_use_source_img", + label="Use source image", + value=q.client.prompt_use_source_img, + tooltip="Image-to-Image text-guided diffusion is applied by default.\ + If un-checked, default Text-to-Image diffusion is used.", + ), + ui.button(name="prompt_apply", label="Apply"), + ] + ), + ui.textbox( + name="prompt_textbox", + label="Prompt", + multiline=True, + value=q.client.prompt_textbox, + ), + ui.expander( + name="expander", + label="Settings", + items=[ + ui.dropdown( + name="df_sampling_dropdown", + label="Samplers", + value="K-LMS", + choices=[ + ui.choice( + name="K-LMS", label="K-LMS(Katherine Crowson)" + ), + ui.choice(name="DDIM", label="DDIM"), + ], + ), + ui.slider( + name="diffusion_n_steps", + label="Steps", + min=10, + max=150, + value=q.client.diffusion_n_steps, + tooltip="No of steps for image synthesis.", + ), + ui.slider( + name="prompt_guidance_scale", + label="Guidance scale", + min=3, + max=20, + step=0.5, + value=q.client.prompt_guidance_scale, + tooltip="No of steps for image synthesis.", + ), + ], + ), + ], + ) if save: await q.page.save() async def update_controls(q: Q, save=False): - q.page['controls'] = get_controls(q) + q.page["controls"] = get_controls(q) if save: await q.page.save() async def update_gif(q: Q): - del q.page['processed_gif'] - if q.client.task_choice == 'C': + del q.page["processed_gif"] + if q.client.task_choice == "C": if q.client.gif_path: with open(q.client.gif_path, "rb") as gif_file: img_buf = base64.b64encode(gif_file.read()).decode("utf-8") - q.page['processed_gif'] = await get_gif_generated_card(q, img_buf) + q.page["processed_gif"] = await get_gif_generated_card(q, img_buf) else: - q.page['processed_gif'] = get_processed_face_card( - None, title="Generated GIF", type='jpg', layout_pos='main', + q.page["processed_gif"] = get_processed_face_card( + None, + title="Generated GIF", + type="jpg", + layout_pos="main", order=2, - empty_msg="After applying the edits, click 'Generate GIF' to generate a gif of the transformation!" + empty_msg="After applying the edits, click 'Generate GIF' to generate a gif of the transformation!", ) await q.page.save() async def progress_generate_gif(q: Q): - q.page['processed_gif'] = get_generate_gif_progress_card(title="") + q.page["processed_gif"] = get_generate_gif_progress_card(title="") await q.page.save() @@ -112,29 +167,29 @@ async def make_base_ui(q: Q, save=False): q.app.logo_path = ( await q.run(q.site.upload, ["./img_styler/ui/assets/h2o_logo.svg"]) )[0] - q.page['meta'] = get_meta(q) - q.page['header'] = get_header(q) - q.page['user_title'] = get_user_title(q) + q.page["meta"] = get_meta(q) + q.page["header"] = get_header(q) + q.page["user_title"] = get_user_title(q) await update_controls(q) await update_faces(q) await update_processed_face(q) await update_gif(q) - q.page['footer'] = get_footer() + q.page["footer"] = get_footer() if save: await q.page.save() def set_username(q: Q): - first = last = '' + first = last = "" email = q.auth.username - names = email.split('@')[0].split('.') + names = email.split("@")[0].split(".") if len(names) > 1: first, *_, last = names elif names: first = names[0] - last = '' + last = "" q.user.email = q.auth.username q.user.first_name = first.strip().title() q.user.last_name = last.strip().title() - q.user.full_name = f'{q.user.first_name} {q.user.last_name}'.strip().title() + q.user.full_name = f"{q.user.first_name} {q.user.last_name}".strip().title() diff --git a/img_styler/ui/components.py b/img_styler/ui/components.py index b42e447..c9a0037 100644 --- a/img_styler/ui/components.py +++ b/img_styler/ui/components.py @@ -6,8 +6,8 @@ def get_meta(q: Q): return ui.meta_card( - box='', - title='ImageStyler', + box="", + title="ImageStyler", layouts=get_layouts(), theme="winter-is-coming" if q.user.dark_mode else "ember", ) @@ -35,7 +35,7 @@ def get_header(q: Q): def get_footer(): return ui.footer_card( - box=ui.box('footer', order=1), + box=ui.box("footer", order=1), caption=( '

Made with 💛️ using Wave. (c) 2022-23 H2O.ai. All rights reserved.

' @@ -45,21 +45,22 @@ def get_footer(): def get_user_title(q: Q): return ui.section_card( - box=ui.box(zone='title', order=1), - title='', - subtitle='', + box=ui.box(zone="title", order=1), + title="", + subtitle="", ) def get_controls(q: Q): task_choices = [ - ui.choice('A', 'Fix Resolution'), - ui.choice('B', 'Image Styling'), - ui.choice('C', 'Image Editing'), - ui.choice('D', 'Image prompt')] + ui.choice("A", "Fix Resolution"), + ui.choice("B", "Image Styling"), + ui.choice("C", "Image Editing"), + ui.choice("D", "Image prompt"), + ] task_choice_dropdown = ui.dropdown( - name='task_dropdown', - label='Select a styling option', + name="task_dropdown", + label="Select a styling option", value=q.client.task_choice, required=True, trigger=True, @@ -73,221 +74,232 @@ def get_controls(q: Q): landmark_controls = [ ui.separator(label="Modify"), ui.slider( - name='age_slider', - label='Age', + name="age_slider", + label="Age", min=-10, max=10, step=1, value=q.client.age_slider if q.client.age_slider else 0, ), ui.slider( - name='eye_distance', - label='Eye Distance', + name="eye_distance", + label="Eye Distance", min=-10, max=10, step=1, value=q.client.eye_distance if q.client.eye_distance else 0, ), ui.slider( - name='eyebrow_distance', - label='Eyebrow Distance', + name="eyebrow_distance", + label="Eyebrow Distance", min=-10, max=10, step=1, value=q.client.eyebrow_distance if q.client.eyebrow_distance else 0, ), ui.slider( - name='eye_ratio', - label='Eye Ratio', + name="eye_ratio", + label="Eye Ratio", min=-10, max=10, step=1, value=q.client.eye_ratio if q.client.eye_ratio else 0, ), ui.slider( - name='eyes_open', - label='Eyes Open', + name="eyes_open", + label="Eyes Open", min=-10, max=10, step=1, value=q.client.eyes_open if q.client.eyes_open else 0, ), ui.slider( - name='gender', - label='Gender', + name="gender", + label="Gender", min=-10, max=10, step=1, value=q.client.gender if q.client.gender else 0, ), ui.slider( - name='lip_ratio', - label='Lip Ratio', + name="lip_ratio", + label="Lip Ratio", min=-10, max=10, step=1, value=q.client.lip_ratio if q.client.lip_ratiolip_ratio else 0, ), ui.slider( - name='mouth_open', - label='Mouth Open', + name="mouth_open", + label="Mouth Open", min=-10, max=10, step=1, value=q.client.mouth_open if q.client.mouth_open else 0, ), ui.slider( - name='mouth_ratio', - label='Mouth Ratio', + name="mouth_ratio", + label="Mouth Ratio", min=-10, max=10, step=1, value=q.client.mouth_ratio if q.client.mouth_ratio else 0, ), ui.slider( - name='nose_mouth_distance', - label='Nose Mouth Distance', + name="nose_mouth_distance", + label="Nose Mouth Distance", min=-10, max=10, step=1, value=q.client.nose_mouth_distance if q.client.nose_mouth_distance else 0, ), ui.slider( - name='nose_ratio', - label='Nose Ratio', + name="nose_ratio", + label="Nose Ratio", min=-10, max=10, step=1, value=q.client.nose_ratio if q.client.nose_ratio else 0, ), ui.slider( - name='nose_tip', - label='Nose Tip', + name="nose_tip", + label="Nose Tip", min=-10, max=10, step=1, value=q.client.nose_tip if q.client.nose_tip else 0, ), ui.slider( - name='pitch', - label='Pitch', + name="pitch", + label="Pitch", min=-10, max=10, step=1, value=q.client.pitch if q.client.pitch else 0, ), ui.slider( - name='roll', - label='Roll', + name="roll", + label="Roll", min=-10, max=10, step=1, value=q.client.roll if q.client.roll else 0, ), ui.slider( - name='smile', - label='Smile', + name="smile", + label="Smile", min=-10, max=10, step=1, value=q.client.smile if q.client.smile else 0, ), ui.slider( - name='yaw', - label='Yaw', + name="yaw", + label="Yaw", min=-10, max=10, step=1, value=q.client.yaw if q.client.yaw else 0, ), ] - if q.client.task_choice == 'A': # Fix Resolution - img_name_parts = q.client.source_face.split('/')[-1].split('.') - new_img_name = '.'.join(img_name_parts[: -1]) + '_fixed.' + img_name_parts[-1] + if q.client.task_choice == "A": # Fix Resolution + img_name_parts = q.client.source_face.split("/")[-1].split(".") + new_img_name = ".".join(img_name_parts[:-1]) + "_fixed." + img_name_parts[-1] disabled = q.client.processedimg is None return ui.form_card( - box=ui.box(zone='side_controls', order=1), + box=ui.box(zone="side_controls", order=1), items=[ task_choice_dropdown, ui.dropdown( - name='source_face', - label='Source Face', + name="source_face", + label="Source Face", choices=[ ui.choice(name=x, label=os.path.basename(x)) for x in q.app.source_faces ], value=q.client.source_face, - tooltip='Select a source face to be enhanced.', + tooltip="Select a source face to be enhanced.", trigger=True, ), ui.buttons( [ ui.button( - name='upload_image_dialog', label='Upload', primary=True + name="upload_image_dialog", label="Upload", primary=True ), - ui.button(name='#capture', label='Capture', primary=True), + ui.button(name="#capture", label="Capture", primary=True), ], - justify='end', + justify="end", + ), + ui.buttons( + [ui.button("fix_resolution", "Fix Resolution", primary=True)], + justify="end", ), - ui.buttons([ - ui.button('fix_resolution', 'Fix Resolution', primary=True) - ], justify='end'), ui.separator(), - ui.textbox('img_name', 'Add fixed image to list', value=new_img_name, disabled=disabled), - ui.buttons([ - ui.button('save_img_to_list', 'Add', primary=True, disabled=disabled) - ], justify='end'), - ] + ui.textbox( + "img_name", + "Add fixed image to list", + value=new_img_name, + disabled=disabled, + ), + ui.buttons( + [ + ui.button( + "save_img_to_list", "Add", primary=True, disabled=disabled + ) + ], + justify="end", + ), + ], ) - elif q.client.task_choice == 'B': + elif q.client.task_choice == "B": # Includes styling controls. return ui.form_card( box=ui.box( - zone='side_controls', + zone="side_controls", order=1, ), items=[ task_choice_dropdown, ui.dropdown( - name='source_face', - label='Source Face', + name="source_face", + label="Source Face", choices=[ ui.choice(name=x, label=os.path.basename(x)) for x in q.app.source_faces ], value=q.client.source_face, - tooltip='Select a source face. One can upload a new source face as well.', + tooltip="Select a source face. One can upload a new source face as well.", trigger=True, ), ui.dropdown( - name='style_face', - label='Style Face', + name="style_face", + label="Style Face", choices=[ ui.choice(name=x, label=os.path.basename(x)) for x in q.app.style_faces ], value=q.client.style_face, - tooltip='Select a style face from the provided options.', + tooltip="Select a style face from the provided options.", trigger=True, ), ui.dropdown( - name='z_low', - label='Z Low', + name="z_low", + label="Z Low", choices=[ ui.choice(name=str(x), label=str(x)) for x in range(0, 17) ], value=str(q.client.z_low), - tooltip='Latent space range (0-16)', + tooltip="Latent space range (0-16)", trigger=True, ), ui.dropdown( - name='z_high', - label='Z High', + name="z_high", + label="Z High", choices=[ ui.choice(name=str(x), label=str(x)) for x in range(0, 17) ], value=str(q.client.z_high), - tooltip='Latent space range (0-16)', + tooltip="Latent space range (0-16)", trigger=True, ), ui.text_m("**Recommended pairs for Z Low/Z High:**"), @@ -295,86 +307,115 @@ def get_controls(q: Q): ui.buttons( [ ui.button( - name='upload_image_dialog', - label='Upload', + name="upload_image_dialog", + label="Upload", primary=True, - tooltip='Upload an image.', + tooltip="Upload an image.", ), ui.button( - name='#capture', - label='Capture', + name="#capture", + label="Capture", primary=True, - tooltip='Upload an image using the camera.', + tooltip="Upload an image using the camera.", ), ], - justify='end', + justify="end", ), ui.buttons( [ - ui.button(name='apply', label='Apply', primary=True), + ui.button(name="apply", label="Apply", primary=True), ], - justify='end', + justify="end", ), ], ) - elif q.client.task_choice == 'C': + elif q.client.task_choice == "C": style_names = { - 'none': 'None', 'anime': 'Anime', 'botero': 'Botero', 'crochet': 'Crochet', 'cubism': 'Cubism', - 'disney_princess': 'Disney Princess', 'edvard_munch': 'Edvard Munch', 'elf': 'Elf', 'ghibli': 'Ghibli', - 'grafitti_on_wall': 'Grafitti on Wall', 'groot': 'Groot', 'joker': 'Joker', 'marble': 'Marble', - 'modernism': 'Modernism', 'modigliani': 'Modigliani', 'mona_lisa': 'Mona Lisa', 'oil': 'Oil', - 'pixar': 'Pixar', 'plastic_puppet': 'Plastic Puppet', 'rick_morty': 'Rick and Morty', 'shrek': 'Shrek', - 'simpson': 'Simpson', 'sketch': 'Sketch', 'ssj': 'Super Saiyan', 'thanos': 'Thanos', 'ukiyoe': 'Ukiyoe', - 'van_gogh': 'Van Gogh', 'vintage_comics': 'Vintage Comics', 'werewolf': 'Werewolf', - 'white_walker': 'White Walker', 'witcher': 'Witcher', 'zombie': 'Zombie', 'zuckerberg': 'Zuckerberg' + "none": "None", + "anime": "Anime", + "botero": "Botero", + "crochet": "Crochet", + "cubism": "Cubism", + "disney_princess": "Disney Princess", + "edvard_munch": "Edvard Munch", + "elf": "Elf", + "ghibli": "Ghibli", + "grafitti_on_wall": "Grafitti on Wall", + "groot": "Groot", + "joker": "Joker", + "marble": "Marble", + "modernism": "Modernism", + "modigliani": "Modigliani", + "mona_lisa": "Mona Lisa", + "oil": "Oil", + "pixar": "Pixar", + "plastic_puppet": "Plastic Puppet", + "rick_morty": "Rick and Morty", + "shrek": "Shrek", + "simpson": "Simpson", + "sketch": "Sketch", + "ssj": "Super Saiyan", + "thanos": "Thanos", + "ukiyoe": "Ukiyoe", + "van_gogh": "Van Gogh", + "vintage_comics": "Vintage Comics", + "werewolf": "Werewolf", + "white_walker": "White Walker", + "witcher": "Witcher", + "zombie": "Zombie", + "zuckerberg": "Zuckerberg", } # Includes edit controls edit_controls = ui.form_card( box=ui.box( - zone='side_controls', + zone="side_controls", order=1, ), items=[ task_choice_dropdown, ui.dropdown( - name='source_face', - label='Source Face', + name="source_face", + label="Source Face", choices=[ ui.choice(name=x, label=os.path.basename(x)) for x in q.app.source_faces ], value=q.client.source_face, trigger=True, - tooltip='Select a source face for editing. One can upload a new source face as well.', + tooltip="Select a source face for editing. One can upload a new source face as well.", ), ui.dropdown( - name='source_style', - label='Styles', + name="source_style", + label="Styles", choices=[ - ui.choice(name=f'style_{x}', label=style_names[x]) + ui.choice(name=f"style_{x}", label=style_names[x]) for x in style_names ], - value=q.client.source_style or 'style_none', - tooltip='Select a pre-configured style to adapt.', - trigger = True + value=q.client.source_style or "style_none", + tooltip="Select a pre-configured style to adapt.", + trigger=True, ), ui.buttons( [ ui.button( - name='upload_image_dialog', label='Upload', primary=True + name="upload_image_dialog", label="Upload", primary=True ), - ui.button(name='#capture', label='Capture', primary=True), + ui.button(name="#capture", label="Capture", primary=True), ], - justify='end', + justify="end", ), ui.buttons( [ - ui.button(name='apply', label='Apply', primary=True), - ui.button(name='generate_gif', label='Generate GIF', primary=True, - disabled=(q.client.processedimg is None)), + ui.button(name="apply", label="Apply", primary=True), + ui.button( + name="generate_gif", + label="Generate GIF", + primary=True, + disabled=(q.client.processedimg is None), + ), ], - justify='end', - ) + justify="end", + ), ], ) start_index = 3 @@ -383,13 +424,13 @@ def get_controls(q: Q): for _index, _item in enumerate(landmark_controls) ] return edit_controls - else: # Option: 'D' Image Prompt - return ui.form_card(box=ui.box( - zone='side_controls', - order=1), items=[ - ui.dropdown( - name='task_dropdown', - label='Select a styling option', + else: # Option: 'D' Image Prompt + return ui.form_card( + box=ui.box(zone="side_controls", order=1), + items=[ + ui.dropdown( + name="task_dropdown", + label="Select a styling option", value=q.client.task_choice, required=True, trigger=True, @@ -398,59 +439,70 @@ def get_controls(q: Q): Image Styling (Transfer a style to an original image), \ Image Editing (Edit and transform an existing image), and \ Fix Resolution (Increase resolution and fix artifacts in an existing image), and \ - Image Prompt (Generate image via prompt)" - ), - ui.dropdown( - name='source_face', - label='Source Face', + Image Prompt (Generate image via prompt)", + ), + ui.dropdown( + name="source_face", + label="Source Face", choices=[ ui.choice(name=x, label=os.path.basename(x)) for x in q.app.source_faces ], value=q.client.source_face, trigger=True, - tooltip='Select a source face for editing. One can upload a new source face as well.', - ), - ui.buttons( + tooltip="Select a source face for editing. One can upload a new source face as well.", + ), + ui.buttons( [ ui.button( - name='upload_image_dialog', - label='Upload', + name="upload_image_dialog", + label="Upload", primary=True, - tooltip='Upload an image.', + tooltip="Upload an image.", ), ui.button( - name='#capture', - label='Capture', + name="#capture", + label="Capture", primary=True, - tooltip='Upload an image using the camera.', + tooltip="Upload an image using the camera.", ), ], - justify='end', - ), - ui.choice_group(name='choice_group_prompt', label='Options', value='checkbox_without_training', - choices=[ - ui.choice(name='checkbox_without_training', label='Default diffusion'), - ui.choice(name='checkbox_re_training', label='Dreambooth fine-tuning', disabled=True) - ] - ) - ]) + justify="end", + ), + ui.choice_group( + name="choice_group_prompt", + label="Options", + value="checkbox_without_training", + choices=[ + ui.choice( + name="checkbox_without_training", label="Default diffusion" + ), + ui.choice( + name="checkbox_re_training", + label="Dreambooth fine-tuning", + disabled=True, + ), + ], + tooltip="Stable Diffusion is a text-to-image latent diffusion model created by the researchers and engineers from CompVis, Stability AI and LAION.", + ), + ], + ) def get_source_header(): return ui.section_card( - box=ui.box(zone='middle_left', order=1, height='45px'), - title='Source Face', - subtitle='', + box=ui.box(zone="middle_left", order=1, height="45px"), + title="Source Face", + subtitle="", items=[ ui.dropdown( - name='source_face', - label='', + name="source_face", + label="", choices=[ ui.choice(name=x, label=x) - for x in ['one.jpg', 'two.jpg', 'three.jpg'] + for x in ["one.jpg", "two.jpg", "three.jpg"] ], - value='one.jpg', + value="one.jpg", trigger=True, ) ], @@ -459,28 +511,28 @@ def get_source_header(): def get_style_header(): return ui.section_card( - box=ui.box(zone='middle_right', order=1, height='45px'), - title='Style Face', - subtitle='', + box=ui.box(zone="middle_right", order=1, height="45px"), + title="Style Face", + subtitle="", items=[ ui.dropdown( - name='style_face', - label='', + name="style_face", + label="", choices=[ ui.choice(name=x, label=x) - for x in ['one.jpg', 'two.jpg', 'three.jpg'] + for x in ["one.jpg", "two.jpg", "three.jpg"] ], - value='one.jpg', + value="one.jpg", trigger=True, ) ], ) -def get_source_face_card(image, type, height: str = '420px', width: str = '400px'): +def get_source_face_card(image, type, height: str = "420px", width: str = "400px"): return ui.image_card( - box=ui.box('middle_left', order=2, height=height, width=width), - title='Source Face', + box=ui.box("middle_left", order=2, height=height, width=width), + title="Source Face", type=type, image=image, ) @@ -488,16 +540,22 @@ def get_source_face_card(image, type, height: str = '420px', width: str = '400px def get_style_face_card(image, type): return ui.image_card( - box=ui.box('middle_right', order=2, height='420px', width='400px'), - title='Style Face', + box=ui.box("middle_right", order=2, height="420px", width="400px"), + title="Style Face", type=type, image=image, ) def get_processed_face_card( - image, type, layout_pos='main', order=1, title='Synthesized Image', - empty_msg: str = "'Apply' to generate a new face!", height='520px', width='500px' + image, + type, + layout_pos="main", + order=1, + title="Synthesized Image", + empty_msg: str = "'Apply' to generate a new face!", + height="520px", + width="500px", ): if image: return ui.image_card( @@ -515,7 +573,7 @@ def get_processed_face_card( def get_generate_gif_progress_card( - layout_pos='main', order=1, title='Generated GIF', height='520px', width='500px' + layout_pos="main", order=1, title="Generated GIF", height="520px", width="500px" ): return ui.form_card( box=ui.box(layout_pos, order=order, height=height, width=width), @@ -524,13 +582,13 @@ def get_generate_gif_progress_card( ) -async def get_gif_generated_card(q: Q, gif, order=1, title='Generated GIF'): +async def get_gif_generated_card(q: Q, gif, order=1, title="Generated GIF"): download_path = await q.site.upload([q.client.gif_path]) return ui.form_card( - box=ui.box('main', order=order, height='550px', width='500px'), + box=ui.box("main", order=order, height="550px", width="500px"), title=title, items=[ - ui.image("GIF", "gif", gif, width='465px'), - ui.link(label=f'Download GIF', download=True, path=download_path[0]) - ] + ui.image("GIF", "gif", gif, width="465px"), + ui.link(label=f"Download GIF", download=True, path=download_path[0]), + ], ) diff --git a/img_styler/utils/logger.py b/img_styler/utils/logger.py index f1c7018..ce8a685 100644 --- a/img_styler/utils/logger.py +++ b/img_styler/utils/logger.py @@ -20,10 +20,10 @@ def unique_id(): job_dir = app_settings['Scheduler']['JobDir'] job_path = f"{job_dir}/{uuid}" -log_filename = f"{job_path}/styleganwebapp.log" +log_filename = f"{job_path}/image_styler.log" os.makedirs(os.path.dirname(log_filename), exist_ok=True) -logging = logging.patch(lambda record: record.update(name="StyleGANWebApp")) +logging = logging.patch(lambda record: record.update(name="ImageStylingArtStudio")) logging.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO") logging.add(log_filename)