Akjava commited on
Commit
cc4a3ff
1 Parent(s): 5aff95e

change simple

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -45,30 +45,28 @@ def process_img2img(image,mask_image,prompt="a person",strength=0.75,seed=0,num_
45
  @spaces.GPU(duration=180)
46
  def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,progress=gr.Progress(track_tqdm=True)):
47
  print("start process_images")
48
- try:
49
- # I'm not sure when this happen
50
- if not isinstance(image, dict):
51
- if image2 == None:
52
- print("empty mask")
53
- return image
54
- else:
55
- image = dict({'background': image, 'layers': [image2]})
56
-
57
- if image2!=None:
58
- #print("use image2")
59
- mask = image2
60
  else:
61
- if len(image['layers']) == 0:
62
- print("empty mask")
63
- return image
64
- print("use layer")
65
- mask = image['layers'][0]
 
 
 
 
 
 
66
 
67
 
68
- output = process_img2img(image["background"],mask,prompt,strength,seed)
69
- except Exception as e:
70
- print(f"An error occurred: {e}")
71
- gr.Error(e)
72
  print("end process_images")
73
  return output
74
 
@@ -99,8 +97,8 @@ css="""
99
  max-width: 640px;
100
  }
101
  """
102
- demo_blocks = gr.Blocks(css=css, elem_id="demo-container")
103
- with demo_blocks as demo:
104
  with gr.Column():
105
  gr.HTML(read_file("demo_header.html"))
106
  with gr.Row():
@@ -110,7 +108,7 @@ with demo_blocks as demo:
110
  with gr.Row():
111
  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")
112
 
113
- btn = gr.Button("Img2Img", elem_id="run_button",variant="primary")
114
 
115
  image_mask = gr.Image(sources=['upload','clipboard'], elem_id="mask_upload", type="pil", label="Mask_Upload",height=400, value=None)
116
  with gr.Accordion(label="Advanced Settings", open=False):
@@ -127,7 +125,7 @@ with demo_blocks as demo:
127
 
128
 
129
 
130
- btn.click(fn=process_images, inputs=[image, image_mask,prompt,strength,seed], outputs =image_out, api_name='infer')
131
  gr.Examples(
132
  examples=[
133
  #["images/00547245_99.jpg", "images/00547245_99_mask.jpg","a beautiful girl,eyes closed",0.8,"images/00547245.jpg"],
@@ -145,10 +143,13 @@ with demo_blocks as demo:
145
 
146
  """
147
  )
 
 
 
 
 
 
 
 
148
 
149
- try:
150
- demo_blocks.queue(max_size=25).launch(share=False,debug=True)
151
- except Exception as e:
152
- print(f"An launch error occurred: {e}")
153
- gr.Error(e)
154
 
 
45
  @spaces.GPU(duration=180)
46
  def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,progress=gr.Progress(track_tqdm=True)):
47
  print("start process_images")
48
+
49
+ # I'm not sure when this happen
50
+ if not isinstance(image, dict):
51
+ if image2 == None:
52
+ print("empty mask")
53
+ return image
 
 
 
 
 
 
54
  else:
55
+ image = dict({'background': image, 'layers': [image2]})
56
+
57
+ if image2!=None:
58
+ #print("use image2")
59
+ mask = image2
60
+ else:
61
+ if len(image['layers']) == 0:
62
+ print("empty mask")
63
+ return image
64
+ print("use layer")
65
+ mask = image['layers'][0]
66
 
67
 
68
+ output = process_img2img(image["background"],mask,prompt,strength,seed)
69
+
 
 
70
  print("end process_images")
71
  return output
72
 
 
97
  max-width: 640px;
98
  }
99
  """
100
+
101
+ with gr.Blocks(css=css, elem_id="demo-container") as demo:
102
  with gr.Column():
103
  gr.HTML(read_file("demo_header.html"))
104
  with gr.Row():
 
108
  with gr.Row():
109
  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")
110
 
111
+ btn = gr.Button("Img2Img", elem_id="run_button",scale=0)
112
 
113
  image_mask = gr.Image(sources=['upload','clipboard'], elem_id="mask_upload", type="pil", label="Mask_Upload",height=400, value=None)
114
  with gr.Accordion(label="Advanced Settings", open=False):
 
125
 
126
 
127
 
128
+ #btn.click(fn=process_images, inputs=[image, image_mask,prompt,strength,seed], outputs =image_out, api_name='infer')
129
  gr.Examples(
130
  examples=[
131
  #["images/00547245_99.jpg", "images/00547245_99_mask.jpg","a beautiful girl,eyes closed",0.8,"images/00547245.jpg"],
 
143
 
144
  """
145
  )
146
+ gr.on(
147
+ triggers=[btn.click, prompt.submit],
148
+ fn = process_images,
149
+ inputs = [image, image_mask, prompt, strength, seed],
150
+ outputs = [image_out]
151
+ )
152
+
153
+ demo.launch()
154
 
 
 
 
 
 
155