Refactored according to linting style
Browse files- app.py +21 -6
- neukit/gui.py +11 -3
app.py
CHANGED
@@ -1,20 +1,35 @@
|
|
1 |
-
from neukit.gui import WebUI
|
2 |
-
from argparse import ArgumentParser
|
3 |
import os
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
def main():
|
7 |
parser = ArgumentParser()
|
8 |
-
parser.add_argument(
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
args = parser.parse_args()
|
11 |
|
12 |
print("Current working directory:", args.cwd)
|
13 |
|
14 |
if not os.path.exists(args.cwd):
|
15 |
raise ValueError("Chosen 'cwd' is not a valid path!")
|
16 |
-
if
|
17 |
-
raise ValueError(
|
|
|
|
|
|
|
18 |
|
19 |
# initialize and run app
|
20 |
print("Launching demo...")
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
from argparse import ArgumentParser
|
3 |
+
|
4 |
+
from neukit.gui import WebUI
|
5 |
|
6 |
|
7 |
def main():
|
8 |
parser = ArgumentParser()
|
9 |
+
parser.add_argument(
|
10 |
+
"--cwd",
|
11 |
+
type=str,
|
12 |
+
default="/home/user/app/",
|
13 |
+
help="Set current working directory (path to app.py).",
|
14 |
+
)
|
15 |
+
parser.add_argument(
|
16 |
+
"--share",
|
17 |
+
type=int,
|
18 |
+
default=1,
|
19 |
+
help="Whether to enable the app to be accessible online"
|
20 |
+
"-> setups a public link which requires internet access.",
|
21 |
+
)
|
22 |
args = parser.parse_args()
|
23 |
|
24 |
print("Current working directory:", args.cwd)
|
25 |
|
26 |
if not os.path.exists(args.cwd):
|
27 |
raise ValueError("Chosen 'cwd' is not a valid path!")
|
28 |
+
if args.share not in [0, 1]:
|
29 |
+
raise ValueError(
|
30 |
+
"The 'share' argument can only be set to 0 or 1, but was:",
|
31 |
+
args.share,
|
32 |
+
)
|
33 |
|
34 |
# initialize and run app
|
35 |
print("Launching demo...")
|
neukit/gui.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
-
import gradio as gr
|
2 |
import os
|
3 |
|
|
|
|
|
4 |
from .inference import run_model
|
5 |
from .utils import load_ct_to_numpy
|
6 |
from .utils import load_pred_volume_to_numpy
|
@@ -8,7 +9,12 @@ from .utils import nifti_to_glb
|
|
8 |
|
9 |
|
10 |
class WebUI:
|
11 |
-
def __init__(
|
|
|
|
|
|
|
|
|
|
|
12 |
# global states
|
13 |
self.images = []
|
14 |
self.pred_images = []
|
@@ -166,4 +172,6 @@ class WebUI:
|
|
166 |
# https://gradio.app/sharing-your-app/
|
167 |
# inference times > 60 seconds -> need queue():
|
168 |
# https://github.com/tloen/alpaca-lora/issues/60#issuecomment-1510006062
|
169 |
-
demo.queue().launch(
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
from .inference import run_model
|
6 |
from .utils import load_ct_to_numpy
|
7 |
from .utils import load_pred_volume_to_numpy
|
|
|
9 |
|
10 |
|
11 |
class WebUI:
|
12 |
+
def __init__(
|
13 |
+
self,
|
14 |
+
model_name: str = None,
|
15 |
+
cwd: str = "/home/user/app/",
|
16 |
+
share: int = 1,
|
17 |
+
):
|
18 |
# global states
|
19 |
self.images = []
|
20 |
self.pred_images = []
|
|
|
172 |
# https://gradio.app/sharing-your-app/
|
173 |
# inference times > 60 seconds -> need queue():
|
174 |
# https://github.com/tloen/alpaca-lora/issues/60#issuecomment-1510006062
|
175 |
+
demo.queue().launch(
|
176 |
+
server_name="0.0.0.0", server_port=7860, share=self.share
|
177 |
+
)
|