Spaces:
Build error
Build error
Nguyen Thai Thao Uyen
commited on
Commit
·
fbc5057
1
Parent(s):
a541988
Add Plot
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from pathlib import Path
|
| 2 |
from typing import List, Dict, Tuple
|
| 3 |
import matplotlib.colors as mpl_colors
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import seaborn as sns
|
| 6 |
import shinyswatch
|
|
@@ -22,9 +23,10 @@ app_ui = ui.page_fillable(
|
|
| 22 |
ui.input_file("image_input", "Upload image: ", multiple=True),
|
| 23 |
),
|
| 24 |
ui.output_image("image"),
|
| 25 |
-
ui.output_image("image_output"),
|
| 26 |
-
ui.
|
| 27 |
-
ui.output_image("
|
|
|
|
| 28 |
),
|
| 29 |
)
|
| 30 |
|
|
@@ -52,6 +54,33 @@ def server(input: Inputs, output: Outputs, session: Session):
|
|
| 52 |
return img
|
| 53 |
return None
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
app = App(
|
| 57 |
app_ui,
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
from typing import List, Dict, Tuple
|
| 3 |
import matplotlib.colors as mpl_colors
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
import pandas as pd
|
| 6 |
import seaborn as sns
|
| 7 |
import shinyswatch
|
|
|
|
| 23 |
ui.input_file("image_input", "Upload image: ", multiple=True),
|
| 24 |
),
|
| 25 |
ui.output_image("image"),
|
| 26 |
+
# ui.output_image("image_output"),
|
| 27 |
+
ui.output_plot("plot"),
|
| 28 |
+
# ui.output_image("prediction"),
|
| 29 |
+
# ui.output_image("prob")
|
| 30 |
),
|
| 31 |
)
|
| 32 |
|
|
|
|
| 54 |
return img
|
| 55 |
return None
|
| 56 |
|
| 57 |
+
@render.plot(alt="A histogram")
|
| 58 |
+
def plot():
|
| 59 |
+
if input.image_input():
|
| 60 |
+
new_image = input.image_input()[0]['datapath']
|
| 61 |
+
|
| 62 |
+
pred_prob, pred_prediction = run.pred(new_image)
|
| 63 |
+
|
| 64 |
+
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
|
| 65 |
+
|
| 66 |
+
axes[0].imshow(new_image, cmap='gray')
|
| 67 |
+
axes[0].set_title("Image")
|
| 68 |
+
|
| 69 |
+
im = axes[1].imshow(pred_prob)
|
| 70 |
+
axes[1].set_title("Probability Map")
|
| 71 |
+
cbar = fig.colorbar(im, ax=axes[1])
|
| 72 |
+
|
| 73 |
+
axes[2].imshow(pred_prediction, cmap='gray')
|
| 74 |
+
axes[2].set_title("Prediction")
|
| 75 |
+
|
| 76 |
+
for ax in axes:
|
| 77 |
+
ax.set_xticks([])
|
| 78 |
+
ax.set_yticks([])
|
| 79 |
+
ax.set_xticklabels([])
|
| 80 |
+
ax.set_yticklabels([])
|
| 81 |
+
|
| 82 |
+
return fig
|
| 83 |
+
|
| 84 |
|
| 85 |
app = App(
|
| 86 |
app_ui,
|
run.py
CHANGED
|
@@ -48,4 +48,4 @@ def pred(src):
|
|
| 48 |
pred_prediction = (pred_prob > PROBABILITY_THRES).astype(np.uint8)
|
| 49 |
|
| 50 |
x=1
|
| 51 |
-
return
|
|
|
|
| 48 |
pred_prediction = (pred_prob > PROBABILITY_THRES).astype(np.uint8)
|
| 49 |
|
| 50 |
x=1
|
| 51 |
+
return pred_prob, pred_prediction
|