Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def process_image(image, prompt):
|
|
| 27 |
return mask
|
| 28 |
|
| 29 |
def get_masks(prompts, img, threshold):
|
| 30 |
-
prompts =
|
| 31 |
masks = []
|
| 32 |
for prompt in prompts:
|
| 33 |
mask = process_image(img, prompt)
|
|
@@ -43,7 +43,7 @@ def extract_image(pos_prompts, neg_prompts, img, threshold):
|
|
| 43 |
neg_mask = np.any(np.stack(negative_masks), axis=0)
|
| 44 |
final_mask = pos_mask & ~neg_mask
|
| 45 |
|
| 46 |
-
final_mask = Image.fromarray(
|
| 47 |
output_image = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
| 48 |
output_image.paste(img, mask=final_mask)
|
| 49 |
return output_image, final_mask
|
|
@@ -62,7 +62,10 @@ iface = gr.Interface(
|
|
| 62 |
],
|
| 63 |
)
|
| 64 |
|
| 65 |
-
#
|
|
|
|
|
|
|
|
|
|
| 66 |
api_interface = gr.Interface(
|
| 67 |
fn=extract_image,
|
| 68 |
inputs=[
|
|
@@ -78,6 +81,5 @@ api_interface = gr.Interface(
|
|
| 78 |
live=True # Setting live to True enables the API endpoint
|
| 79 |
)
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
iface.launch()
|
| 83 |
api_interface.launch(share=True) # share=True allows external access to the API
|
|
|
|
| 27 |
return mask
|
| 28 |
|
| 29 |
def get_masks(prompts, img, threshold):
|
| 30 |
+
prompts = prompts.split(",")
|
| 31 |
masks = []
|
| 32 |
for prompt in prompts:
|
| 33 |
mask = process_image(img, prompt)
|
|
|
|
| 43 |
neg_mask = np.any(np.stack(negative_masks), axis=0)
|
| 44 |
final_mask = pos_mask & ~neg_mask
|
| 45 |
|
| 46 |
+
final_mask = Image.fromarray(final_mask.astype(np.uint8) * 255, "L")
|
| 47 |
output_image = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
| 48 |
output_image.paste(img, mask=final_mask)
|
| 49 |
return output_image, final_mask
|
|
|
|
| 62 |
],
|
| 63 |
)
|
| 64 |
|
| 65 |
+
# Launch Gradio UI
|
| 66 |
+
iface.launch()
|
| 67 |
+
|
| 68 |
+
# Define API interface
|
| 69 |
api_interface = gr.Interface(
|
| 70 |
fn=extract_image,
|
| 71 |
inputs=[
|
|
|
|
| 81 |
live=True # Setting live to True enables the API endpoint
|
| 82 |
)
|
| 83 |
|
| 84 |
+
# Launch API
|
|
|
|
| 85 |
api_interface.launch(share=True) # share=True allows external access to the API
|