|
|
import gradio as gr |
|
|
import tempfile |
|
|
from pathlib import Path |
|
|
from wrapper import run_pipeline_on_image |
|
|
|
|
|
def process(image): |
|
|
if image is None: |
|
|
return [] |
|
|
with tempfile.TemporaryDirectory() as tmpdir: |
|
|
|
|
|
img_path = Path(tmpdir) / "input.png" |
|
|
image.save(img_path) |
|
|
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True) |
|
|
|
|
|
order = [ |
|
|
'NDVI', 'ARI', 'GNDVI', 'LBP', 'HOG', 'Lacunarity', 'SizeAnalysis' |
|
|
] |
|
|
return [outputs[k] for k in order if k in outputs] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# 🌿 Sorghum Single-Image Demo") |
|
|
inp = gr.Image(type="pil", label="Upload Image") |
|
|
run = gr.Button("Run Pipeline", variant="primary") |
|
|
gallery = gr.Gallery(label="Outputs") |
|
|
run.click(process, inputs=inp, outputs=gallery) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |