Ashwin V. Mohanan commited on
Commit
8e5df59
·
1 Parent(s): ddd87aa

Change output dir and sync table formats

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. app/main.py +1 -1
  3. app/tabs/submit.py +13 -7
  4. output/.gitkeep +0 -0
.gitignore CHANGED
@@ -9,3 +9,5 @@ wheels/
9
  # Virtual environments
10
  .venv
11
  dawsonia.log
 
 
 
9
  # Virtual environments
10
  .venv
11
  dawsonia.log
12
+ output/*/
13
+ .gradio_cache
app/main.py CHANGED
@@ -94,5 +94,5 @@ if __name__ == "__main__":
94
  server_port=7860,
95
  enable_monitoring=True,
96
  show_api=False,
97
- allowed_paths=[".gradio_cache/output"],
98
  )
 
94
  server_port=7860,
95
  enable_monitoring=True,
96
  show_api=False,
97
+ allowed_paths=["output"],
98
  )
app/tabs/submit.py CHANGED
@@ -53,7 +53,7 @@ def run_dawsonia(
53
  progress(0, desc="Dawsonia: starting")
54
 
55
  model_path = Path("data/models/dawsonia/2024-07-02")
56
- output_path = Path(GRADIO_CACHE, "output")
57
 
58
  print("Dawsonia: digitizing", book)
59
  table_fmt = book.table_format
@@ -94,9 +94,12 @@ def run_dawsonia(
94
  )
95
  progress_value = (page_number - first_page) / max(1, last_page - first_page)
96
 
97
- page, im = read_page(output_path_book, str(page_number), progress, progress_value) # , im_from_gallery[0])
98
- collection.append(page)
99
- images.append(im)
 
 
 
100
 
101
 
102
  gr.Info("Pages were succesfully digitized ✨")
@@ -127,6 +130,7 @@ def read_page(output_path_book: Path, prefix: str, progress, progress_value, im_
127
  cells = [
128
  make_cell(value, bbox) for value, bbox in zip(values_array, bbox_array)
129
  ]
 
130
  return Page(width, height, cells, im_path_from_gallery or str(image_path)), im
131
 
132
 
@@ -150,13 +154,15 @@ def all_example_images() -> list[str]:
150
 
151
  def get_selected_example_image(
152
  first_page, last_page, event: gr.SelectData
153
- ) -> tuple[str, io.Book] | None:
154
  """
155
  Get the name of the pipeline that corresponds to the selected image.
156
  """
157
  # for name, details in PIPELINES.items():
158
  name, _ext = event.value["image"]["orig_name"].split(".")
159
 
 
 
160
  if (last_page - first_page) > MAX_IMAGES:
161
  raise ValueError(f"Maximum images you can digitize is set to: {MAX_IMAGES}")
162
 
@@ -165,7 +171,7 @@ def get_selected_example_image(
165
  first, last, book = io.read_book(book_path)
166
  book._name = name
167
  book.size_cell = [1.0, 1.0, 1.0, 1.0]
168
- return [book.read_image(pg) for pg in range(first_page, last_page)], book
169
 
170
 
171
  with gr.Blocks() as submit:
@@ -229,7 +235,7 @@ with gr.Blocks() as submit:
229
  examples.select(
230
  get_selected_example_image,
231
  (first_page, last_page),
232
- (batch_image_gallery, batch_book_state),
233
  trigger_mode="always_last",
234
  )
235
 
 
53
  progress(0, desc="Dawsonia: starting")
54
 
55
  model_path = Path("data/models/dawsonia/2024-07-02")
56
+ output_path = Path("output")
57
 
58
  print("Dawsonia: digitizing", book)
59
  table_fmt = book.table_format
 
94
  )
95
  progress_value = (page_number - first_page) / max(1, last_page - first_page)
96
 
97
+ if results := read_page(output_path_book, str(page_number), progress, progress_value): # , im_from_gallery[0])
98
+ page, im = results
99
+ collection.append(page)
100
+ images.append(im)
101
+ else:
102
+ gr.Info(f"No tables detected in {page_number = }")
103
 
104
 
105
  gr.Info("Pages were succesfully digitized ✨")
 
130
  cells = [
131
  make_cell(value, bbox) for value, bbox in zip(values_array, bbox_array)
132
  ]
133
+
134
  return Page(width, height, cells, im_path_from_gallery or str(image_path)), im
135
 
136
 
 
154
 
155
  def get_selected_example_image(
156
  first_page, last_page, event: gr.SelectData
157
+ ) -> tuple[str, io.Book, str] | None:
158
  """
159
  Get the name of the pipeline that corresponds to the selected image.
160
  """
161
  # for name, details in PIPELINES.items():
162
  name, _ext = event.value["image"]["orig_name"].split(".")
163
 
164
+ station_tf = Path("table_formats", name).with_suffix(".toml")
165
+
166
  if (last_page - first_page) > MAX_IMAGES:
167
  raise ValueError(f"Maximum images you can digitize is set to: {MAX_IMAGES}")
168
 
 
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:
 
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
 
output/.gitkeep ADDED
File without changes