israelweiss commited on
Commit
c52d0f0
1 Parent(s): 1ae4124

redundant button, effort for faster response

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -22,17 +22,14 @@ def download_image(url):
22
  response = requests.get(url)
23
  return Image.open(BytesIO(response.content)).convert("RGB")
24
 
25
- def eraser_api_call(image_base64_file, mask_base64_file, seed, mask_type, original_quality, guidance_scale):
26
 
27
  url = "http://engine.prod.bria-api.com/v1/eraser"
28
 
29
  payload = {
30
  "file": image_base64_file,
31
  "mask_file": mask_base64_file,
32
- "seed": seed,
33
  "mask_type": mask_type,
34
- "original_quality": original_quality,
35
- "text_guidance_scale": guidance_scale
36
  }
37
  response = requests.post(url, json=payload, headers=auth_headers)
38
  response = response.json()
@@ -97,7 +94,7 @@ def read_content(file_path: str) -> str:
97
 
98
  return content
99
 
100
- def predict(dict, guidance_scale=1.2, seed=123456):
101
 
102
  init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
103
  mask = Image.fromarray(dict['layers'][0][:,:,3], 'L') #dict['layers'].convert("RGB")#.resize((1024, 1024))
@@ -106,8 +103,7 @@ def predict(dict, guidance_scale=1.2, seed=123456):
106
  mask_base64_file = convert_mask_image_to_base64_string(mask)
107
 
108
  mask_type = "manual"
109
- original_quality = True
110
- gen_img = eraser_api_call(image_base64_file, mask_base64_file, seed, mask_type, original_quality, guidance_scale)
111
 
112
  return gen_img
113
 
@@ -155,9 +151,8 @@ with image_blocks as demo:
155
  gr.Markdown("## BRIA Eraser")
156
  gr.HTML('''
157
  <p style="margin-bottom: 10px; font-size: 94%">
158
- This is a demo for
159
- <a href="https://huggingface.co/briaai/BRIA-2.3-ControlNet-Inpainting" target="_blank">BRIA 2.3 ControlNet Inpainting</a>.
160
- BRIA Eraser enables the ability to clear out and clean areas in an image or remove specific elements, while trained on licensed data, and so provide full legal liability coverage for copyright and privacy infringement.
161
  </p>
162
  ''')
163
  with gr.Row():
@@ -165,17 +160,12 @@ with image_blocks as demo:
165
  image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[], brush=gr.Brush(colors=["#000000"], color_mode="fixed"))
166
  with gr.Row(elem_id="prompt-container", equal_height=True):
167
  btn = gr.Button("Inpaint!", elem_id="run_button")
168
-
169
- with gr.Accordion(label="Advanced Settings", open=False):
170
- with gr.Row(equal_height=True):
171
- guidance_scale = gr.Number(value=1.2, minimum=0.0, maximum=2.5, step=0.1, label="guidance_scale")
172
- seed = gr.Number(value=123456, minimum=0, maximum=999999, step=1, label="seed")
173
 
174
  with gr.Column():
175
  image_out = gr.Image(label="Output", elem_id="output-img", height=400)
176
 
177
  # Button click will trigger the inpainting function (no prompt required)
178
- btn.click(fn=predict, inputs=[image, guidance_scale, seed], outputs=[image_out], api_name='run')
179
 
180
 
181
  gr.HTML(
@@ -187,4 +177,5 @@ with image_blocks as demo:
187
  """
188
  )
189
 
190
- image_blocks.queue(max_size=25,api_open=False).launch(show_api=False)
 
 
22
  response = requests.get(url)
23
  return Image.open(BytesIO(response.content)).convert("RGB")
24
 
25
+ def eraser_api_call(image_base64_file, mask_base64_file, mask_type):
26
 
27
  url = "http://engine.prod.bria-api.com/v1/eraser"
28
 
29
  payload = {
30
  "file": image_base64_file,
31
  "mask_file": mask_base64_file,
 
32
  "mask_type": mask_type,
 
 
33
  }
34
  response = requests.post(url, json=payload, headers=auth_headers)
35
  response = response.json()
 
94
 
95
  return content
96
 
97
+ def predict(dict):
98
 
99
  init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
100
  mask = Image.fromarray(dict['layers'][0][:,:,3], 'L') #dict['layers'].convert("RGB")#.resize((1024, 1024))
 
103
  mask_base64_file = convert_mask_image_to_base64_string(mask)
104
 
105
  mask_type = "manual"
106
+ gen_img = eraser_api_call(image_base64_file, mask_base64_file, mask_type)
 
107
 
108
  return gen_img
109
 
 
151
  gr.Markdown("## BRIA Eraser")
152
  gr.HTML('''
153
  <p style="margin-bottom: 10px; font-size: 94%">
154
+ This is a demo for BRIA Eraser which enables the ability to remove specific elements or objects.
155
+ The model was trained on licensed data, and so provide full legal liability coverage for copyright and privacy infringement.
 
156
  </p>
157
  ''')
158
  with gr.Row():
 
160
  image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[], brush=gr.Brush(colors=["#000000"], color_mode="fixed"))
161
  with gr.Row(elem_id="prompt-container", equal_height=True):
162
  btn = gr.Button("Inpaint!", elem_id="run_button")
 
 
 
 
 
163
 
164
  with gr.Column():
165
  image_out = gr.Image(label="Output", elem_id="output-img", height=400)
166
 
167
  # Button click will trigger the inpainting function (no prompt required)
168
+ btn.click(fn=predict, inputs=[image], outputs=[image_out], api_name='run')
169
 
170
 
171
  gr.HTML(
 
177
  """
178
  )
179
 
180
+ # image_blocks.queue(max_size=25,api_open=False).launch(show_api=False)
181
+ demo.launch()