Spaces:
Sleeping
Sleeping
Nunzio commited on
Commit ·
4912b0e
1
Parent(s): f3229fd
added image handling
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import torch, uuid
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
from utils.imageHandling import hfImageToTensor, preprocessing, postprocessing, loadPreloadedImages
|
| 5 |
from model.modelLoading import loadBiSeNet, loadBiSeNetV2
|
|
@@ -18,6 +19,7 @@ MODELS = {
|
|
| 18 |
}
|
| 19 |
|
| 20 |
|
|
|
|
| 21 |
image_list = loadPreloadedImages(gta_image_dir, city_image_dir, turin_image_dir)
|
| 22 |
uuid_to_path = dict()
|
| 23 |
|
|
@@ -26,6 +28,10 @@ for i in range(len(image_list)):
|
|
| 26 |
uuid_to_path[uid] = image_list[i][1]
|
| 27 |
image_list[i][1] = uid
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# %% prediction on an image
|
| 31 |
|
|
@@ -90,9 +96,10 @@ with gr.Blocks(title="Semantic Segmentation Predictors") as demo:
|
|
| 90 |
with gr.Row():
|
| 91 |
image_gallery = gr.Gallery(value=image_list, label="Preloaded Examples",
|
| 92 |
type="value", columns=5, rows=4,
|
| 93 |
-
height=
|
| 94 |
)
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
submit_btn.click(
|
| 98 |
fn=run_prediction,
|
|
|
|
| 1 |
import torch, uuid
|
| 2 |
import gradio as gr
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
from utils.imageHandling import hfImageToTensor, preprocessing, postprocessing, loadPreloadedImages
|
| 6 |
from model.modelLoading import loadBiSeNet, loadBiSeNetV2
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
|
| 22 |
+
|
| 23 |
image_list = loadPreloadedImages(gta_image_dir, city_image_dir, turin_image_dir)
|
| 24 |
uuid_to_path = dict()
|
| 25 |
|
|
|
|
| 28 |
uuid_to_path[uid] = image_list[i][1]
|
| 29 |
image_list[i][1] = uid
|
| 30 |
|
| 31 |
+
def handle_image_click(uid):
|
| 32 |
+
return Image.open(uuid_to_path.get(uid)).convert("RGB")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
|
| 36 |
# %% prediction on an image
|
| 37 |
|
|
|
|
| 96 |
with gr.Row():
|
| 97 |
image_gallery = gr.Gallery(value=image_list, label="Preloaded Examples",
|
| 98 |
type="value", columns=5, rows=4,
|
| 99 |
+
height=1050, allow_preview=False, show_label=False,
|
| 100 |
)
|
| 101 |
+
|
| 102 |
+
image_gallery.select(fn=handle_image_click, inputs=[], outputs=image_input)
|
| 103 |
|
| 104 |
submit_btn.click(
|
| 105 |
fn=run_prediction,
|