Gabriel commited on
Commit
ba34352
·
1 Parent(s): 15a60a2

minor fixes

Browse files
app/main.py CHANGED
@@ -15,17 +15,15 @@ logger = logging.getLogger("gradio_log")
15
 
16
 
17
  TAB_LABELS = {
18
- "ENG": ["Home", "Simple HTR", "Custom HTR", "Examples"],
19
- "SWE": ["Hem", "Enkel HTR", "Anpassad HTR", "Exempel"],
20
  }
21
 
22
  LANG_CHOICES = ["ENG", "SWE"]
23
 
24
  with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
25
  with gr.Row():
26
- local_language = gr.BrowserState(
27
- default_value="ENG", storage_key="selected_language"
28
- )
29
  main_language = gr.State(value="ENG")
30
 
31
  with gr.Column(scale=1):
@@ -47,17 +45,17 @@ with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
47
  with gr.Tab(label="Home") as tab_home:
48
  overview.render()
49
 
50
- with gr.Tab(label="Simple HTR") as tab_simple_htr:
51
  htrflow_pipeline.render()
52
 
53
- with gr.Tab(label="Custom HTR") as tab_custom_htr:
54
  adv_htrflow_pipeline.render()
55
 
56
  with gr.Tab(label="Examples") as tab_examples:
57
  examples.render()
58
 
59
- with gr.Tab(label="Data Explorer") as tab_data_explorer:
60
- data_explorer.render()
61
 
62
  @demo.load(
63
  inputs=[local_language],
 
15
 
16
 
17
  TAB_LABELS = {
18
+ "ENG": ["Home", "Simple", "Advanced", "Examples"],
19
+ "SWE": ["Hem", "Enkel", "Avancerad", "Exempel"],
20
  }
21
 
22
  LANG_CHOICES = ["ENG", "SWE"]
23
 
24
  with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
25
  with gr.Row():
26
+ local_language = gr.BrowserState(default_value="ENG", storage_key="selected_language")
 
 
27
  main_language = gr.State(value="ENG")
28
 
29
  with gr.Column(scale=1):
 
45
  with gr.Tab(label="Home") as tab_home:
46
  overview.render()
47
 
48
+ with gr.Tab(label="Simple") as tab_simple_htr:
49
  htrflow_pipeline.render()
50
 
51
+ with gr.Tab(label="Advanced") as tab_custom_htr:
52
  adv_htrflow_pipeline.render()
53
 
54
  with gr.Tab(label="Examples") as tab_examples:
55
  examples.render()
56
 
57
+ # with gr.Tab(label="Data Explorer") as tab_data_explorer:
58
+ # data_explorer.render()
59
 
60
  @demo.load(
61
  inputs=[local_language],
app/tabs/adv_htrflow_tab.py CHANGED
@@ -4,14 +4,19 @@ import gradio as gr
4
 
5
  with gr.Blocks() as adv_htrflow_pipeline:
6
  with gr.Row(variant="panel"):
7
- with gr.Column():
8
- # TODO: We want to either crop or draw polygon or bbox and send it to the custom model. Or just as the image is.
9
- # TODO: For the viewer we should be able to select from the output of the model what for values we want to
10
- # TODO: add batch predictions here..
11
- # TODO: add load from s3, local, hf daasets( however everything could go through hf_datasets).
12
- # TODO: send a crop from the user
13
 
14
- image_mask = gr.ImageMask(interactive=True)
 
 
 
 
 
 
 
15
 
16
  with gr.Group():
17
  with gr.Row(visible=True) as yaml_pipeline:
@@ -22,21 +27,21 @@ with gr.Blocks() as adv_htrflow_pipeline:
22
  label="yaml",
23
  interactive=True,
24
  )
25
- test = gr.Dropdown( # TODO: This should be a dropdown to decide input image or mask or s3 or local path
26
- ["Upload", "Draw", "s3", "local", "crop"],
27
- value="Upload",
28
- multiselect=False,
29
- label="Upload method",
30
- container=False,
31
- scale=0,
32
- interactive=True,
33
- )
 
 
34
 
35
  with gr.Row():
36
  run_button = gr.Button("Submit", variant="primary", scale=0)
37
- cancel_button = gr.Button(
38
- "stop", variant="stop", scale=0
39
- ) # TODO: This should be a cancel button and be hidden until the run button is clicked
40
  d = gr.DownloadButton(
41
  "Download the file", visible=True, scale=0
42
  ) # TODO: This should be hidden until the run button is clicked
@@ -48,7 +53,7 @@ with gr.Blocks() as adv_htrflow_pipeline:
48
  # TODO: add a upload to hf datasets
49
  # TODO: add a hf login button to login to upload datasets
50
 
51
- with gr.Column():
52
  with gr.Tabs():
53
  with gr.Tab("HTR ouput"):
54
  gr.CheckboxGroup(
@@ -64,7 +69,7 @@ with gr.Blocks() as adv_htrflow_pipeline:
64
  # TODO add https://www.gradio.app/docs/gradio/highlightedtext and graph of run graph
65
  pass
66
 
67
- test.select(lambda: gr.update(visible=True), None, image_mask)
68
 
69
  def foo():
70
  for i in range(300):
 
4
 
5
  with gr.Blocks() as adv_htrflow_pipeline:
6
  with gr.Row(variant="panel"):
7
+ with gr.Column(scale=2):
8
+ image_mask2 = gr.ImageEditor(
9
+ label="Uploaded image", interactive=True, layers=False, eraser=False, brush=False, height=400
10
+ )
 
 
11
 
12
+ image_mask = gr.Gallery(
13
+ file_types=["image"],
14
+ label="Upload images",
15
+ interactive=True,
16
+ height=400,
17
+ object_fit="cover",
18
+ columns=5,
19
+ )
20
 
21
  with gr.Group():
22
  with gr.Row(visible=True) as yaml_pipeline:
 
27
  label="yaml",
28
  interactive=True,
29
  )
30
+ gr.Checkbox(value=True, label="Batch", container=True, scale=0)
31
+
32
+ # input_files_format_dropdown = gr.Dropdown(
33
+ # ["Upload", "Batch", "Crop"],
34
+ # value="Upload",
35
+ # multiselect=False,
36
+ # label="Upload method",
37
+ # container=False,
38
+ # scale=0,
39
+ # interactive=True,
40
+ # )
41
 
42
  with gr.Row():
43
  run_button = gr.Button("Submit", variant="primary", scale=0)
44
+ cancel_button = gr.Button("stop", variant="stop", scale=0)
 
 
45
  d = gr.DownloadButton(
46
  "Download the file", visible=True, scale=0
47
  ) # TODO: This should be hidden until the run button is clicked
 
53
  # TODO: add a upload to hf datasets
54
  # TODO: add a hf login button to login to upload datasets
55
 
56
+ with gr.Column(scale=3):
57
  with gr.Tabs():
58
  with gr.Tab("HTR ouput"):
59
  gr.CheckboxGroup(
 
69
  # TODO add https://www.gradio.app/docs/gradio/highlightedtext and graph of run graph
70
  pass
71
 
72
+ # input_files_format_dropdown.select(lambda: gr.update(visible=True), None, image_mask)
73
 
74
  def foo():
75
  for i in range(300):
app/tabs/data_explorer_tab copy.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_modal import Modal
3
+
4
+ output_image_placehholder = gr.Image(label="Output image", height=400, show_share_button=True)
5
+
6
+
7
+ def show_warning(selection: gr.SelectData):
8
+ gr.Warning(f"Your choice is #{selection.index}, with image: {selection.value['image']['path']}!")
9
+
10
+
11
+ with gr.Blocks() as data_explorer:
12
+ with gr.Row(variant="panel"):
13
+ with gr.Column(scale=1):
14
+ output_dataframe_pipeline = gr.Textbox(label="Path", info="path s3 or path, hf-dataset.")
15
+ with gr.Group():
16
+ (
17
+ gr.Dropdown(
18
+ ["ran", "swam", "ate", "slept"],
19
+ value=["swam", "slept"],
20
+ multiselect=True,
21
+ label="Activity",
22
+ info="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ",
23
+ ),
24
+ )
25
+ gr.Slider(2, 20, value=4, label="Count", info="Choose between 2 and 20")
26
+ gr.Slider(2, 20, value=4, label="Another", info="Choose between 2 and 20")
27
+ output_dataframe_pipeline = gr.Textbox(label="search", info="search image bla bla..")
28
+ gr.Button("Search", variant="primary", scale=0)
29
+ with gr.Column(scale=4):
30
+ with gr.Tabs():
31
+ with gr.Tab("Gallery"):
32
+ image_gallery = gr.Gallery(
33
+ [
34
+ "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
35
+ "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
36
+ "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
37
+ "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
38
+ ]
39
+ * 10,
40
+ allow_preview=False,
41
+ label="Image Gallery",
42
+ preview=False,
43
+ columns=[7],
44
+ rows=[10],
45
+ show_download_button=True,
46
+ show_share_button=True,
47
+ )
48
+ with gr.Tab("Embeddings"):
49
+ pass
50
+ # TODO: add a embedding plot here
51
+ # user needs to login hf and get a datasets with embeddings
52
+
53
+ with Modal(visible=False) as gallery_modal:
54
+ with gr.Row():
55
+ with gr.Column(scale=0):
56
+ gr.Markdown("")
57
+ with gr.Column(scale=4):
58
+ gr.Image()
59
+ with gr.Column(scale=0):
60
+ gr.Markdown("")
61
+
62
+ image_gallery.select(fn=show_warning, inputs=None).then(lambda: Modal(visible=True), None, gallery_modal)
app/tabs/data_explorer_tab.py CHANGED
@@ -1,63 +1,28 @@
1
  import gradio as gr
2
- import pandas as pd
3
- from gradio_modal import Modal
4
 
5
- output_image_placehholder = gr.Image(label="Output image", height=400, show_share_button=True)
6
 
7
-
8
- def show_warning(selection: gr.SelectData):
9
- gr.Warning(f"Your choice is #{selection.index}, with image: {selection.value['image']['path']}!")
 
 
 
 
10
 
11
 
12
  with gr.Blocks() as data_explorer:
13
  with gr.Row(variant="panel"):
14
- with gr.Column(scale=1):
15
- output_dataframe_pipeline = gr.Textbox(label="Path", info="path s3 or path, hf-dataset.")
16
- with gr.Group():
17
- (
18
- gr.Dropdown(
19
- ["ran", "swam", "ate", "slept"],
20
- value=["swam", "slept"],
21
- multiselect=True,
22
- label="Activity",
23
- info="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ",
24
- ),
25
- )
26
- gr.Slider(2, 20, value=4, label="Count", info="Choose between 2 and 20")
27
- gr.Slider(2, 20, value=4, label="Another", info="Choose between 2 and 20")
28
- output_dataframe_pipeline = gr.Textbox(label="search", info="search image bla bla..")
29
- gr.Button("Search", variant="primary", scale=0)
30
- with gr.Column(scale=4):
31
- with gr.Tabs():
32
- with gr.Tab("Gallery"):
33
- image_gallery = gr.Gallery(
34
- [
35
- "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
36
- "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
37
- "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
38
- "https://unsplash.com/photos/4oaDBgVROGo/download?ixid=M3wxMjA3fDB8MXxhbGx8NHx8fHx8fDJ8fDE3MTA0NjI1MzZ8&force=true&w=640",
39
- ]
40
- * 10,
41
- allow_preview=False,
42
- label="Image Gallery",
43
- preview=False,
44
- columns=[7],
45
- rows=[10],
46
- show_download_button=True,
47
- show_share_button=True,
48
- )
49
- with gr.Tab("Embeddings"):
50
- pass
51
- # TODO: add a embedding plot here
52
- # user needs to login hf and get a datasets with embeddings
53
-
54
- with Modal(visible=False) as gallery_modal:
55
- with gr.Row():
56
- with gr.Column(scale=0):
57
- gr.Markdown("")
58
- with gr.Column(scale=4):
59
- gr.Image()
60
- with gr.Column(scale=0):
61
- gr.Markdown("")
62
 
63
- image_gallery.select(fn=show_warning, inputs=None).then(lambda: Modal(visible=True), None, gallery_modal)
 
 
 
 
 
1
  import gradio as gr
 
 
2
 
 
3
 
4
+ def display_dataset(dataset_repo):
5
+ return gr.HTML(f"""<iframe
6
+ src="https://huggingface.co/datasets/{dataset_repo}/embed/viewer/default/train"
7
+ frameborder="0"
8
+ width="100%"
9
+ height="700px"
10
+ ></iframe>""")
11
 
12
 
13
  with gr.Blocks() as data_explorer:
14
  with gr.Row(variant="panel"):
15
+ with gr.Column(scale=0, min_width=160):
16
+ input_datasets_path = gr.Textbox(
17
+ label="HF datasets", placeholder="Gabriel/linkoping", scale=0, container=False
18
+ )
19
+ view_dataset = gr.Button("View dataseet", variant="primary", scale=0)
20
+ gr.LoginButton("Login to HF", variant="secondary", scale=0)
21
+ with gr.Column():
22
+ iframe_output = gr.HTML()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ view_dataset.click(
25
+ fn=display_dataset,
26
+ inputs=input_datasets_path,
27
+ outputs=[iframe_output],
28
+ )
app/tabs/examples_tab.py CHANGED
@@ -12,7 +12,7 @@ output_image_placehholder = gr.Image(
12
  height=400,
13
  show_share_button=True,
14
  )
15
- markdown_selected_option = gr.Markdown(container=True)
16
 
17
 
18
  def htr_image_placehholder(txt, method, image):
 
12
  height=400,
13
  show_share_button=True,
14
  )
15
+ markdown_selected_option = gr.Markdown(value="&nbsp;", container=True)
16
 
17
 
18
  def htr_image_placehholder(txt, method, image):
app/tabs/htrflow_tab.py CHANGED
@@ -41,6 +41,7 @@ def submit_button_pipeline_fn(method, input_image, yaml_str):
41
  def get_yaml_button_fn(
42
  method,
43
  output_formats,
 
44
  simple_segment_model=None,
45
  simple_htr_model=None,
46
  simple_htr_model_type=None,
@@ -54,21 +55,23 @@ def get_yaml_button_fn(
54
  ):
55
  env = Environment(loader=FileSystemLoader("app/templates"))
56
 
 
 
 
57
  template_name = "steps_template.yaml.j2"
58
  try:
59
  if method == "Simple layout":
60
  steps = [
61
  {
62
  "step": "Segmentation",
63
- "model": simple_htr_model_type,
64
  "model_settings": {"model": simple_segment_model},
65
  },
66
  {
67
  "step": "TextRecognition",
68
- "model": simple_segment_model_type,
69
  "model_settings": {"model": simple_htr_model},
70
  },
71
- {"step": "OrderLines"},
72
  ]
73
  elif method == "Nested segmentation":
74
  steps = [
@@ -87,11 +90,12 @@ def get_yaml_button_fn(
87
  "model": nested_htr_model_type,
88
  "model_settings": {"model": nested_htr_model},
89
  },
90
- {"step": "OrderLines"},
91
  ]
92
  else:
93
  return "Invalid method or not yet supported."
94
 
 
 
95
  steps.extend(
96
  {
97
  "step": "Export",
@@ -116,7 +120,7 @@ inital_state_selection_option = "Simple layout"
116
 
117
  with gr.Blocks() as htrflow_pipeline:
118
  with gr.Row(variant="panel"):
119
- with gr.Column():
120
  # gr.Markdown("<h2>Control Panel</h2>")
121
 
122
  with gr.Group():
@@ -180,6 +184,13 @@ with gr.Blocks() as htrflow_pipeline:
180
  with gr.Column():
181
  gr.Textbox("WIP")
182
  with gr.Row():
 
 
 
 
 
 
 
183
  output_formats = gr.Dropdown(
184
  choices=["txt", "alto", "page"],
185
  value="txt",
@@ -193,7 +204,7 @@ with gr.Blocks() as htrflow_pipeline:
193
  get_yaml_button = gr.Button("Get Yaml", variant="secondary", scale=0)
194
  output_files_pipeline = gr.Files(label="Output files", height=100, visible=False)
195
 
196
- with gr.Column():
197
  with gr.Tabs():
198
  with gr.Tab("Viewer"):
199
  with gr.Group():
@@ -224,6 +235,7 @@ with gr.Blocks() as htrflow_pipeline:
224
  inputs=[
225
  template_method_radio,
226
  output_formats,
 
227
  simple_segment_model,
228
  simple_htr_model,
229
  simple_htr_model_type,
@@ -253,6 +265,7 @@ with gr.Blocks() as htrflow_pipeline:
253
  inputs=[
254
  template_method_radio,
255
  output_formats,
 
256
  simple_segment_model,
257
  simple_htr_model,
258
  simple_htr_model_type,
 
41
  def get_yaml_button_fn(
42
  method,
43
  output_formats,
44
+ reading_order,
45
  simple_segment_model=None,
46
  simple_htr_model=None,
47
  simple_htr_model_type=None,
 
55
  ):
56
  env = Environment(loader=FileSystemLoader("app/templates"))
57
 
58
+ if output_formats is None:
59
+ output_formats = ["txt"]
60
+
61
  template_name = "steps_template.yaml.j2"
62
  try:
63
  if method == "Simple layout":
64
  steps = [
65
  {
66
  "step": "Segmentation",
67
+ "model": simple_segment_model_type,
68
  "model_settings": {"model": simple_segment_model},
69
  },
70
  {
71
  "step": "TextRecognition",
72
+ "model": simple_htr_model_type,
73
  "model_settings": {"model": simple_htr_model},
74
  },
 
75
  ]
76
  elif method == "Nested segmentation":
77
  steps = [
 
90
  "model": nested_htr_model_type,
91
  "model_settings": {"model": nested_htr_model},
92
  },
 
93
  ]
94
  else:
95
  return "Invalid method or not yet supported."
96
 
97
+ steps.append({"step": reading_order})
98
+
99
  steps.extend(
100
  {
101
  "step": "Export",
 
120
 
121
  with gr.Blocks() as htrflow_pipeline:
122
  with gr.Row(variant="panel"):
123
+ with gr.Column(scale=2):
124
  # gr.Markdown("<h2>Control Panel</h2>")
125
 
126
  with gr.Group():
 
184
  with gr.Column():
185
  gr.Textbox("WIP")
186
  with gr.Row():
187
+ reading_order = gr.Dropdown(
188
+ choices=["OrderLines", "ReadingOrderMarginalia"],
189
+ value="OrderLines",
190
+ multiselect=False,
191
+ label="Reading Order",
192
+ info="Supported format are: ...",
193
+ )
194
  output_formats = gr.Dropdown(
195
  choices=["txt", "alto", "page"],
196
  value="txt",
 
204
  get_yaml_button = gr.Button("Get Yaml", variant="secondary", scale=0)
205
  output_files_pipeline = gr.Files(label="Output files", height=100, visible=False)
206
 
207
+ with gr.Column(scale=2):
208
  with gr.Tabs():
209
  with gr.Tab("Viewer"):
210
  with gr.Group():
 
235
  inputs=[
236
  template_method_radio,
237
  output_formats,
238
+ reading_order,
239
  simple_segment_model,
240
  simple_htr_model,
241
  simple_htr_model_type,
 
265
  inputs=[
266
  template_method_radio,
267
  output_formats,
268
+ reading_order,
269
  simple_segment_model,
270
  simple_htr_model,
271
  simple_htr_model_type,
pyproject.toml CHANGED
@@ -17,9 +17,9 @@ classifiers = [
17
  requires-python = ">=3.10,<3.13"
18
 
19
  dependencies = [
20
- # "torch==2.0.1",
21
  "htrflow==0.1.3",
22
- "gradio>=5.11.0",
23
  "datasets>=3.2.0",
24
  "pandas>=2.2.3",
25
  "jinja2>=3.1.4",
 
17
  requires-python = ">=3.10,<3.13"
18
 
19
  dependencies = [
20
+ "torch==2.0.1",
21
  "htrflow==0.1.3",
22
+ "gradio[oauth]>=5.11.0",
23
  "datasets>=3.2.0",
24
  "pandas>=2.2.3",
25
  "jinja2>=3.1.4",
uv.lock CHANGED
The diff for this file is too large to render. See raw diff