Spaces:
Sleeping
Sleeping
Nunzio commited on
Commit ·
ef2b3d9
1
Parent(s): 335b126
index
Browse files
app.py
CHANGED
|
@@ -19,9 +19,6 @@ MODELS = {
|
|
| 19 |
|
| 20 |
|
| 21 |
def load_example(index:int=0, useGta:bool=True)-> gr.Image:
|
| 22 |
-
print(type(index))
|
| 23 |
-
print(index)
|
| 24 |
-
print(useGta)
|
| 25 |
example_img = loadPreloadedImages(gta_image_dir if useGta else city_image_dir)
|
| 26 |
return gr.update(value=example_img[index if 0 <= index < len(example_img) else 0], visible=True)
|
| 27 |
|
|
@@ -67,7 +64,7 @@ def run_prediction(image: gr.Image, selected_model: str)-> tuple[torch.Tensor]:
|
|
| 67 |
# Gradio UI
|
| 68 |
with gr.Blocks(title="Semantic Segmentation Predictors") as demo:
|
| 69 |
gr.Markdown("# Semantic Segmentation with Real-Time Networks")
|
| 70 |
-
gr.Markdown('A small user interface created to run semantic segmentation on images using
|
| 71 |
gr.Markdown("Upload an image and choose your preferred model for segmentation, or otherwise use one of the preloaded images.")
|
| 72 |
|
| 73 |
with gr.Row():
|
|
@@ -82,25 +79,37 @@ with gr.Blocks(title="Semantic Segmentation Predictors") as demo:
|
|
| 82 |
with gr.Column():
|
| 83 |
result_display = gr.Image(label="Model prediction", visible=True)
|
| 84 |
error_text = gr.Markdown("", visible=False)
|
| 85 |
-
|
| 86 |
with gr.Row():
|
| 87 |
gr.Markdown("## Preloaded GTA V images to be used for testing the model")
|
| 88 |
with gr.Row():
|
| 89 |
-
gta_gallery = gr.Gallery(
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
gr.Markdown("## Preloaded Cityscapes images to be used for testing the model")
|
| 96 |
with gr.Row():
|
| 97 |
-
city_gallery = gr.Gallery(
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
submit_btn.click(
|
| 106 |
fn=run_prediction,
|
|
@@ -108,7 +117,7 @@ with gr.Blocks(title="Semantic Segmentation Predictors") as demo:
|
|
| 108 |
outputs=[result_display, error_text],
|
| 109 |
)
|
| 110 |
|
| 111 |
-
gr.Markdown("Made by group 21 semantic segmentation project at Politecnico di Torino 2024
|
| 112 |
|
| 113 |
demo.launch()
|
| 114 |
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def load_example(index:int=0, useGta:bool=True)-> gr.Image:
|
|
|
|
|
|
|
|
|
|
| 22 |
example_img = loadPreloadedImages(gta_image_dir if useGta else city_image_dir)
|
| 23 |
return gr.update(value=example_img[index if 0 <= index < len(example_img) else 0], visible=True)
|
| 24 |
|
|
|
|
| 64 |
# Gradio UI
|
| 65 |
with gr.Blocks(title="Semantic Segmentation Predictors") as demo:
|
| 66 |
gr.Markdown("# Semantic Segmentation with Real-Time Networks")
|
| 67 |
+
gr.Markdown('A small user interface created to run semantic segmentation on images using Cityscapes-like predictions and real-time segmentation networks.')
|
| 68 |
gr.Markdown("Upload an image and choose your preferred model for segmentation, or otherwise use one of the preloaded images.")
|
| 69 |
|
| 70 |
with gr.Row():
|
|
|
|
| 79 |
with gr.Column():
|
| 80 |
result_display = gr.Image(label="Model prediction", visible=True)
|
| 81 |
error_text = gr.Markdown("", visible=False)
|
| 82 |
+
|
| 83 |
with gr.Row():
|
| 84 |
gr.Markdown("## Preloaded GTA V images to be used for testing the model")
|
| 85 |
with gr.Row():
|
| 86 |
+
gta_gallery = gr.Gallery(
|
| 87 |
+
value=loadPreloadedImages(gta_image_dir),
|
| 88 |
+
label="GTA V Examples",
|
| 89 |
+
show_label=False,
|
| 90 |
+
columns=5,
|
| 91 |
+
type="index",
|
| 92 |
+
rows=1,
|
| 93 |
+
height=200,
|
| 94 |
+
allow_preview=False
|
| 95 |
)
|
| 96 |
|
| 97 |
with gr.Row():
|
| 98 |
gr.Markdown("## Preloaded Cityscapes images to be used for testing the model")
|
| 99 |
with gr.Row():
|
| 100 |
+
city_gallery = gr.Gallery(
|
| 101 |
+
value=loadPreloadedImages(city_image_dir),
|
| 102 |
+
label="Cityscapes Examples",
|
| 103 |
+
show_label=False,
|
| 104 |
+
columns=5,
|
| 105 |
+
type="index",
|
| 106 |
+
rows=1,
|
| 107 |
+
height=256,
|
| 108 |
+
allow_preview=False
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
gta_gallery.select(fn=lambda i: load_example(i, True), inputs=[], outputs=image_input)
|
| 112 |
+
city_gallery.select(fn=lambda i: load_example(i, False), inputs=[], outputs=image_input)
|
| 113 |
|
| 114 |
submit_btn.click(
|
| 115 |
fn=run_prediction,
|
|
|
|
| 117 |
outputs=[result_display, error_text],
|
| 118 |
)
|
| 119 |
|
| 120 |
+
gr.Markdown("Made by group 21 semantic segmentation project at Politecnico di Torino 2024–2025")
|
| 121 |
|
| 122 |
demo.launch()
|
| 123 |
|