-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
147 lines (115 loc) · 5.8 KB
/
server.R
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
library(shiny)
library(golem)
library(shinydashboard)
library(shinydashboardPlus)
library(shinythemes)
library(shinyBS)
library(plotly)
library(png)
library(yaml)
library(reticulate)
library(ggplot2)
library(oro.nifti)
##### For Server Deployment use a virtual Python Env
# virtualenv_create('pyDev',python = 'python3')
# virtualenv_install("pyDev", packages = c('torch','pillow','numpy','pybase64','uuid','diffusers','accelerate','nibabel'))
use_virtualenv("pyDev", required = TRUE)
py_libs <- import("cgan_inference")
py_libs_inference_v2 <- import("cgan_inference_v2")
# For local PC testing use conda...
# Create a new "pytorch_env" environment first
# https://rstudio.github.io/reticulate/articles/python_packages.html
# library(reticulate)
# conda_create(name = "pytorch_env",
# packages = c("python=3.8", "torch", "pillow", "numpy", "pybase64", "uuid"))
# in terminal
# %> conda create --name pytorch_env python=3.8
# %> conda activate pytorch_env
# %> pip install torch pillow numpy pybase64 uuid
# use_condaenv(condaenv = "pytorch_env", required = TRUE)
# # conda_install(envname = "pytorch_env", packages = "nibabel")
# py_libs <- import("cgan_inference")
# py_libs_inference_v2 <- import("cgan_inference_v2")
# py_libs_inference_3d_v1 <- import("gan_3d_inference_v1")
imgpath <- paste0(getwd() , "/images/")
addResourcePath("images", imgpath)
# app_server <- function(input, output) {}
# read configuration file
config <- read_yaml("configs/config.yaml")
uiconfig <- read_yaml("configs/ui_config.yaml")
img_list <-list()
# load variables from configs
img_folder_path <- config$img_path
img_width <- uiconfig$img_width
img_height <- uiconfig$img_height
scale_factor <- uiconfig$scale_factor
source("R/server/brain_gen_2d_server.R")
source("R/server/brain_gen_2d_v2_server.R")
source("R/server/brain_gen_3d_v1_server.R")
app_server <- function(input, output, session) {
observeEvent(input$sliceOrein_p2, {
choices <- switch(input$sliceOrein_p2,
"Axial" = c("Superior", "Middle", "Inferior"),
"Sagittal" = c("Left", "Middle", "Right"),
"Coronal" = c("Front", "Middle", "Back"),
NULL)
updateSelectInput(session, "sliceLoc_p2", choices = choices)
})
brain_gen_3d_v1_panel_server(input, output, session,py_libs_inference_3d_v1)
brain_gen_2d_v2_panel_server(input, output, session,py_libs_inference_v2)
brain_gen_2d_panel_server(input, output, session,py_libs)
# img_list <-list()
output$session_info <- renderUI({
i <- c("<h4>R session info </h4>")
i <- c(i, capture.output(sessionInfo()))
HTML(paste(i, collapse = "<br/>"))
})
observeEvent(input$show_modal, {
shiny::showModal(
shiny::modalDialog(title = "SOCR 2D Synthetic Brain Image Generator Help",
size = "l", easyClose = TRUE,
h5(paste0("See the About tab for additional information ",
"About GAN GAIM model, app organization and use, and other ",
"supporting information.")),
h5("The SOCR 2D Synthetic Image Generator is free and requires no external ",
"pay-to-play API keys.",
h6(
paste(input$modelSelect_p2," is a conditional deep learning model for brain image generation with 7.7 million parameters.")
),
# if(input$modelSelect == "brainGen_v1"){
# h6("'brainGen_v1' is a deep learning model for brain image generation with 7.7 million parameters. ")
# }
# else if(input$modelSelect == "brainGenSeg_v1"){
# h6("brainGenSeg_v1 is a deep learning model for brain image generation with 7.7 million parameters.
# It is capable of generating sythentic 2D brain mri images along with segmatation mask of tumours.")
#
# },
footer = modalButton("Close")
)
) )
})
observeEvent(input$show_modal_p2, {
shiny::showModal(
shiny::modalDialog(title = "SOCR 2D Synthetic Brain Image Generator Help",
size = "l", easyClose = TRUE,
h5(paste0("See the About tab for additional information ",
"About GAN GAIM model, app organization and use, and other ",
"supporting information.")),
h5("The SOCR 2D Synthetic Image Generator is free and requires no external ",
"pay-to-play API keys.",
h6(
paste(input$modelSelect_p2," is a conditional deep learning model for brain image generation with 7.7 million parameters.")
),
# if(input$modelSelect == "brainGen_v1"){
# h6("'brainGen_v1' is a conditional deep learning model for brain image generation with 7.7 million parameters. ")
# }
# else if(input$modelSelect == "brainGenSeg_v1"){
# h6("brainGenSeg_v1 is a conditional deep learning model for brain image generation with 7.7 million parameters.
# It is capable of generating sythentic 2D brain mri images along with segmatation mask of tumours.")
#
# },
footer = modalButton("Close")
)
) )
})
}