Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,17 +18,31 @@ live_preds = None
|
|
| 18 |
|
| 19 |
def rotate_btn_fn(img_path, xt, yt, zt, add_bone_cmap=False):
|
| 20 |
global current_img
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return out_img
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
return out_img
|
| 32 |
|
| 33 |
css_style = "./style.css"
|
| 34 |
callback = gr.CSVLogger()
|
|
@@ -40,7 +54,7 @@ with gr.Blocks(css=css_style, title="RadRotator") as app:
|
|
| 40 |
|
| 41 |
with gr.TabItem("Demo"):
|
| 42 |
with gr.Row():
|
| 43 |
-
input_img = gr.Image(type='filepath', label='Input image',
|
| 44 |
output_img = gr.Image(type='pil', label='Output image', interactive=False, elem_classes='imgs')
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column(scale=0.25):
|
|
@@ -70,8 +84,8 @@ with gr.Blocks(css=css_style, title="RadRotator") as app:
|
|
| 70 |
try:
|
| 71 |
app.close()
|
| 72 |
gr.close_all()
|
| 73 |
-
except:
|
| 74 |
-
|
| 75 |
|
| 76 |
demo = app.launch(
|
| 77 |
max_threads=4,
|
|
|
|
| 18 |
|
| 19 |
def rotate_btn_fn(img_path, 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 not os.path.exists(img_path):
|
| 27 |
+
raise FileNotFoundError(f"Input image path does not exist: {img_path}")
|
| 28 |
+
|
| 29 |
+
out_img_path = f'data/cached_outputs/{os.path.basename(img_path)[:-4]}_{angles}.png'
|
| 30 |
+
if not os.path.exists(out_img_path):
|
| 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 |
+
|
| 37 |
+
cmap = plt.get_cmap('bone')
|
| 38 |
+
out_img = cmap(out_img)
|
| 39 |
+
out_img = (out_img[..., :3] * 255).astype(np.uint8)
|
| 40 |
+
current_img = out_img
|
| 41 |
return out_img
|
| 42 |
+
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"Error in rotate_btn_fn: {e}")
|
| 45 |
+
return None
|
|
|
|
| 46 |
|
| 47 |
css_style = "./style.css"
|
| 48 |
callback = gr.CSVLogger()
|
|
|
|
| 54 |
|
| 55 |
with gr.TabItem("Demo"):
|
| 56 |
with gr.Row():
|
| 57 |
+
input_img = gr.Image(type='filepath', label='Input image', interactive=True, elem_classes='imgs')
|
| 58 |
output_img = gr.Image(type='pil', label='Output image', interactive=False, elem_classes='imgs')
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column(scale=0.25):
|
|
|
|
| 84 |
try:
|
| 85 |
app.close()
|
| 86 |
gr.close_all()
|
| 87 |
+
except Exception as e:
|
| 88 |
+
print(f"Error closing app: {e}")
|
| 89 |
|
| 90 |
demo = app.launch(
|
| 91 |
max_threads=4,
|