Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from fastai.vision.all import *
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
pred = learner.predict(img)
|
| 10 |
return pred[0]
|
| 11 |
|
| 12 |
|
| 13 |
def create_interface():
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
output = gr.Text()
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=predict_image,
|
| 21 |
inputs=image_input,
|
| 22 |
outputs=output,
|
| 23 |
-
title="
|
| 24 |
-
description="Upload an image to
|
| 25 |
)
|
| 26 |
return iface
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
iface = create_interface()
|
| 30 |
iface.launch(share=True)
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from fastai.vision.all import *
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Model Loading (Choose ONE)
|
| 7 |
+
# learner = load_learner('export_2.pkl') # If using exported pickle model
|
| 8 |
+
learner = load_learner('model-epoch=119.ckpt') # If using checkpoint
|
| 9 |
+
|
| 10 |
+
def predict_image(file):
|
| 11 |
+
if file.name.endswith('.npz'):
|
| 12 |
+
# Load NPZ data
|
| 13 |
+
with np.load(file.name) as data:
|
| 14 |
+
# Assuming your NPZ file contains an array named 'arr_0'
|
| 15 |
+
img_array = data['arr_0']
|
| 16 |
+
# Ensure correct dimensions (e.g., channels last)
|
| 17 |
+
# img_array = img_array.transpose((1, 2, 0)) # If needed
|
| 18 |
+
img = Image.fromarray(img_array)
|
| 19 |
+
else:
|
| 20 |
+
# Load regular image files (JPG, PNG, etc.)
|
| 21 |
+
img = PILImage.create(file.name)
|
| 22 |
pred = learner.predict(img)
|
| 23 |
return pred[0]
|
| 24 |
|
| 25 |
|
| 26 |
def create_interface():
|
| 27 |
+
image_input = gr.File(
|
| 28 |
+
label="Upload Image or NPZ",
|
| 29 |
+
file_types=[".jpg", ".jpeg", ".png", ".npz"]
|
| 30 |
+
)
|
| 31 |
output = gr.Text()
|
| 32 |
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=predict_image,
|
| 35 |
inputs=image_input,
|
| 36 |
outputs=output,
|
| 37 |
+
title="Medical Image Segmentation", # More informative title
|
| 38 |
+
description="Upload an image or NPZ file to segment." # Clear description
|
| 39 |
)
|
| 40 |
return iface
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
iface = create_interface()
|
| 44 |
iface.launch(share=True)
|
|
|
|
|
|