Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,15 +53,43 @@ class Segmenter:
|
|
| 53 |
output_predictions: torch.Tensor = output.argmax(0)
|
| 54 |
return self.colorizer.colorize(output_predictions)
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
-
|
|
|
|
|
|
|
|
|
| 53 |
output_predictions: torch.Tensor = output.argmax(0)
|
| 54 |
return self.colorizer.colorize(output_predictions)
|
| 55 |
|
| 56 |
+
class GradioApp:
|
| 57 |
+
def __init__(self, segmenter: Segmenter):
|
| 58 |
+
self.segmenter = segmenter
|
| 59 |
|
| 60 |
+
def launch(self):
|
| 61 |
+
with gr.Blocks() as demo:
|
| 62 |
+
gr.Markdown("<h1 style='text-align: center; color: #4CAF50;'>Deeplabv3 Segmentation</h1>")
|
| 63 |
+
gr.Markdown("<p style='text-align: center;'>Upload an image to perform semantic segmentation using Deeplabv3 ResNet101.</p>")
|
| 64 |
+
gr.Markdown("""
|
| 65 |
+
### Model Information
|
| 66 |
+
**DeepLabv3 with ResNet101** is a convolutional neural network model designed for semantic image segmentation.
|
| 67 |
+
It utilizes atrous convolution to capture multi-scale context by using different atrous rates.
|
| 68 |
+
""")
|
| 69 |
+
with gr.Row():
|
| 70 |
+
with gr.Column():
|
| 71 |
+
image_input = gr.Image(type='pil', label="Input Image", show_label=False)
|
| 72 |
+
with gr.Column():
|
| 73 |
+
image_output = gr.Image(type='pil', label="Segmented Output", show_label=False)
|
| 74 |
+
|
| 75 |
+
button = gr.Button("Segment")
|
| 76 |
+
button.click(fn=self.segmenter.segment, inputs=image_input, outputs=image_output)
|
| 77 |
+
|
| 78 |
+
gr.Markdown("### Example Images")
|
| 79 |
+
gr.Examples(
|
| 80 |
+
examples=[
|
| 81 |
+
["https://www.timeforkids.com/wp-content/uploads/2024/01/Snapshot_20240126.jpg?w=1024"],
|
| 82 |
+
["https://www.timeforkids.com/wp-content/uploads/2023/09/G3G5_230915_puffins_on_the_rise.jpg?w=1024"],
|
| 83 |
+
["https://www.timeforkids.com/wp-content/uploads/2024/03/G3G5_240412_bug_eyed.jpg?w=1024"]
|
| 84 |
+
],
|
| 85 |
+
inputs=image_input,
|
| 86 |
+
outputs=image_output,
|
| 87 |
+
label="Click an example to use it"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
demo.launch()
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
+
segmenter = Segmenter()
|
| 94 |
+
app = GradioApp(segmenter)
|
| 95 |
+
app.launch()
|