Fahimeh Orvati Nia
commited on
Commit
·
49abd9f
1
Parent(s):
d807150
update
Browse files- app.py +12 -3
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -3,12 +3,21 @@ import tempfile
|
|
| 3 |
from pathlib import Path
|
| 4 |
from wrapper import run_pipeline_on_image
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def process(image):
|
| 7 |
if image is None:
|
| 8 |
return []
|
| 9 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 10 |
-
# Save PIL image
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
image.save(img_path)
|
| 13 |
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True)
|
| 14 |
# Keep order consistent: return exactly the 7 images
|
|
@@ -31,7 +40,7 @@ with gr.Blocks() as demo:
|
|
| 31 |
gallery = gr.Gallery(label="Analysis Results", columns=3, height="auto")
|
| 32 |
|
| 33 |
# Update preview when image is uploaded
|
| 34 |
-
inp.change(fn=
|
| 35 |
run.click(process, inputs=inp, outputs=gallery)
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
from wrapper import run_pipeline_on_image
|
| 5 |
|
| 6 |
+
def show_preview(image):
|
| 7 |
+
"""Show the original uploaded image as-is."""
|
| 8 |
+
if image is None:
|
| 9 |
+
return None
|
| 10 |
+
# Return original image without conversion
|
| 11 |
+
return image
|
| 12 |
+
|
| 13 |
def process(image):
|
| 14 |
if image is None:
|
| 15 |
return []
|
| 16 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 17 |
+
# Save PIL image preserving original format
|
| 18 |
+
# Determine extension from image format
|
| 19 |
+
ext = image.format.lower() if image.format else 'png'
|
| 20 |
+
img_path = Path(tmpdir) / f"input.{ext}"
|
| 21 |
image.save(img_path)
|
| 22 |
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True)
|
| 23 |
# Keep order consistent: return exactly the 7 images
|
|
|
|
| 40 |
gallery = gr.Gallery(label="Analysis Results", columns=3, height="auto")
|
| 41 |
|
| 42 |
# Update preview when image is uploaded
|
| 43 |
+
inp.change(fn=show_preview, inputs=inp, outputs=preview)
|
| 44 |
run.click(process, inputs=inp, outputs=gallery)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -9,4 +9,6 @@ scikit-image
|
|
| 9 |
scikit-learn
|
| 10 |
scipy
|
| 11 |
matplotlib
|
| 12 |
-
plantcv
|
|
|
|
|
|
|
|
|
| 9 |
scikit-learn
|
| 10 |
scipy
|
| 11 |
matplotlib
|
| 12 |
+
plantcv
|
| 13 |
+
kornia
|
| 14 |
+
timm
|