Yardenfren commited on
Commit
9175f99
1 Parent(s): 77e3547

Update app_inference.py

Browse files
Files changed (1) hide show
  1. app_inference.py +15 -4
app_inference.py CHANGED
@@ -127,6 +127,19 @@ def toggle_column(is_checked):
127
  except Exception as e:
128
  raise type(e)(f'failed to toggle_column, due to: {e}')
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  class InferenceUtil:
132
  def __init__(self, hf_token: str | None):
@@ -245,14 +258,12 @@ with gr.Blocks(css=css) as demo:
245
  style_image,
246
  ])
247
  style_prompt.change(
248
- fn=lambda content_blora_prompt,
249
- style_blora_prompt: f'{content_blora_prompt} in {style_blora_prompt[0].lower() + style_blora_prompt[1:]} style' if style_blora_prompt else content_blora_prompt,
250
  inputs=[content_prompt, style_prompt],
251
  outputs=prompt,
252
  )
253
  content_prompt.change(
254
- fn=lambda content_blora_prompt,
255
- style_blora_prompt: f'{content_blora_prompt} in {style_blora_prompt[0].lower() + style_blora_prompt[1:]} style' if content_blora_prompt else style_blora_prompt,
256
  inputs=[content_prompt, style_prompt],
257
  outputs=prompt,
258
  )
 
127
  except Exception as e:
128
  raise type(e)(f'failed to toggle_column, due to: {e}')
129
 
130
+ def handle_prompt_change(content_blora_prompt, style_blora_prompt) -> str:
131
+ try:
132
+ if content_blora_prompt and style_blora_prompt:
133
+ return f'{content_blora_prompt} in {style_blora_prompt[0].lower() + style_blora_prompt[1:]} style'
134
+ if content_blora_prompt:
135
+ return content_blora_prompt
136
+ if style_blora_prompt:
137
+ return f'A dog in {style_blora_prompt[0].lower() + style_blora_prompt[1:]} style'
138
+
139
+ return ''
140
+ except Exception as e:
141
+ raise type(e)(f'failed to handle_prompt_change, due to: {e}')
142
+
143
 
144
  class InferenceUtil:
145
  def __init__(self, hf_token: str | None):
 
258
  style_image,
259
  ])
260
  style_prompt.change(
261
+ fn=handle_prompt_change,
 
262
  inputs=[content_prompt, style_prompt],
263
  outputs=prompt,
264
  )
265
  content_prompt.change(
266
+ fn=handle_prompt_change,
 
267
  inputs=[content_prompt, style_prompt],
268
  outputs=prompt,
269
  )