Gabriel commited on
Commit
c9a1c2d
1 Parent(s): 4c85050

test docker

Browse files
Dockerfile CHANGED
@@ -33,4 +33,4 @@ WORKDIR $HOME/app
33
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
34
  COPY --chown=user . $HOME/app
35
 
36
- CMD ["python", "app.py"]
 
33
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
34
  COPY --chown=user . $HOME/app
35
 
36
+ CMD ["python", "app/app.py"]
app.py → app/app.py RENAMED
@@ -6,10 +6,11 @@ import gradio as gr
6
  from helper.examples.examples import DemoImages
7
  from helper.gradio_config import css, js, theme
8
  from helper.text import TextAbout, TextApp, TextHowTo, TextRiksarkivet, TextRoadmap
9
- from src.htr_pipeline.gradio_backend import CustomTrack, FastTrack, SingletonModelLoader
 
 
10
 
11
  model_loader = SingletonModelLoader()
12
- fast_track = FastTrack(model_loader)
13
  custom_track = CustomTrack(model_loader)
14
  images_for_demo = DemoImages()
15
 
@@ -18,67 +19,7 @@ with gr.Blocks(title="HTR Riksarkivet", theme=theme, css=css) as demo:
18
 
19
  with gr.Tabs():
20
  with gr.Tab("HTR Tool"):
21
- with gr.Row(equal_height=True):
22
- with gr.Column(scale=2):
23
- with gr.Row():
24
- fast_track_input_region_image = gr.Image(
25
- label="Image to run HTR on", type="numpy", tool="editor", elem_id="image_upload", height=395
26
- )
27
-
28
- with gr.Row():
29
- # with gr.Group():
30
- # callback = gr.CSVLogger()
31
- # # hf_writer = gr.HuggingFaceDatasetSaver(HF_API_TOKEN, "htr_pipelin_flags")
32
- # flagging_button = gr.Button(
33
- # "Flag",
34
- # variant="secondary",
35
- # visible=True,
36
- # ).style(full_width=True)
37
- # radio_file_input = gr.Radio(
38
- # value="Text file", choices=["Text file ", "Page XML file "], label="What kind file output?"
39
- # )
40
-
41
- radio_file_input = gr.CheckboxGroup(
42
- choices=["Txt", "XML"],
43
- value=["Txt"],
44
- label="Output file extension",
45
- # info="Only txt and page xml is supported for now!",
46
- )
47
-
48
- htr_pipeline_button = gr.Button(
49
- "Run HTR",
50
- variant="primary",
51
- visible=True,
52
- elem_id="run_pipeline_button",
53
- ).style(full_width=False)
54
-
55
- with gr.Group():
56
- with gr.Row():
57
- fast_file_downlod = gr.File(label="Download output file", visible=False)
58
- with gr.Row():
59
- with gr.Accordion("Example images to use:", open=False) as fast_example_accord:
60
- fast_name_files_placeholder = gr.Markdown(visible=False)
61
-
62
- gr.Examples(
63
- examples=images_for_demo.examples_list,
64
- inputs=[fast_name_files_placeholder, fast_track_input_region_image],
65
- label="Example images",
66
- examples_per_page=3,
67
- )
68
-
69
- with gr.Column(scale=4):
70
- fast_track_output_image = gr.Image(
71
- label="HTR results visualizer", type="numpy", tool="editor", height=650
72
- )
73
-
74
- with gr.Row(visible=False) as api_placeholder:
75
- htr_pipeline_button_api = gr.Button(
76
- "Run pipeline",
77
- variant="primary",
78
- visible=False,
79
- ).style(full_width=False)
80
-
81
- xml_rendered_placeholder_for_api = gr.Textbox(visible=False)
82
 
83
  with gr.Tab("Stepwise HTR Tool"):
84
  with gr.Tabs():
@@ -394,29 +335,6 @@ with gr.Blocks(title="HTR Riksarkivet", theme=theme, css=css) as demo:
394
  with gr.Row():
395
  gr.Markdown(TextRiksarkivet.riksarkivet)
396
 
397
- htr_pipeline_button.click(
398
- fast_track.segment_to_xml,
399
- inputs=[fast_track_input_region_image, radio_file_input],
400
- outputs=[fast_track_output_image, fast_file_downlod, fast_file_downlod],
401
- )
402
-
403
- htr_pipeline_button_api.click(
404
- fast_track.segment_to_xml_api,
405
- inputs=[fast_track_input_region_image],
406
- outputs=[xml_rendered_placeholder_for_api],
407
- api_name="predict",
408
- )
409
-
410
- # fast_track_input_region_image.change(
411
- # fn=lambda: (gr.Accordion.update(open=False)),
412
- # outputs=[fast_example_accord],
413
- # )
414
-
415
- # input_region_image.change(
416
- # fn=lambda: (gr.Accordion.update(open=False)),
417
- # outputs=[example_accord],
418
- # )
419
-
420
  # callback.setup([fast_track_input_region_image], "flagged_data_points")
421
  # flagging_button.click(lambda *args: callback.flag(args), [fast_track_input_region_image], None, preprocess=False)
422
  # flagging_button.click(lambda: (gr.update(value="Flagged")), outputs=flagging_button)
 
6
  from helper.examples.examples import DemoImages
7
  from helper.gradio_config import css, js, theme
8
  from helper.text import TextAbout, TextApp, TextHowTo, TextRiksarkivet, TextRoadmap
9
+ from src.htr_pipeline.gradio_backend import CustomTrack, SingletonModelLoader
10
+
11
+ from .htr_tool import htr_tool_tab
12
 
13
  model_loader = SingletonModelLoader()
 
14
  custom_track = CustomTrack(model_loader)
15
  images_for_demo = DemoImages()
16
 
 
19
 
20
  with gr.Tabs():
21
  with gr.Tab("HTR Tool"):
22
+ htr_tool_tab.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  with gr.Tab("Stepwise HTR Tool"):
25
  with gr.Tabs():
 
335
  with gr.Row():
336
  gr.Markdown(TextRiksarkivet.riksarkivet)
337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  # callback.setup([fast_track_input_region_image], "flagged_data_points")
339
  # flagging_button.click(lambda *args: callback.flag(args), [fast_track_input_region_image], None, preprocess=False)
340
  # flagging_button.click(lambda: (gr.update(value="Flagged")), outputs=flagging_button)
app/htr_tool.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from helper.examples.examples import DemoImages
4
+ from src.htr_pipeline.gradio_backend import FastTrack, SingletonModelLoader
5
+
6
+ model_loader = SingletonModelLoader()
7
+
8
+ fast_track = FastTrack(model_loader)
9
+
10
+ images_for_demo = DemoImages()
11
+
12
+
13
+ with gr.Blocks() as htr_tool_tab:
14
+ with gr.Row(equal_height=True):
15
+ with gr.Column(scale=2):
16
+ with gr.Row():
17
+ fast_track_input_region_image = gr.Image(
18
+ label="Image to run HTR on", type="numpy", tool="editor", elem_id="image_upload", height=395
19
+ )
20
+
21
+ with gr.Row():
22
+ # with gr.Group():
23
+ # callback = gr.CSVLogger()
24
+ # # hf_writer = gr.HuggingFaceDatasetSaver(HF_API_TOKEN, "htr_pipelin_flags")
25
+ # flagging_button = gr.Button(
26
+ # "Flag",
27
+ # variant="secondary",
28
+ # visible=True,
29
+ # ).style(full_width=True)
30
+ # radio_file_input = gr.Radio(
31
+ # value="Text file", choices=["Text file ", "Page XML file "], label="What kind file output?"
32
+ # )
33
+
34
+ radio_file_input = gr.CheckboxGroup(
35
+ choices=["Txt", "XML"],
36
+ value=["Txt"],
37
+ label="Output file extension",
38
+ # info="Only txt and page xml is supported for now!",
39
+ )
40
+
41
+ htr_pipeline_button = gr.Button(
42
+ "Run HTR",
43
+ variant="primary",
44
+ visible=True,
45
+ elem_id="run_pipeline_button",
46
+ ).style(full_width=False)
47
+
48
+ with gr.Group():
49
+ with gr.Row():
50
+ fast_file_downlod = gr.File(label="Download output file", visible=False)
51
+ with gr.Row():
52
+ with gr.Accordion("Example images to use:", open=False) as fast_example_accord:
53
+ fast_name_files_placeholder = gr.Markdown(visible=False)
54
+
55
+ gr.Examples(
56
+ examples=images_for_demo.examples_list,
57
+ inputs=[fast_name_files_placeholder, fast_track_input_region_image],
58
+ label="Example images",
59
+ examples_per_page=3,
60
+ )
61
+
62
+ with gr.Column(scale=4):
63
+ fast_track_output_image = gr.Image(label="HTR results visualizer", type="numpy", tool="editor", height=650)
64
+
65
+ with gr.Row(visible=False) as api_placeholder:
66
+ htr_pipeline_button_api = gr.Button(
67
+ "Run pipeline",
68
+ variant="primary",
69
+ visible=False,
70
+ ).style(full_width=False)
71
+
72
+ xml_rendered_placeholder_for_api = gr.Textbox(visible=False)
73
+ htr_pipeline_button.click(
74
+ fast_track.segment_to_xml,
75
+ inputs=[fast_track_input_region_image, radio_file_input],
76
+ outputs=[fast_track_output_image, fast_file_downlod, fast_file_downlod],
77
+ )
78
+
79
+ htr_pipeline_button_api.click(
80
+ fast_track.segment_to_xml_api,
81
+ inputs=[fast_track_input_region_image],
82
+ outputs=[xml_rendered_placeholder_for_api],
83
+ api_name="predict",
84
+ )
src/htr_pipeline/inferencer.py CHANGED
@@ -92,7 +92,10 @@ class Inferencer:
92
 
93
  if visualize:
94
  result_viz = self.seg_model.visualize(
95
- inputs=[image], preds=[result_tl_clean], return_vis=True, no_save_vis=True
 
 
 
96
  )[0]
97
  else:
98
  result_viz = None
 
92
 
93
  if visualize:
94
  result_viz = self.seg_model.visualize(
95
+ inputs=[image],
96
+ preds=[result_tl_clean],
97
+ return_vis=True,
98
+ no_save_vis=True,
99
  )[0]
100
  else:
101
  result_viz = None