Spaces:
Build error
Build error
Nguyen Thai Thao Uyen
commited on
Commit
·
8b13732
1
Parent(s):
c47a5b6
UI
Browse files
app.py
CHANGED
|
@@ -1,59 +1,78 @@
|
|
| 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
|
| 7 |
-
import run
|
| 8 |
|
| 9 |
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
|
| 10 |
-
from transformers import SamModel, SamConfig, SamProcessor
|
| 11 |
-
import torch
|
| 12 |
|
| 13 |
sns.set_theme()
|
| 14 |
|
| 15 |
www_dir = Path(__file__).parent.resolve() / "www"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
app_ui = ui.page_fillable(
|
| 18 |
shinyswatch.theme.minty(),
|
| 19 |
ui.layout_sidebar(
|
| 20 |
ui.sidebar(
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
),
|
| 23 |
-
ui.output_image("image"),
|
| 24 |
-
ui.output_image("image_output"),
|
| 25 |
-
ui.output_image("single_patch_prediction"),
|
| 26 |
-
ui.output_image("single_patch_prob")
|
| 27 |
),
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
def server(input: Inputs, output: Outputs, session: Session):
|
| 32 |
-
@
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
|
| 55 |
app = App(
|
| 56 |
app_ui,
|
| 57 |
server,
|
| 58 |
static_assets=str(www_dir),
|
| 59 |
-
)
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
from typing import List, Dict, Tuple
|
| 3 |
import matplotlib.colors as mpl_colors
|
| 4 |
+
|
| 5 |
import pandas as pd
|
| 6 |
import seaborn as sns
|
| 7 |
import shinyswatch
|
|
|
|
| 8 |
|
| 9 |
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
|
|
|
|
|
|
|
| 10 |
|
| 11 |
sns.set_theme()
|
| 12 |
|
| 13 |
www_dir = Path(__file__).parent.resolve() / "www"
|
| 14 |
|
| 15 |
+
df = pd.read_csv(Path(__file__).parent / "penguins.csv", na_values="NA")
|
| 16 |
+
numeric_cols: List[str] = df.select_dtypes(include=["float64"]).columns.tolist()
|
| 17 |
+
species: List[str] = df["Species"].unique().tolist()
|
| 18 |
+
species.sort()
|
| 19 |
+
|
| 20 |
app_ui = ui.page_fillable(
|
| 21 |
shinyswatch.theme.minty(),
|
| 22 |
ui.layout_sidebar(
|
| 23 |
ui.sidebar(
|
| 24 |
+
# Artwork by @allison_horst
|
| 25 |
+
ui.input_selectize(
|
| 26 |
+
"xvar",
|
| 27 |
+
"X variable",
|
| 28 |
+
numeric_cols,
|
| 29 |
+
selected="Bill Length (mm)",
|
| 30 |
+
),
|
| 31 |
+
ui.input_selectize(
|
| 32 |
+
"yvar",
|
| 33 |
+
"Y variable",
|
| 34 |
+
numeric_cols,
|
| 35 |
+
selected="Bill Depth (mm)",
|
| 36 |
+
),
|
| 37 |
+
|
| 38 |
+
),
|
| 39 |
+
ui.output_ui("value_boxes"),
|
| 40 |
+
ui.output_plot("scatter", fill=True),
|
| 41 |
+
ui.help_text(
|
| 42 |
+
"Artwork by ",
|
| 43 |
+
ui.a("@allison_horst", href="https://twitter.com/allison_horst"),
|
| 44 |
+
class_="text-end",
|
| 45 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
),
|
| 47 |
)
|
| 48 |
|
| 49 |
|
| 50 |
def server(input: Inputs, output: Outputs, session: Session):
|
| 51 |
+
# @reactive.ui
|
| 52 |
+
|
| 53 |
+
return
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# "darkorange", "purple", "cyan4"
|
| 57 |
+
colors = [[255, 140, 0], [160, 32, 240], [0, 139, 139]]
|
| 58 |
+
colors = [(r / 255.0, g / 255.0, b / 255.0) for r, g, b in colors]
|
| 59 |
+
|
| 60 |
+
palette: Dict[str, Tuple[float, float, float]] = {
|
| 61 |
+
"Adelie": colors[0],
|
| 62 |
+
"Chinstrap": colors[1],
|
| 63 |
+
"Gentoo": colors[2],
|
| 64 |
+
"default": sns.color_palette()[0], # type: ignore
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
bg_palette = {}
|
| 68 |
+
# Use `sns.set_style("whitegrid")` to help find approx alpha value
|
| 69 |
+
for name, col in palette.items():
|
| 70 |
+
# Adjusted n_colors until `axe` accessibility did not complain about color contrast
|
| 71 |
+
bg_palette[name] = mpl_colors.to_hex(sns.light_palette(col, n_colors=7)[1]) # type: ignore
|
| 72 |
|
| 73 |
|
| 74 |
app = App(
|
| 75 |
app_ui,
|
| 76 |
server,
|
| 77 |
static_assets=str(www_dir),
|
| 78 |
+
)
|