Skip to content

Commit

Permalink
Change layout for enabling prompt #5
Browse files Browse the repository at this point in the history
  • Loading branch information
pramitchoudhary committed Oct 20, 2022
1 parent af7b050 commit aab7173
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 4 additions & 1 deletion img_styler/ui/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
import os
import random
from h2o_wave import Q
from h2o_wave import Q, ui

from .components import (
get_controls,
Expand Down Expand Up @@ -30,6 +30,9 @@ async def update_faces(q: Q, save=False):
q.page['source_face'] = get_source_face_card(
img2buf(q.client.source_face), type='jpg', height='520px', width='500px'
)
q.page['prompt_textbox'] = ui.form_card(ui.box('main', order=1, height='200px', width='900px'), items=[
ui.textbox(name='textbox', label='Prompt', multiline=True),
ui.button(name='prompt_apply', label='Apply')])
del q.page['style_face']
if q.client.task_choice == 'A':
q.page['style_face'] = get_style_face_card(
Expand Down
23 changes: 20 additions & 3 deletions img_styler/ui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_user_title(q: Q):


def get_controls(q: Q):
task_choices = [ui.choice('A', 'Image Styling'), ui.choice('B', 'Image Editing')]
task_choices = [ui.choice('A', 'Image Styling'), ui.choice('B', 'Image Editing'), ui.choice('C', 'Image prompt')]
landmark_controls = [
ui.separator(label="Modify"),
ui.slider(
Expand Down Expand Up @@ -272,9 +272,9 @@ def get_controls(q: Q):
),
],
)
else:
elif q.client.task_choice == 'B':
style_names = {
'none': 'None', 'prompt': 'Prompt', 'anime': 'Anime', 'botero': 'Botero', 'crochet': 'Crochet', 'cubism': 'Cubism',
'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',
Expand Down Expand Up @@ -348,6 +348,23 @@ def get_controls(q: Q):
for _index, _item in enumerate(landmark_controls)
]
return edit_controls
else: # Option: 'C'
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,
choices=task_choices,
tooltip="There are 2 options available. \
Image Styling (Transfer a style to an original image) and \
Image Editing (Edit and transform an existing image).",
),
ui.checkbox(name='checkbox_without_training', label='Without re-training', value=True),
ui.checkbox(name='checkbox_re_training', label='With re-training')])


def get_source_header():
Expand Down
5 changes: 0 additions & 5 deletions img_styler/ui/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ async def process(q: Q):
await update_faces(q)
await update_processed_face(q)
await update_gif(q)
if q.args.task_dropdown == 'B' and q.args.source_style is not None:
styles = q.args.source_style[len('style_'):]
q.client.source_style = q.args.source_style
if styles == 'prompt':
logger.info(f"Prompt action selected: {styles}")
if q.args.apply:
await apply(q)
if hash == 'capture':
Expand Down

0 comments on commit aab7173

Please sign in to comment.