Spaces:
Sleeping
Sleeping
Formated code
Browse files- demo/src/gui.py +23 -7
- demo/src/logger.py +3 -3
demo/src/gui.py
CHANGED
@@ -3,12 +3,13 @@ import os
|
|
3 |
import gradio as gr
|
4 |
|
5 |
from .inference import run_model
|
6 |
-
from .logger import
|
|
|
|
|
7 |
from .utils import load_ct_to_numpy
|
8 |
from .utils import load_pred_volume_to_numpy
|
9 |
from .utils import nifti_to_glb
|
10 |
|
11 |
-
|
12 |
# setup logging
|
13 |
LOGGER = setup_logger()
|
14 |
|
@@ -100,7 +101,7 @@ class WebUI:
|
|
100 |
width=512,
|
101 |
)
|
102 |
return out
|
103 |
-
|
104 |
def toggle_sidebar(self, state):
|
105 |
state = not state
|
106 |
return gr.update(visible=state), state
|
@@ -122,13 +123,24 @@ class WebUI:
|
|
122 |
with gr.Row():
|
123 |
with gr.Column(visible=True, scale=0.2) as sidebar_left:
|
124 |
# gr.Markdown("SideBar Left")
|
125 |
-
logs = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
demo.load(read_logs, None, logs, every=1)
|
127 |
|
128 |
with gr.Column():
|
129 |
with gr.Row():
|
130 |
-
file_output = gr.File(
|
131 |
-
|
|
|
|
|
|
|
|
|
132 |
|
133 |
model_selector = gr.Dropdown(
|
134 |
list(self.class_names.keys()),
|
@@ -156,7 +168,11 @@ class WebUI:
|
|
156 |
sidebar_state = gr.State(True)
|
157 |
|
158 |
btn_toggle_sidebar = gr.Button("Toggle Sidebar")
|
159 |
-
btn_toggle_sidebar.click(
|
|
|
|
|
|
|
|
|
160 |
|
161 |
btn_clear_logs = gr.Button("Clear logs")
|
162 |
btn_clear_logs.click(flush_logs, [], [])
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
from .inference import run_model
|
6 |
+
from .logger import flush_logs
|
7 |
+
from .logger import read_logs
|
8 |
+
from .logger import setup_logger
|
9 |
from .utils import load_ct_to_numpy
|
10 |
from .utils import load_pred_volume_to_numpy
|
11 |
from .utils import nifti_to_glb
|
12 |
|
|
|
13 |
# setup logging
|
14 |
LOGGER = setup_logger()
|
15 |
|
|
|
101 |
width=512,
|
102 |
)
|
103 |
return out
|
104 |
+
|
105 |
def toggle_sidebar(self, state):
|
106 |
state = not state
|
107 |
return gr.update(visible=state), state
|
|
|
123 |
with gr.Row():
|
124 |
with gr.Column(visible=True, scale=0.2) as sidebar_left:
|
125 |
# gr.Markdown("SideBar Left")
|
126 |
+
logs = gr.Textbox(
|
127 |
+
label="Logs",
|
128 |
+
info="Verbose from inference will be displayed below.",
|
129 |
+
max_lines=16,
|
130 |
+
autoscroll=True,
|
131 |
+
elem_id="logs",
|
132 |
+
show_copy_button=True,
|
133 |
+
)
|
134 |
demo.load(read_logs, None, logs, every=1)
|
135 |
|
136 |
with gr.Column():
|
137 |
with gr.Row():
|
138 |
+
file_output = gr.File(
|
139 |
+
file_count="single", elem_id="upload"
|
140 |
+
)
|
141 |
+
file_output.upload(
|
142 |
+
self.upload_file, file_output, file_output
|
143 |
+
)
|
144 |
|
145 |
model_selector = gr.Dropdown(
|
146 |
list(self.class_names.keys()),
|
|
|
168 |
sidebar_state = gr.State(True)
|
169 |
|
170 |
btn_toggle_sidebar = gr.Button("Toggle Sidebar")
|
171 |
+
btn_toggle_sidebar.click(
|
172 |
+
self.toggle_sidebar,
|
173 |
+
[sidebar_state],
|
174 |
+
[sidebar_left, sidebar_state],
|
175 |
+
)
|
176 |
|
177 |
btn_clear_logs = gr.Button("Clear logs")
|
178 |
btn_clear_logs.click(flush_logs, [], [])
|
demo/src/logger.py
CHANGED
@@ -10,14 +10,14 @@ def setup_logger():
|
|
10 |
# clear log
|
11 |
file_to_delete = open("log.txt", "w")
|
12 |
file_to_delete.close()
|
13 |
-
|
14 |
file_handler = logging.FileHandler(filename="log.txt")
|
15 |
stdout_handler = logging.StreamHandler(stream=sys.stdout)
|
16 |
handlers = [file_handler, stdout_handler]
|
17 |
|
18 |
logging.basicConfig(
|
19 |
-
level=logging.INFO,
|
20 |
-
format=
|
21 |
handlers=handlers,
|
22 |
)
|
23 |
|
|
|
10 |
# clear log
|
11 |
file_to_delete = open("log.txt", "w")
|
12 |
file_to_delete.close()
|
13 |
+
|
14 |
file_handler = logging.FileHandler(filename="log.txt")
|
15 |
stdout_handler = logging.StreamHandler(stream=sys.stdout)
|
16 |
handlers = [file_handler, stdout_handler]
|
17 |
|
18 |
logging.basicConfig(
|
19 |
+
level=logging.INFO,
|
20 |
+
format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s",
|
21 |
handlers=handlers,
|
22 |
)
|
23 |
|