|
|
import gradio as gr |
|
|
import tempfile |
|
|
from pathlib import Path |
|
|
from wrapper import run_pipeline_on_image |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
from itertools import product |
|
|
|
|
|
def show_preview(image): |
|
|
"""Show uploaded image as-is.""" |
|
|
return image |
|
|
|
|
|
def process(image): |
|
|
if image is None: |
|
|
return [] |
|
|
with tempfile.TemporaryDirectory() as tmpdir: |
|
|
|
|
|
|
|
|
ext = image.format.lower() if image.format else 'png' |
|
|
img_path = Path(tmpdir) / f"input.{ext}" |
|
|
image.save(img_path) |
|
|
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True) |
|
|
|
|
|
order = [ |
|
|
'NDVI', 'ARI', 'GNDVI' |
|
|
] |
|
|
return [outputs[k] for k in order if k in outputs] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# 🌿 Sorghum Plant Analysis Demo") |
|
|
gr.Markdown("Upload a sorghum plant image to analyze vegetation indices, texture features, and morphology.") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
inp = gr.Image(type="pil", label="Upload Image") |
|
|
run = gr.Button("Run Pipeline", variant="primary") |
|
|
with gr.Column(): |
|
|
preview = gr.Image(type="pil", label="Uploaded Image Preview", interactive=False) |
|
|
|
|
|
gallery = gr.Gallery(label="Analysis Results", columns=3, height="auto") |
|
|
|
|
|
|
|
|
inp.change(fn=show_preview, inputs=inp, outputs=preview) |
|
|
run.click(process, inputs=inp, outputs=gallery) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |