Fahimeh Orvati Nia
commited on
Commit
·
3c8af25
1
Parent(s):
e768711
update
Browse files
app.py
CHANGED
|
@@ -7,8 +7,13 @@ from PIL import Image
|
|
| 7 |
from itertools import product
|
| 8 |
|
| 9 |
def show_preview(image):
|
| 10 |
-
"""Show uploaded image
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def process(image):
|
| 14 |
if image is None:
|
|
@@ -21,10 +26,23 @@ def process(image):
|
|
| 21 |
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True)
|
| 22 |
|
| 23 |
# Assemble displays
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
order = ['NDVI', 'ARI', 'GNDVI']
|
| 27 |
-
gallery_items = [outputs[k] for k in order if k in outputs]
|
| 28 |
stats_text = outputs.get('StatsText', '')
|
| 29 |
return overlay, mask, gallery_items, stats_text
|
| 30 |
|
|
@@ -40,8 +58,8 @@ with gr.Blocks() as demo:
|
|
| 40 |
preview = gr.Image(type="pil", label="Uploaded Image Preview", interactive=False)
|
| 41 |
|
| 42 |
with gr.Row():
|
| 43 |
-
overlay_img = gr.Image(type="
|
| 44 |
-
mask_img = gr.Image(type="
|
| 45 |
|
| 46 |
gallery = gr.Gallery(label="Vegetation Indices", columns=3, height="auto")
|
| 47 |
stats = gr.Textbox(label="Statistics", lines=4)
|
|
|
|
| 7 |
from itertools import product
|
| 8 |
|
| 9 |
def show_preview(image):
|
| 10 |
+
"""Show uploaded image, converted to RGB for reliable preview rendering."""
|
| 11 |
+
if image is None:
|
| 12 |
+
return None
|
| 13 |
+
try:
|
| 14 |
+
return image.convert("RGB")
|
| 15 |
+
except Exception:
|
| 16 |
+
return image
|
| 17 |
|
| 18 |
def process(image):
|
| 19 |
if image is None:
|
|
|
|
| 26 |
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True)
|
| 27 |
|
| 28 |
# Assemble displays
|
| 29 |
+
def load_pil(path_str):
|
| 30 |
+
try:
|
| 31 |
+
if not path_str:
|
| 32 |
+
return None
|
| 33 |
+
im = Image.open(path_str)
|
| 34 |
+
im = im.convert('RGB')
|
| 35 |
+
# Copy to memory so it survives after tmpdir is removed
|
| 36 |
+
copied = im.copy()
|
| 37 |
+
im.close()
|
| 38 |
+
return copied
|
| 39 |
+
except Exception:
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
overlay = load_pil(outputs.get('Overlay'))
|
| 43 |
+
mask = load_pil(outputs.get('Mask'))
|
| 44 |
order = ['NDVI', 'ARI', 'GNDVI']
|
| 45 |
+
gallery_items = [load_pil(outputs[k]) for k in order if k in outputs]
|
| 46 |
stats_text = outputs.get('StatsText', '')
|
| 47 |
return overlay, mask, gallery_items, stats_text
|
| 48 |
|
|
|
|
| 58 |
preview = gr.Image(type="pil", label="Uploaded Image Preview", interactive=False)
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
+
overlay_img = gr.Image(type="pil", label="Segmentation Overlay", interactive=False)
|
| 62 |
+
mask_img = gr.Image(type="pil", label="Mask", interactive=False)
|
| 63 |
|
| 64 |
gallery = gr.Gallery(label="Vegetation Indices", columns=3, height="auto")
|
| 65 |
stats = gr.Textbox(label="Statistics", lines=4)
|