Akjava commited on
Commit
e1e11cc
·
1 Parent(s): bde9fae

catch error

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -16,26 +16,30 @@ def sanitize_prompt(prompt):
16
 
17
  @spaces.GPU(duration=180)
18
  def process_images(image, image2=None,prompt="a girl",inpaint_model="black-forest-labs/FLUX.1-schnell",strength=0.75,seed=0):
19
- # I'm not sure when this happen
20
- if not isinstance(image, dict):
21
- if image2 == None:
22
- print("empty mask")
23
- return image
24
- else:
25
- image = dict({'background': image, 'layers': [image2]})
 
26
 
27
- if image2!=None:
28
- #print("use image2")
29
- mask = image2
30
- else:
31
- if len(image['layers']) == 0:
32
- print("empty mask")
33
- return image
34
- print("use layer")
35
- mask = image['layers'][0]
36
 
37
 
38
- output = flux1_inpaint.process_image(image["background"],mask,prompt,inpaint_model,strength,seed)
 
 
 
39
 
40
  return output
41
 
@@ -77,7 +81,7 @@ with demo_blocks as demo:
77
  with gr.Row():
78
  prompt = gr.Textbox(label="Prompt",value="a eyes closed girl,shut eyes",placeholder="Your prompt (what you want in place of what is erased)", elem_id="prompt")
79
 
80
- btn = gr.Button("Inpaint", elem_id="run_button",variant="primary")
81
 
82
  image_mask = gr.Image(sources=['upload','clipboard'], elem_id="mask_upload", type="pil", label="Mask_Upload",height=400, value=None)
83
  with gr.Accordion(label="Advanced Settings", open=False):
 
16
 
17
  @spaces.GPU(duration=180)
18
  def process_images(image, image2=None,prompt="a girl",inpaint_model="black-forest-labs/FLUX.1-schnell",strength=0.75,seed=0):
19
+ try:
20
+ # I'm not sure when this happen
21
+ if not isinstance(image, dict):
22
+ if image2 == None:
23
+ print("empty mask")
24
+ return image
25
+ else:
26
+ image = dict({'background': image, 'layers': [image2]})
27
 
28
+ if image2!=None:
29
+ #print("use image2")
30
+ mask = image2
31
+ else:
32
+ if len(image['layers']) == 0:
33
+ print("empty mask")
34
+ return image
35
+ print("use layer")
36
+ mask = image['layers'][0]
37
 
38
 
39
+ output = flux1_img2img.process_image(image["background"],mask,prompt,inpaint_model,strength,seed)
40
+ except Exception as e:
41
+ print(f"An error occurred: {e}")
42
+ gr.Error(e)
43
 
44
  return output
45
 
 
81
  with gr.Row():
82
  prompt = gr.Textbox(label="Prompt",value="a eyes closed girl,shut eyes",placeholder="Your prompt (what you want in place of what is erased)", elem_id="prompt")
83
 
84
+ btn = gr.Button("Img2Img", elem_id="run_button",variant="primary")
85
 
86
  image_mask = gr.Image(sources=['upload','clipboard'], elem_id="mask_upload", type="pil", label="Mask_Upload",height=400, value=None)
87
  with gr.Accordion(label="Advanced Settings", open=False):