Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,14 +74,13 @@ def process_input_image(image_source, download_masks=False):
|
|
| 74 |
|
| 75 |
mask_zip, output_name = create_mask_zip(predicted_image)
|
| 76 |
if download_masks:
|
| 77 |
-
masks_zip.set_attributes(label="Download Masks", filename="masks.zip", hidden=False)
|
| 78 |
return "Predicted Masked Image", rgb_image, mask_zip, output_name
|
| 79 |
else:
|
| 80 |
-
masks_zip.set_attributes(hidden=True)
|
| 81 |
return "Predicted Masked Image", rgb_image, None, None
|
| 82 |
|
| 83 |
|
| 84 |
|
|
|
|
| 85 |
my_app = gr.Blocks()
|
| 86 |
|
| 87 |
|
|
@@ -103,6 +102,33 @@ def create_mask_zip(mask, output_name='masks.zip'):
|
|
| 103 |
buffer.seek(0)
|
| 104 |
return buffer, output_name
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
# Define the custom legend HTML
|
| 108 |
legend_html = '''
|
|
|
|
| 74 |
|
| 75 |
mask_zip, output_name = create_mask_zip(predicted_image)
|
| 76 |
if download_masks:
|
|
|
|
| 77 |
return "Predicted Masked Image", rgb_image, mask_zip, output_name
|
| 78 |
else:
|
|
|
|
| 79 |
return "Predicted Masked Image", rgb_image, None, None
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
+
|
| 84 |
my_app = gr.Blocks()
|
| 85 |
|
| 86 |
|
|
|
|
| 102 |
buffer.seek(0)
|
| 103 |
return buffer, output_name
|
| 104 |
|
| 105 |
+
class MaskZipOutput(gr.outputs.OutputComponent):
|
| 106 |
+
def __init__(self):
|
| 107 |
+
self.label = "Download Masks"
|
| 108 |
+
self.filename = "masks.zip"
|
| 109 |
+
self.mime_type = "application/zip"
|
| 110 |
+
|
| 111 |
+
def get_template_context(self):
|
| 112 |
+
return {
|
| 113 |
+
"label": self.label,
|
| 114 |
+
"filename": self.filename,
|
| 115 |
+
"mime_type": self.mime_type
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
def component_type(self):
|
| 119 |
+
return "output.file"
|
| 120 |
+
|
| 121 |
+
def to_response(self, value):
|
| 122 |
+
if value is None:
|
| 123 |
+
return {}
|
| 124 |
+
return {
|
| 125 |
+
"file": {
|
| 126 |
+
"name": self.filename,
|
| 127 |
+
"content": value.read(),
|
| 128 |
+
"mime_type": self.mime_type
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
|
| 133 |
# Define the custom legend HTML
|
| 134 |
legend_html = '''
|