Spaces:
Running
Running
Ashwin V. Mohanan
commited on
Commit
·
1846d66
1
Parent(s):
8e5df59
Support overwritting table formats file
Browse files- app/tabs/submit.py +19 -4
app/tabs/submit.py
CHANGED
@@ -171,7 +171,16 @@ def get_selected_example_image(
|
|
171 |
first, last, book = io.read_book(book_path)
|
172 |
book._name = name
|
173 |
book.size_cell = [1.0, 1.0, 1.0, 1.0]
|
174 |
-
return [book.read_image(pg) for pg in range(first_page, last_page)], book, station_tf.read_text()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
|
177 |
with gr.Blocks() as submit:
|
@@ -181,6 +190,7 @@ with gr.Blocks() as submit:
|
|
181 |
)
|
182 |
|
183 |
batch_book_state = gr.State()
|
|
|
184 |
collection_submit_state = gr.State()
|
185 |
|
186 |
with gr.Group():
|
@@ -211,9 +221,9 @@ with gr.Blocks() as submit:
|
|
211 |
gr.Markdown(
|
212 |
"## Table format configuration\n"
|
213 |
"Write a custom table format, overriding the default one. "
|
214 |
-
"
|
215 |
)
|
216 |
-
|
217 |
gr.HTML(
|
218 |
(
|
219 |
"<a href='https://dawsonia.readthedocs.io/en/latest/user_guide/misc.html#table-formats' target='_blank'>"
|
@@ -223,6 +233,7 @@ with gr.Blocks() as submit:
|
|
223 |
padding=False,
|
224 |
elem_classes="pipeline-help",
|
225 |
)
|
|
|
226 |
|
227 |
with gr.Row():
|
228 |
run_button = gr.Button("Digitize", variant="primary", scale=0, min_width=200)
|
@@ -235,7 +246,7 @@ with gr.Blocks() as submit:
|
|
235 |
examples.select(
|
236 |
get_selected_example_image,
|
237 |
(first_page, last_page),
|
238 |
-
(batch_image_gallery, batch_book_state, table_fmt_config_override),
|
239 |
trigger_mode="always_last",
|
240 |
)
|
241 |
|
@@ -257,4 +268,8 @@ with gr.Blocks() as submit:
|
|
257 |
inputs=(table_fmt_config_override, first_page, last_page, batch_book_state, batch_image_gallery),
|
258 |
outputs=(collection_submit_state, batch_image_gallery),
|
259 |
)
|
|
|
|
|
260 |
edit_table_fmt_button.click(lambda: Modal(visible=True), None, edit_table_fmt_modal)
|
|
|
|
|
|
171 |
first, last, book = io.read_book(book_path)
|
172 |
book._name = name
|
173 |
book.size_cell = [1.0, 1.0, 1.0, 1.0]
|
174 |
+
return [book.read_image(pg) for pg in range(first_page, last_page)], book, book_path, station_tf.read_text()
|
175 |
+
|
176 |
+
|
177 |
+
def overwrite_table_format_file(book: io.Book, book_path, table_fmt: str):
|
178 |
+
name = book.station_name
|
179 |
+
table_fmt_dir = Path("table_formats")
|
180 |
+
(table_fmt_dir / name).with_suffix(".toml").write_text(table_fmt)
|
181 |
+
book.table_format = io.read_specific_table_format(table_fmt_dir, Path(book_path))
|
182 |
+
gr.Info(f"Overwritten table format file for {name}")
|
183 |
+
return book
|
184 |
|
185 |
|
186 |
with gr.Blocks() as submit:
|
|
|
190 |
)
|
191 |
|
192 |
batch_book_state = gr.State()
|
193 |
+
batch_book_path_state = gr.State()
|
194 |
collection_submit_state = gr.State()
|
195 |
|
196 |
with gr.Group():
|
|
|
221 |
gr.Markdown(
|
222 |
"## Table format configuration\n"
|
223 |
"Write a custom table format, overriding the default one. "
|
224 |
+
"Click on the **Save** button when you are done."
|
225 |
)
|
226 |
+
save_tf_button = gr.Button("Save", variant="primary", scale=0, min_width=200)
|
227 |
gr.HTML(
|
228 |
(
|
229 |
"<a href='https://dawsonia.readthedocs.io/en/latest/user_guide/misc.html#table-formats' target='_blank'>"
|
|
|
233 |
padding=False,
|
234 |
elem_classes="pipeline-help",
|
235 |
)
|
236 |
+
table_fmt_config_override = gr.Code("", language="python")
|
237 |
|
238 |
with gr.Row():
|
239 |
run_button = gr.Button("Digitize", variant="primary", scale=0, min_width=200)
|
|
|
246 |
examples.select(
|
247 |
get_selected_example_image,
|
248 |
(first_page, last_page),
|
249 |
+
(batch_image_gallery, batch_book_state, batch_book_path_state, table_fmt_config_override),
|
250 |
trigger_mode="always_last",
|
251 |
)
|
252 |
|
|
|
268 |
inputs=(table_fmt_config_override, first_page, last_page, batch_book_state, batch_image_gallery),
|
269 |
outputs=(collection_submit_state, batch_image_gallery),
|
270 |
)
|
271 |
+
|
272 |
+
## Table formats modal dialog box
|
273 |
edit_table_fmt_button.click(lambda: Modal(visible=True), None, edit_table_fmt_modal)
|
274 |
+
save_tf_button.click(
|
275 |
+
overwrite_table_format_file, (batch_book_state, batch_book_path_state, table_fmt_config_override), (batch_book_state,))
|