Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,21 +16,28 @@ from io_utils import LoadImageD
|
|
| 16 |
current_img = None
|
| 17 |
live_preds = None
|
| 18 |
|
| 19 |
-
def rotate_btn_fn(
|
| 20 |
global current_img
|
| 21 |
|
| 22 |
try:
|
| 23 |
angles = (xt, yt, zt)
|
| 24 |
print(f"Rotating with angles: {angles}")
|
| 25 |
|
| 26 |
-
if
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
out_img_path = f'data/cached_outputs/{os.path.basename(
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
raise FileNotFoundError(f"Output image path does not exist: {out_img_path}")
|
| 32 |
|
| 33 |
-
out_img = skimage.io.imread(out_img_path)
|
| 34 |
if not add_bone_cmap:
|
| 35 |
return out_img
|
| 36 |
|
|
@@ -54,8 +61,8 @@ with gr.Blocks(css=css_style, title="RadRotator") as app:
|
|
| 54 |
|
| 55 |
with gr.TabItem("Demo"):
|
| 56 |
with gr.Row():
|
| 57 |
-
input_img = gr.Image(type='
|
| 58 |
-
output_img = gr.Image(type='
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column(scale=0.25):
|
| 61 |
pass
|
|
|
|
| 16 |
current_img = None
|
| 17 |
live_preds = None
|
| 18 |
|
| 19 |
+
def rotate_btn_fn(img, xt, yt, zt, add_bone_cmap=False):
|
| 20 |
global current_img
|
| 21 |
|
| 22 |
try:
|
| 23 |
angles = (xt, yt, zt)
|
| 24 |
print(f"Rotating with angles: {angles}")
|
| 25 |
|
| 26 |
+
if isinstance(img, np.ndarray):
|
| 27 |
+
input_img_path = "uploaded_image.png"
|
| 28 |
+
skimage.io.imsave(input_img_path, img)
|
| 29 |
+
elif isinstance(img, str) and os.path.exists(img):
|
| 30 |
+
input_img_path = img
|
| 31 |
+
else:
|
| 32 |
+
raise ValueError("Invalid input image")
|
| 33 |
|
| 34 |
+
out_img_path = f'data/cached_outputs/{os.path.basename(input_img_path)[:-4]}_{angles}.png'
|
| 35 |
+
|
| 36 |
+
if os.path.exists(out_img_path):
|
| 37 |
+
out_img = skimage.io.imread(out_img_path)
|
| 38 |
+
else:
|
| 39 |
raise FileNotFoundError(f"Output image path does not exist: {out_img_path}")
|
| 40 |
|
|
|
|
| 41 |
if not add_bone_cmap:
|
| 42 |
return out_img
|
| 43 |
|
|
|
|
| 61 |
|
| 62 |
with gr.TabItem("Demo"):
|
| 63 |
with gr.Row():
|
| 64 |
+
input_img = gr.Image(type='numpy', label='Input image', interactive=True, elem_classes='imgs')
|
| 65 |
+
output_img = gr.Image(type='numpy', label='Output image', interactive=False, elem_classes='imgs')
|
| 66 |
with gr.Row():
|
| 67 |
with gr.Column(scale=0.25):
|
| 68 |
pass
|