File size: 1,475 Bytes
9def24b
 
 
 
 
 
c47a5b6
9def24b
 
c47a5b6
 
9def24b
 
 
 
 
 
 
 
 
c47a5b6
9def24b
c47a5b6
 
 
 
9def24b
 
 
 
 
 
c47a5b6
 
 
 
 
 
 
 
9def24b
 
c47a5b6
 
 
 
 
 
 
 
 
 
9def24b
 
 
 
 
 
c47a5b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path
from typing import List, Dict, Tuple
import matplotlib.colors as mpl_colors
import pandas as pd
import seaborn as sns
import shinyswatch
import run

from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
from transformers import SamModel, SamConfig, SamProcessor
import torch

sns.set_theme()

www_dir = Path(__file__).parent.resolve() / "www"

app_ui = ui.page_fillable(
    shinyswatch.theme.minty(),
    ui.layout_sidebar(
        ui.sidebar(
            ui.input_file("image_input", "Upload image: ", multiple=True),
        ),
        ui.output_image("image"),
        ui.output_image("image_output"),
        ui.output_image("single_patch_prediction"),
        ui.output_image("single_patch_prob")
    ),
)


def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.image
    def image():
        here = Path(__file__).parent
        if input.image_input():
            src = input.image_input()[0]['datapath']
            img = {"src": src, "width": "500px"} 
            return img
        return None

    @output
    @render.image
    def image_output():
        here = Path(__file__).parent
        if input.image_input():
            src = input.image_input()[0]['datapath']
            img = {"src": src, "width": "500px"} 
            x = run.pred(src)
            print(x)
            return img
        return None


app = App(
    app_ui,
    server,
    static_assets=str(www_dir),
)