amlpai04 commited on
Commit
e6c2b26
·
1 Parent(s): 8fa0da0

radical changes for workflow app instead

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +2 -0
  2. app/assets/__init__.py +0 -0
  3. app/assets/examples.py +0 -27
  4. app/assets/images/.gitkeep +0 -0
  5. app/assets/templates/1_simple.yaml +16 -0
  6. app/assets/templates/2_nested.yaml +22 -0
  7. app/assets/templates/c_nested_labels.yaml +41 -0
  8. app/assets/templates/c_nested_reading_order.yaml +24 -0
  9. app/assets/templates/c_nested_with_filter.yaml +28 -0
  10. app/assets/templates/c_simple_gensettings.yaml +21 -0
  11. app/assets/templates/c_simple_multi_output.yaml +24 -0
  12. app/backend.py +0 -0
  13. app/content/ENG/changelog_roadmap/changelog.md +0 -14
  14. app/content/ENG/changelog_roadmap/old_changelog.md +0 -39
  15. app/content/ENG/changelog_roadmap/roadmap.md +0 -27
  16. app/content/ENG/contributions/contributions.md +0 -33
  17. app/content/ENG/contributions/huminfra_image.md +0 -3
  18. app/content/ENG/contributions/riksarkivet_image.md +0 -3
  19. app/content/ENG/duplicate_api/api1.md +0 -11
  20. app/content/ENG/duplicate_api/api2.md +0 -3
  21. app/content/ENG/duplicate_api/api_code1.md +0 -11
  22. app/content/ENG/duplicate_api/api_code2.md +0 -26
  23. app/content/ENG/duplicate_api/duplicate.md +0 -26
  24. app/content/ENG/faq_discussion/discussion.md +0 -7
  25. app/content/ENG/faq_discussion/faq.md +0 -13
  26. app/content/ENG/htrflow/htrflow_col1.md +0 -18
  27. app/content/ENG/htrflow/htrflow_col2.md +0 -23
  28. app/content/ENG/htrflow/htrflow_row1.md +0 -3
  29. app/content/ENG/htrflow/htrflow_tab1.md +0 -7
  30. app/content/ENG/htrflow/htrflow_tab2.md +0 -7
  31. app/content/ENG/htrflow/htrflow_tab3.md +0 -7
  32. app/content/ENG/htrflow/htrflow_tab4.md +0 -7
  33. app/content/NOR/htrflow/htrflow_col1.md +0 -18
  34. app/content/NOR/htrflow/htrflow_col2.md +0 -23
  35. app/content/NOR/htrflow/htrflow_row1.md +0 -3
  36. app/content/NOR/htrflow/htrflow_tab1.md +0 -7
  37. app/content/NOR/htrflow/htrflow_tab2.md +0 -7
  38. app/content/NOR/htrflow/htrflow_tab3.md +0 -7
  39. app/content/NOR/htrflow/htrflow_tab4.md +0 -7
  40. app/content/SWE/htrflow/htrflow_col1.md +0 -18
  41. app/content/SWE/htrflow/htrflow_col2.md +0 -23
  42. app/content/SWE/htrflow/htrflow_row1.md +0 -3
  43. app/content/SWE/htrflow/htrflow_tab1.md +0 -7
  44. app/content/SWE/htrflow/htrflow_tab2.md +0 -7
  45. app/content/SWE/htrflow/htrflow_tab3.md +0 -7
  46. app/content/SWE/htrflow/htrflow_tab4.md +0 -7
  47. app/gradio_config.py +0 -7
  48. app/main.py +12 -71
  49. app/plot_viewer.py +0 -200
  50. app/tabs/adv_htrflow_tab.py +11 -37
README.md CHANGED
@@ -17,4 +17,6 @@ datasets:
17
  "Riksarkivet/placeholder_line_segmentation",
18
  "Riksarkivet/placeholder_htr",
19
  ]
 
 
20
  ---
 
17
  "Riksarkivet/placeholder_line_segmentation",
18
  "Riksarkivet/placeholder_htr",
19
  ]
20
+ license: mit
21
+ short_description: Transform research papers and mathematical concepts into stu
22
  ---
app/assets/__init__.py DELETED
File without changes
app/assets/examples.py DELETED
@@ -1,27 +0,0 @@
1
- import io
2
-
3
- import datasets
4
- from PIL import Image
5
-
6
-
7
- class DemoImages:
8
- def __init__(self, url="Riksarkivet/test_images_demo", cache_dir=".app/assets/images/.cache_images"):
9
- if not hasattr(self, "images_datasets"):
10
- self.images_datasets = datasets.load_dataset(url, cache_dir=cache_dir, split="train")
11
- self.example_df = self.images_datasets.to_pandas()
12
- self.examples_list = self.convert_bytes_to_images()
13
-
14
- def convert_bytes_to_images(self):
15
- examples_list = []
16
- for index, row in self.example_df.iterrows():
17
- image_bytes = row["image"]["bytes"]
18
- image = Image.open(io.BytesIO(image_bytes))
19
-
20
- path_to_image = f"./app/assets/images/image_{index}.jpg"
21
- image.save(path_to_image)
22
-
23
- description = row["text"]
24
-
25
- examples_list.append([description, "Nested segmentation", path_to_image])
26
-
27
- return examples_list
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/assets/images/.gitkeep DELETED
File without changes
app/assets/templates/1_simple.yaml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-lines-within-regions-1
7
+ - step: TextRecognition
8
+ settings:
9
+ model: TrOCR
10
+ model_settings:
11
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
12
+ - step: OrderLines
13
+ - step: Export
14
+ settings:
15
+ format: txt
16
+ dest: outputs
app/assets/templates/2_nested.yaml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-regions-1
7
+ - step: Segmentation
8
+ settings:
9
+ model: yolo
10
+ model_settings:
11
+ model: Riksarkivet/yolov9-lines-within-regions-1
12
+ - step: TextRecognition
13
+ settings:
14
+ model: TrOCR
15
+ model_settings:
16
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
17
+ - step: OrderLines
18
+ - step: Export
19
+ settings:
20
+ format: txt
21
+ dest: text-outputs
22
+
app/assets/templates/c_nested_labels.yaml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-regions-1
7
+ generation_settings:
8
+ batch_size: 2
9
+ - step: Segmentation
10
+ settings:
11
+ model: yolo
12
+ model_settings:
13
+ model: Riksarkivet/yolov9-lines-within-regions-1
14
+ generation_settings:
15
+ batch_size: 2
16
+ - step: TextRecognition
17
+ settings:
18
+ model: WordLevelTrocr
19
+ model_settings:
20
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
21
+ generation_settings:
22
+ batch_size: 4
23
+ num_beams: 1
24
+ - step: ReadingOrderMarginalia
25
+ settings:
26
+ two_page: auto
27
+ - step: Export
28
+ settings:
29
+ dest: outputs/alto
30
+ format: alto
31
+ - step: Export
32
+ settings:
33
+ dest: outputs/page
34
+ format: page
35
+ labels:
36
+ level_labels:
37
+ - region
38
+ - line
39
+ - word
40
+ sep: _
41
+ template: "{label}{number}"
app/assets/templates/c_nested_reading_order.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-regions-1
7
+ - step: Segmentation
8
+ settings:
9
+ model: yolo
10
+ model_settings:
11
+ model: Riksarkivet/yolov9-lines-within-regions-1
12
+ - step: TextRecognition
13
+ settings:
14
+ model: TrOCR
15
+ model_settings:
16
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
17
+ - step: ReadingOrderMarginalia
18
+ settings:
19
+ two_page: always
20
+ - step: Export
21
+ settings:
22
+ format: txt
23
+ dest: text-outputs
24
+
app/assets/templates/c_nested_with_filter.yaml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-regions-1
7
+ - step: Segmentation
8
+ settings:
9
+ model: yolo
10
+ model_settings:
11
+ model: Riksarkivet/yolov9-lines-within-regions-1
12
+ - step: TextRecognition
13
+ settings:
14
+ model: TrOCR
15
+ model_settings:
16
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
17
+ - step: OrderLines
18
+ - step: Export
19
+ settings:
20
+ format: txt
21
+ dest: raw-outputs
22
+ - step: RemoveLowTextConfidenceLines
23
+ settings:
24
+ threshold: 0.95
25
+ - step: Export
26
+ settings:
27
+ format: txt
28
+ dest: cleaned-outputs
app/assets/templates/c_simple_gensettings.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-lines-within-regions-1
7
+ generation_settings:
8
+ batch_size: 2
9
+ - step: TextRecognition
10
+ settings:
11
+ model: TrOCR
12
+ model_settings:
13
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
14
+ generation_settings:
15
+ batch_size: 4
16
+ num_beams: 1
17
+ - step: OrderLines
18
+ - step: Export
19
+ settings:
20
+ format: txt
21
+ dest: outputs
app/assets/templates/c_simple_multi_output.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ steps:
2
+ - step: Segmentation
3
+ settings:
4
+ model: yolo
5
+ model_settings:
6
+ model: Riksarkivet/yolov9-lines-within-regions-1
7
+ - step: TextRecognition
8
+ settings:
9
+ model: TrOCR
10
+ model_settings:
11
+ model: Riksarkivet/trocr-base-handwritten-hist-swe-2
12
+ - step: OrderLines
13
+ - step: Export
14
+ settings:
15
+ format: txt
16
+ dest: text-outputs
17
+ - step: Export
18
+ settings:
19
+ format: page
20
+ dest: page-outputs
21
+ - step: Export
22
+ settings:
23
+ format: alto
24
+ dest: alto-outputs
app/backend.py DELETED
File without changes
app/content/ENG/changelog_roadmap/changelog.md DELETED
@@ -1,14 +0,0 @@
1
- ## Changelog
2
-
3
- All notable changes to HTRFLOW will be documented here.
4
-
5
- ### [0.1.0] - 2023-11-08
6
-
7
- #### Added
8
-
9
- - Support for TROCR -> Latin and Eng model
10
- - New feature! Compare different runs with GT, see tab **Fast track** > **Compare**
11
-
12
- #### Fixed
13
-
14
- - Fixed bug for Docker and running app locally, [issue](https://github.com/Riksarkivet/HTRFLOW/issues/2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/changelog_roadmap/old_changelog.md DELETED
@@ -1,39 +0,0 @@
1
- ## Changelog
2
-
3
- All notable changes to HTRFLOW will be documented here.
4
-
5
- ### [0.0.2] - 2023-11-01
6
-
7
- #### Added
8
-
9
- - Better documentation for API, see **Overview** > **Duplicating for own use & API**
10
- - Better documentation for restrictions of app, see **Overview** > **HTRFLOW**
11
-
12
- #### Fixed
13
-
14
- - Fixed bug for API, [issue](https://github.com/Riksarkivet/HTRFLOW/issues/2)
15
-
16
- #### Changed
17
-
18
- - Changed named for **FAQ & Discussion** to **FAQ & Contact**
19
-
20
- ---
21
-
22
- ### [0.0.1] - 2023-10-23
23
-
24
- #### Added
25
-
26
- - Added a new feature to **Stepwise** > **Explore results** > New Text diff and CER component
27
-
28
- #### Fixed
29
-
30
- - Fixed naming conventions of tabs in app so they are more coherent with the code.
31
-
32
- #### Changed
33
-
34
- - Changed the layout in both Fast track and Stepwise to improve the UX
35
-
36
- - Examples are viewed in the middle of the layout
37
- - "Advanced settings" are initial hidden
38
-
39
- - Removed **help** tab for now (documentation of Fast track and Stepwise will come in a later release)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/changelog_roadmap/roadmap.md DELETED
@@ -1,27 +0,0 @@
1
- ## Roadmap
2
-
3
- Our roadmap is where you can learn about what features we're working on. Have any questions or comments about items on the roadmap? See **Overview** > **FAQ & Discussion** for feedback or collaboration.
4
-
5
- ### Working on
6
-
7
- - Release Training and Eval data on HuggingFace
8
-
9
- - Add support for TrOCR models as Text recognition model:
10
-
11
- - Train a TrOCR model specialized on Swedish historical handwritten text.
12
-
13
- - Optimize the backend of the application:
14
- - Package the code
15
- - Add support for batch inference
16
- - Start a collaborative open source project
17
-
18
- ### Backlog
19
-
20
- - Initial document classifier
21
-
22
- - Add support for Different segmentation strategies:
23
-
24
- - Table detection
25
- - Different text layouts with multiple columns
26
-
27
- - Add more endpoints for rest api and add a more extensive documentation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/contributions/contributions.md DELETED
@@ -1,33 +0,0 @@
1
- ## HTRFLOW – Contributions
2
-
3
- The AI models used in HTRFLOW is the result of a collaborative effort, involving the National Archives in both Sweden and Finland, in partnership with the Stockholm City Archives, Jämtlands läns fornskriftsällskap, citizen science volunteers and researchers from Stockholm and Uppsala Universities.
4
-
5
- Several datasets have been created by participants through Citizen Science using the Handwritten Text Recognition (HTR) software, Transkribus, provided by [READ-COOP SCE](https://readcoop.eu/) .
6
-
7
- ### Archives used to train models for HTRFLOW
8
-
9
- [Svea hovrätt (Renskrivna protokoll), 1713–1735](https://sok.riksarkivet.se/arkiv/H2hpDbNn14scxjzdWqAaJ1)
10
-
11
- [Bergmästaren i Nora m fl bergslag (Hammartingsprotokoll), 1698–1765](https://sok.riksarkivet.se/arkiv/M5Fe2TT9rH6cxG02H087k3)
12
-
13
- [Trolldomskommissionen, mainly 1670s](https://sok.riksarkivet.se/trolldomskommissionen)
14
-
15
- [Bergskollegium, 1718–1758](https://sok.riksarkivet.se/arkiv/SMFky31ekQ80Qsk0UCZZE2)
16
-
17
- [Jämtlands domsaga, 1647–1688](https://sok.riksarkivet.se/arkiv/2l4NYFT8rH6cxG02H087k3)
18
-
19
- [Stockholms domkapitel, 1728–1759](https://sok.riksarkivet.se/arkiv/etg1tyeEaIPMBzKbUKTjw1)
20
-
21
- [Politikollegiet, 1729–1759](https://sok.riksarkivet.se/arkiv/1lQnXIDiKaYxRLBlK1dGF3)
22
-
23
- [Göteborgs poliskammare före 1900 (Detektiva polisens rapportböcker), 1868–1901](https://sok.riksarkivet.se/arkiv/oLTOi9yxweZJUG018W43t3)
24
-
25
- [Renovated Court Records, the National Archives of Finland, 1800s](https://tuomiokirjat.kansallisarkisto.fi/)
26
-
27
- ### Ongoing research collaborations
28
-
29
- [Transcription node Sweden – machine interpretation and citizen research combined](https://riksarkivet.se/forskning), Swedish National Archives and University of Gothenburg, funded by the Swedish National Heritage Board.
30
-
31
- [Mapping the geographies of early modern mining knowledge. A digital history of the study tours of the Swedish Bureau of Mines, 1691–1826](https://www.idehist.uu.se/forskning/projekt/den-tidigmoderna-bergsvetenskapens-geografier), Uppsala University and Stockholm University, funded by the Swedish Research Council.
32
-
33
- The Swedish National Archives' research and development on HTR is part of the Swedish national infrastructure Huminfra. [Click here](https://riksarkivet.se/huminfra) for more information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/contributions/huminfra_image.md DELETED
@@ -1,3 +0,0 @@
1
- <a href="https://www.huminfra.se/">
2
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/Huminfra_logo.png?raw=true" width="17%" align="left" margin-right="100" />
3
- </a>
 
 
 
 
app/content/ENG/contributions/riksarkivet_image.md DELETED
@@ -1,3 +0,0 @@
1
- <a href="https://riksarkivet.se">
2
- <img src="https://raw.githubusercontent.com/Borg93/Riksarkivet_docs/main/docs/assets/fav-removebg-preview.png" width="17%" align="right" margin-right="100" />
3
- </a>
 
 
 
 
app/content/ENG/duplicate_api/api1.md DELETED
@@ -1,11 +0,0 @@
1
- ## Usage of Client API
2
-
3
- If you prefer to run **Fast track** programmatically, we offer an API for that purpose.
4
-
5
- - [REST API](https://riksarkivet-htr-demo.hf.space/?view=api)
6
- - Docuemtnation for gradio client with [python](https://www.gradio.app/guides/getting-started-with-the-python-client)
7
- - Docuemtnation for gradio client with [javascript](https://www.gradio.app/guides/getting-started-with-the-js-client)
8
-
9
- **Note**: More extensive APIs and documentation can be added in the future upon request.
10
-
11
- See example below for usage of API in python:
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/duplicate_api/api2.md DELETED
@@ -1,3 +0,0 @@
1
- ### Output from the api
2
-
3
- The output from the api is currently in the format of Page XML, which can be imported into this [viewer](https://huggingface.co/spaces/Riksarkivet/Viewer_demo).
 
 
 
 
app/content/ENG/duplicate_api/api_code1.md DELETED
@@ -1,11 +0,0 @@
1
- from gradio_client import Client # pip install gradio_client
2
-
3
- # Change url to your client (localhost: http://127.0.0.1:7860/)
4
-
5
- client = Client("https://huggingface.co/spaces/Riksarkivet/htr_demo")
6
- job = client.submit(
7
- "https://your.image.url.or.pah.jpg",
8
- api_name="/run_htr_pipeline",
9
- )
10
-
11
- print(job.result())
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/duplicate_api/api_code2.md DELETED
@@ -1,26 +0,0 @@
1
- Loaded as API: http://127.0.0.1:7860/ ✔
2
-
3
- <?xml version="1.0" encoding="UTF-8"?>
4
- <PcGts xmlns="http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15 http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15/pagecontent.xsd">
5
- <Metadata>
6
- <Creator>Swedish National Archives</Creator>
7
- <Created>2023-08-21, 13:28:06</Created>
8
- </Metadata>
9
- <Page imageFilename="page_xml.xml" imageWidth="4885" imageHeight="4066">
10
- <TextRegion id="region_0" custom="readingOrder {index:0;}">
11
- <Coords points="1477,265 1467,217 1440,201 1370,211 1248,203 1127,224 1067,224 1003,212 844,247 766,243 747,261 742,280 751,332 766,346 1258,341 1357,332 1439,341 1468,327"/>
12
- <TextLine id="line_region_0_0" custom="readingOrder {index:0;}">
13
- <Coords points="1458,248 1443,222 1449,200 1412,215 1366,200 1325,207 1302,200 1241,200 1235,206 1205,200 1187,210 1085,222 957,206 795,239 769,273 771,333 783,340 1445,333 1450,324"/>
14
- <TextEquiv>
15
- <Unicode>År 1865.</Unicode>
16
- </TextEquiv>
17
- <PredScore pred_score="0.9482"/>
18
- </TextLine>
19
- </TextRegion>
20
- <TextRegion id="region_1" custom="readingOrder {index:1;}">
21
- ......................................
22
- </TextRegion>
23
- </Page>
24
- </PcGts>
25
-
26
- # Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/duplicate_api/duplicate.md DELETED
@@ -1,26 +0,0 @@
1
- ## Duplicating for own use
2
-
3
- Please be aware of certain limitations when using the application:
4
-
5
- - This application is primarily designed for demonstration purposes and is not intended for scaling up HTR.
6
- - Currently, the Swedish National Archives has constraints on sharing hardware, leading to a queue system for high demand.
7
- - The demo is hosted on Hugging Face domains, and they may rate-limit you if there's an excessive number of requests in a short timeframe, especially when using the API.
8
-
9
- For those requiring heavy usage, you can conveniently duplicate the application.
10
-
11
- - Duplicate [application](https://huggingface.co/spaces/Riksarkivet/htr_demo?duplicate=true).
12
-
13
- By doing so, you'll create your own private app, which allows for unlimited requests without any restrictions. The image below shows the minimum hardware you need to use if you don't have access to hardware youself:
14
-
15
- <figure>
16
-
17
- <img src="https://raw.githubusercontent.com/Borg93/htr_gradio_file_placeholder/main/hardware_example.png" alt="HTR_tool" style="width:75%; display: block; margin-left: auto; margin-right:auto;" >
18
- <figcaption style="text-align: center;"> <em> Figure - Choose a hardware that has atleast a GPU </em></figcaption>
19
- </figure>
20
-
21
- For individuals with access to dedicated hardware, additional options are available. You have the flexibility to run this application on your own machine utilizing Docker, or by cloning the repository directly. Doing so allows you to leverage your hardware's capabilities to their fullest extent.
22
-
23
- - [Clone with Docker](https://huggingface.co/spaces/Riksarkivet/htr_demo?docker=true)
24
- - [Clone Repo](https://huggingface.co/spaces/Riksarkivet/htr_demo/settings?clone=true)
25
-
26
- **Note**: To take advantage of CUDA for accelerated inferences, an Nvidia graphics card is required. This setup significantly enhances the performance, ensuring a smoother and faster operation.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/faq_discussion/discussion.md DELETED
@@ -1,7 +0,0 @@
1
- ## Contact us
2
-
3
- If you have any questions, or suggestions for features or improvements, please don’t hesitate to contact us.
4
-
5
- - Open a discussion on [HuggingFace](https://huggingface.co/spaces/Riksarkivet/htr_demo/discussions).
6
-
7
- - Send an email to: forskning@riksarkivet.se
 
 
 
 
 
 
 
 
app/content/ENG/faq_discussion/faq.md DELETED
@@ -1,13 +0,0 @@
1
- ## Frequently Asked Questions
2
-
3
- **Q**: <u>Is my data secure? Can I upload my own images?</u>
4
- **A**: Absolutely. Uploaded files are not saved or stored.
5
-
6
- **Q**: <u>Why am I always in a queue?</u>
7
- **A**: This is due to hardware constraints and rate limits imposed by Hugging Face. For alternative ways to use the app, refer to the tab > **Documentation** under > **Duplication for Own Use & API**.
8
-
9
- **Q**: <u>Why is Fast track so slow?</u>
10
- **A**: The current speed is due to hardware limitations and the present state of the code. However, we plan to update the application in future releases, which will significantly improve the performance of the application.
11
-
12
- **Q**: <u>Is it possible to run Fast track or the API on image batches?</u>
13
- **A**: Not currently, but we plan to implement this feature in the future.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/htrflow/htrflow_col1.md DELETED
@@ -1,18 +0,0 @@
1
- ## Introduction
2
-
3
- The Swedish National Archives introduces a demonstrational end-to-end HTR (Handwritten Text Recognition) pipeline. The pipeline consists of two instance segmentation models, one trained for segmenting text-regions within running-text document images, and another trained for segmenting text-lines within these regions. The text-lines are then transcribed by a text-recognition model trained on a vast set of swedish handwriting ranging from the 17th to the 19th century.
4
-
5
- ## Usage
6
-
7
- It needs to be emphasized that this application is intended mainly for demo-purposes. Its aim is to showcase our pipeline for transcribing historical, running-text documents, not to put the pipeline into large-scale production.
8
- **Note**: In the future we’ll optimize the code to suit a production scenario with multi-GPU, batch-inference, but this is still a work in progress. <br>
9
-
10
- For an insight into the upcoming features we are working on:
11
-
12
- - Navigate to the > **Overview** > **Changelog & Roadmap**.
13
-
14
- ## Limitations
15
-
16
- The demo, hosted on Huggingface and assigned a T4 GPU, can only handle two users submissions at a time. If you experience long wait times or unresponsiveness, this is the reason. In the future, we plan to host this solution ourselves, with a better server for an improved user experience, optimized code, and multiple model options. Exciting developments are on the horizon!
17
-
18
- It's also important to note that the models work on running text, not text in table format.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/htrflow/htrflow_col2.md DELETED
@@ -1,23 +0,0 @@
1
- ## Source Code
2
-
3
- Please fork and leave a star on Github if you like it! The code for this project can be found here:
4
-
5
- - [Github](https://github.com/Riksarkivet/HTRFLOW)
6
-
7
- **Note**: We will in the future package all of the code for mass HTR (batch inference on multi-GPU setup), but the code is still work in progress.
8
-
9
- ## Models
10
-
11
- The models used in this demo are very much a work in progress, and as more data, and new architectures, becomes available, they will be retrained and reevaluated. For more information about the models, please refer to their model-cards on Huggingface.
12
-
13
- - [Riksarkivet/rtmdet_regions](https://huggingface.co/Riksarkivet/rtmdet_regions)
14
- - [Riksarkivet/rtmdet_lines](https://huggingface.co/Riksarkivet/rtmdet_lines)
15
- - [Riksarkivet/satrn_htr](https://huggingface.co/https://huggingface.co/Riksarkivet/satrn_htr)
16
-
17
- ## Datasets
18
-
19
- Train and testsets created by the Swedish National Archives will be released here:
20
-
21
- - [Riksarkivet/placeholder_region_segmentation](https://huggingface.co/datasets/Riksarkivet/placeholder_region_segmentation)
22
- - [Riksarkivet/placeholder_line_segmentation](https://huggingface.co/datasets/Riksarkivet/placeholder_line_segmentation)
23
- - [Riksarkivet/placeholder_htr](https://huggingface.co/datasets/Riksarkivet/placeholder_htr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/ENG/htrflow/htrflow_row1.md DELETED
@@ -1,3 +0,0 @@
1
- ## The Pipeline in Overview
2
-
3
- The steps in the pipeline can be seen below as follows:
 
 
 
 
app/content/ENG/htrflow/htrflow_tab1.md DELETED
@@ -1,7 +0,0 @@
1
- ### Binarization
2
-
3
- The reason for binarizing the images before processing them is that we want the models to generalize as well as possible. By training on only binarized images and by binarizing images before running them through the pipeline, we take the target domain closer to the training domain, and reduce negative effects of background variation, background noise etc., on the final results. The pipeline implements a simple adaptive thresholding algorithm for binarization.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_bin.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/ENG/htrflow/htrflow_tab2.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text-region segmentation
2
-
3
- To facilitate the text-line segmentation process, it is advantageous to segment the image into text-regions beforehand. This initial step offers several benefits, including reducing variations in line spacing, eliminating blank areas on the page, establishing a clear reading order, and distinguishing marginalia from the main text. The segmentation model utilized in this process predicts both bounding boxes and masks. Although the model has the capability to predict both, only the masks are utilized for the segmentation tasks of lines and regions. An essential post-processing step involves checking for regions that are contained within other regions. During this step, only the containing region is retained, while the contained region is discarded. This ensures that the final segmented text-regions are accurate and devoid of overlapping or redundant areas. This ensures that there’s no duplicate text-regions sent to the text-recognition model.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_region.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/ENG/htrflow/htrflow_tab3.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text-line segmentation
2
-
3
- This is also an instance segmentation model, trained on extracting text-lines from the cropped text-regions. The same post-processing as in the text-region segmentation step, is done in the text-line segmentation step.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_line.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/ENG/htrflow/htrflow_tab4.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text Recognition
2
-
3
- The text-recognition model was trained on approximately one million handwritten text-line images ranging from the 17th to the 19th century. See the model card for detailed evaluation results, and results from some fine-tuning experiments.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_htr.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/NOR/htrflow/htrflow_col1.md DELETED
@@ -1,18 +0,0 @@
1
- ### Introduktion
2
-
3
- Riksarkivet presenterar en demonstrationspipeline för HTR (Handwritten Text Recognition). Pipelinen består av två instanssegmenteringsmodeller: en tränad för att segmentera textregioner i bilder av löpande-textdokument och en annan tränad för att segmentera textrader inom dessa regioner. Textraderna transkriberas därefter av en textigenkänningsmodell som är tränad på ett stort dataset med svensk handskrift från 1600- till 1800-talet.
4
-
5
- ### Användning
6
-
7
- Det är viktigt att betona att denna applikation främst är avsedd för demonstrationsändamål. Målet är att visa upp vår pipeline för att transkribera historiska dokument med löpande text, inte att använda pipelinen i storskalig produktion.
8
- **Obs**: I framtiden kommer vi att optimera koden för att passa ett produktionsscenario med multi-GPU och batch-inferens, men detta arbete pågår fortfarande. <br>
9
-
10
- För en inblick i de kommande funktionerna vi arbetar med:
11
-
12
- - Navigera till > **Översikt** > **Ändringslogg och roadmap**.
13
-
14
- ### Begränsningar
15
-
16
- Demon, som är värd på Huggingface och tilldelad en T4 GPU, kan bara hantera två användarinlämningar åt gången. Om du upplever långa väntetider eller att applikationen inte svarar, är detta anledningen. I framtiden planerar vi att själva vara värdar för denna lösning, med en bättre server för en förbättrad användarupplevelse, optimerad kod och flera modellalternativ. Spännande utveckling är på gång!
17
-
18
- Det är också viktigt att notera att modellerna fungerar på löpande text och inte text i tabellformat.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/NOR/htrflow/htrflow_col2.md DELETED
@@ -1,23 +0,0 @@
1
- ## Source Code
2
-
3
- Please fork and leave a star on Github if you like it! The code for this project can be found here:
4
-
5
- - [Github](https://github.com/Riksarkivet/HTRFLOW)
6
-
7
- **Note**: We will in the future package all of the code for mass HTR (batch inference on multi-GPU setup), but the code is still work in progress.
8
-
9
- ## Models
10
-
11
- The models used in this demo are very much a work in progress, and as more data, and new architectures, becomes available, they will be retrained and reevaluated. For more information about the models, please refer to their model-cards on Huggingface.
12
-
13
- - [Riksarkivet/rtmdet_regions](https://huggingface.co/Riksarkivet/rtmdet_regions)
14
- - [Riksarkivet/rtmdet_lines](https://huggingface.co/Riksarkivet/rtmdet_lines)
15
- - [Riksarkivet/satrn_htr](https://huggingface.co/https://huggingface.co/Riksarkivet/satrn_htr)
16
-
17
- ## Datasets
18
-
19
- Train and testsets created by the Swedish National Archives will be released here:
20
-
21
- - [Riksarkivet/placeholder_region_segmentation](https://huggingface.co/datasets/Riksarkivet/placeholder_region_segmentation)
22
- - [Riksarkivet/placeholder_line_segmentation](https://huggingface.co/datasets/Riksarkivet/placeholder_line_segmentation)
23
- - [Riksarkivet/placeholder_htr](https://huggingface.co/datasets/Riksarkivet/placeholder_htr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/NOR/htrflow/htrflow_row1.md DELETED
@@ -1,3 +0,0 @@
1
- ## The Pipeline in Overview
2
-
3
- The steps in the pipeline can be seen below as follows:
 
 
 
 
app/content/NOR/htrflow/htrflow_tab1.md DELETED
@@ -1,7 +0,0 @@
1
- ### Binarization
2
-
3
- The reason for binarizing the images before processing them is that we want the models to generalize as well as possible. By training on only binarized images and by binarizing images before running them through the pipeline, we take the target domain closer to the training domain, and reduce negative effects of background variation, background noise etc., on the final results. The pipeline implements a simple adaptive thresholding algorithm for binarization.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_bin.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/NOR/htrflow/htrflow_tab2.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text-region segmentation
2
-
3
- To facilitate the text-line segmentation process, it is advantageous to segment the image into text-regions beforehand. This initial step offers several benefits, including reducing variations in line spacing, eliminating blank areas on the page, establishing a clear reading order, and distinguishing marginalia from the main text. The segmentation model utilized in this process predicts both bounding boxes and masks. Although the model has the capability to predict both, only the masks are utilized for the segmentation tasks of lines and regions. An essential post-processing step involves checking for regions that are contained within other regions. During this step, only the containing region is retained, while the contained region is discarded. This ensures that the final segmented text-regions are accurate and devoid of overlapping or redundant areas. This ensures that there’s no duplicate text-regions sent to the text-recognition model.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_region.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/NOR/htrflow/htrflow_tab3.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text-line segmentation
2
-
3
- This is also an instance segmentation model, trained on extracting text-lines from the cropped text-regions. The same post-processing as in the text-region segmentation step, is done in the text-line segmentation step.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_line.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/NOR/htrflow/htrflow_tab4.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text Recognition
2
-
3
- The text-recognition model was trained on approximately one million handwritten text-line images ranging from the 17th to the 19th century. See the model card for detailed evaluation results, and results from some fine-tuning experiments.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_htr.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/SWE/htrflow/htrflow_col1.md DELETED
@@ -1,18 +0,0 @@
1
- ### Introduktion
2
-
3
- Riksarkivet presenterar en demonstrationspipeline för HTR (Handwritten Text Recognition). Pipelinen består av två instanssegmenteringsmodeller: en tränad för att segmentera textregioner i bilder av löpande-textdokument och en annan tränad för att segmentera textrader inom dessa regioner. Textraderna transkriberas därefter av en textigenkänningsmodell som är tränad på ett stort dataset med svensk handskrift från 1600- till 1800-talet.
4
-
5
- ### Användning
6
-
7
- Det är viktigt att betona att denna applikation främst är avsedd för demonstrationsändamål. Målet är att visa upp vår pipeline för att transkribera historiska dokument med löpande text, inte att använda pipelinen i storskalig produktion.
8
- **Obs**: I framtiden kommer vi att optimera koden för att passa ett produktionsscenario med multi-GPU och batch-inferens, men detta arbete pågår fortfarande. <br>
9
-
10
- För en inblick i de kommande funktionerna vi arbetar med:
11
-
12
- - Navigera till > **Översikt** > **Ändringslogg och roadmap**.
13
-
14
- ### Begränsningar
15
-
16
- Demon, som är värd på Huggingface och tilldelad en T4 GPU, kan bara hantera två användarinlämningar åt gången. Om du upplever långa väntetider eller att applikationen inte svarar, är detta anledningen. I framtiden planerar vi att själva vara värdar för denna lösning, med en bättre server för en förbättrad användarupplevelse, optimerad kod och flera modellalternativ. Spännande utveckling är på gång!
17
-
18
- Det är också viktigt att notera att modellerna fungerar på löpande text och inte text i tabellformat.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/SWE/htrflow/htrflow_col2.md DELETED
@@ -1,23 +0,0 @@
1
- ## Source Code
2
-
3
- Please fork and leave a star on Github if you like it! The code for this project can be found here:
4
-
5
- - [Github](https://github.com/Riksarkivet/HTRFLOW)
6
-
7
- **Note**: We will in the future package all of the code for mass HTR (batch inference on multi-GPU setup), but the code is still work in progress.
8
-
9
- ## Models
10
-
11
- The models used in this demo are very much a work in progress, and as more data, and new architectures, becomes available, they will be retrained and reevaluated. For more information about the models, please refer to their model-cards on Huggingface.
12
-
13
- - [Riksarkivet/rtmdet_regions](https://huggingface.co/Riksarkivet/rtmdet_regions)
14
- - [Riksarkivet/rtmdet_lines](https://huggingface.co/Riksarkivet/rtmdet_lines)
15
- - [Riksarkivet/satrn_htr](https://huggingface.co/https://huggingface.co/Riksarkivet/satrn_htr)
16
-
17
- ## Datasets
18
-
19
- Train and testsets created by the Swedish National Archives will be released here:
20
-
21
- - [Riksarkivet/placeholder_region_segmentation](https://huggingface.co/datasets/Riksarkivet/placeholder_region_segmentation)
22
- - [Riksarkivet/placeholder_line_segmentation](https://huggingface.co/datasets/Riksarkivet/placeholder_line_segmentation)
23
- - [Riksarkivet/placeholder_htr](https://huggingface.co/datasets/Riksarkivet/placeholder_htr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/content/SWE/htrflow/htrflow_row1.md DELETED
@@ -1,3 +0,0 @@
1
- ## The Pipeline in Overview
2
-
3
- The steps in the pipeline can be seen below as follows:
 
 
 
 
app/content/SWE/htrflow/htrflow_tab1.md DELETED
@@ -1,7 +0,0 @@
1
- ### Binarization
2
-
3
- The reason for binarizing the images before processing them is that we want the models to generalize as well as possible. By training on only binarized images and by binarizing images before running them through the pipeline, we take the target domain closer to the training domain, and reduce negative effects of background variation, background noise etc., on the final results. The pipeline implements a simple adaptive thresholding algorithm for binarization.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_bin.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/SWE/htrflow/htrflow_tab2.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text-region segmentation
2
-
3
- To facilitate the text-line segmentation process, it is advantageous to segment the image into text-regions beforehand. This initial step offers several benefits, including reducing variations in line spacing, eliminating blank areas on the page, establishing a clear reading order, and distinguishing marginalia from the main text. The segmentation model utilized in this process predicts both bounding boxes and masks. Although the model has the capability to predict both, only the masks are utilized for the segmentation tasks of lines and regions. An essential post-processing step involves checking for regions that are contained within other regions. During this step, only the containing region is retained, while the contained region is discarded. This ensures that the final segmented text-regions are accurate and devoid of overlapping or redundant areas. This ensures that there’s no duplicate text-regions sent to the text-recognition model.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_region.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/SWE/htrflow/htrflow_tab3.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text-line segmentation
2
-
3
- This is also an instance segmentation model, trained on extracting text-lines from the cropped text-regions. The same post-processing as in the text-region segmentation step, is done in the text-line segmentation step.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_line.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/content/SWE/htrflow/htrflow_tab4.md DELETED
@@ -1,7 +0,0 @@
1
- ### Text Recognition
2
-
3
- The text-recognition model was trained on approximately one million handwritten text-line images ranging from the 17th to the 19th century. See the model card for detailed evaluation results, and results from some fine-tuning experiments.
4
-
5
- <figure>
6
- <img src="https://github.com/Borg93/htr_gradio_file_placeholder/blob/main/app_project_htr.png?raw=true" alt="HTR_tool" style="width:70%; display: block; margin-left: auto; margin-right:auto;" >
7
- </figure>
 
 
 
 
 
 
 
 
app/gradio_config.py CHANGED
@@ -13,12 +13,5 @@ theme = gr.themes.Default(
13
  )
14
 
15
  css = """
16
- body > gradio-app > div > div > div.wrap.svelte-1rjryqp > footer > a {
17
- display: none !important;
18
- }
19
- body > gradio-app > div > div > div.wrap.svelte-1rjryqp > footer > div {
20
- display: none !important;
21
- }
22
- #langdropdown {width: 100px;}
23
 
24
  """
 
13
  )
14
 
15
  css = """
 
 
 
 
 
 
 
16
 
17
  """
app/main.py CHANGED
@@ -1,97 +1,38 @@
1
- import logging
2
-
3
  import gradio as gr
4
 
5
  from app.gradio_config import css, theme
6
  from app.tabs.adv_htrflow_tab import adv_htrflow_pipeline
7
- from app.tabs.data_explorer_tab import data_explorer
8
  from app.tabs.examples_tab import examples
9
- from app.tabs.htrflow_tab import htrflow_pipeline
10
- from app.tabs.overview_tab import overview, overview_language
11
- from app.utils.lang_helper import get_tab_updates
 
 
12
  from app.utils.md_helper import load_markdown
13
 
14
- logger = logging.getLogger("gradio_log")
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(
27
- default_value="ENG", storage_key="selected_language"
28
- )
29
- main_language = gr.State(value="ENG")
30
-
31
  with gr.Column(scale=1):
32
- language_selector = gr.Dropdown(
33
- choices=LANG_CHOICES,
34
- value="ENG",
35
- container=False,
36
- min_width=50,
37
- scale=0,
38
- elem_id="langdropdown",
39
- )
40
-
41
  with gr.Column(scale=2):
42
  gr.Markdown(load_markdown(None, "main_title"))
43
  with gr.Column(scale=1):
44
  gr.Markdown(load_markdown(None, "main_sub_title"))
45
 
46
  with gr.Tabs(elem_classes="top-navbar") as navbar:
47
- with gr.Tab(label="Home") as tab_home:
48
- overview.render()
49
-
50
- with gr.Tab(label="Simple") as tab_simple_htr:
51
- htrflow_pipeline.render()
52
 
53
- with gr.Tab(label="Advanced") 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],
64
- outputs=[language_selector, main_language, overview_language],
65
- )
66
- def load_language(saved_values):
67
- return (saved_values,) * 3
68
-
69
- @language_selector.change(
70
- inputs=[language_selector],
71
- outputs=[
72
- local_language,
73
- main_language,
74
- overview_language,
75
- ],
76
- )
77
- def save_language_to_browser(selected_language):
78
- return (selected_language,) * 3
79
-
80
- @main_language.change(
81
- inputs=[main_language],
82
- outputs=[
83
- tab_home,
84
- tab_simple_htr,
85
- tab_custom_htr,
86
- ],
87
- )
88
- def update_main_tabs(selected_language):
89
- return (*get_tab_updates(selected_language, TAB_LABELS),)
90
-
91
- @main_language.change(inputs=[main_language])
92
- def log_on_language_change(selected_language):
93
- logger.info(f"Language changed to: {selected_language}")
94
-
95
 
96
  demo.queue()
97
 
 
 
 
1
  import gradio as gr
2
 
3
  from app.gradio_config import css, theme
4
  from app.tabs.adv_htrflow_tab import adv_htrflow_pipeline
 
5
  from app.tabs.examples_tab import examples
6
+ from app.tabs.templating import (
7
+ templating_block,
8
+ template_image_folder,
9
+ template_yaml_folder,
10
+ )
11
  from app.utils.md_helper import load_markdown
12
 
13
+ gr.set_static_paths(paths=[template_image_folder])
14
+ gr.set_static_paths(paths=[template_yaml_folder])
 
 
 
 
 
15
 
 
16
 
17
  with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
18
  with gr.Row():
 
 
 
 
 
19
  with gr.Column(scale=1):
20
+ pass
 
 
 
 
 
 
 
 
21
  with gr.Column(scale=2):
22
  gr.Markdown(load_markdown(None, "main_title"))
23
  with gr.Column(scale=1):
24
  gr.Markdown(load_markdown(None, "main_sub_title"))
25
 
26
  with gr.Tabs(elem_classes="top-navbar") as navbar:
27
+ with gr.Tab(label="Templating") as tab_templating:
28
+ templating_block.render()
 
 
 
29
 
30
+ with gr.Tab(label="Submit Job") as tab_submit_job:
31
  adv_htrflow_pipeline.render()
32
 
33
+ with gr.Tab(label="Output & Visualize") as tab_examples:
34
  examples.render()
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  demo.queue()
38
 
app/plot_viewer.py DELETED
@@ -1,200 +0,0 @@
1
- import xml.etree.ElementTree as ET
2
- from io import BytesIO
3
-
4
- import cv2
5
- import gradio as gr
6
- import numpy as np
7
- import requests
8
- from PIL import Image
9
-
10
-
11
- def parse_alto_xml(xml_file):
12
- """Parse the ALTO XML file to extract polygons and text content for each TextLine."""
13
- tree = ET.parse(xml_file)
14
- root = tree.getroot()
15
- ns = {"alto": "http://www.loc.gov/standards/alto/ns-v4#"}
16
-
17
- annotations = []
18
- transcriptions = {}
19
-
20
- for text_block in root.findall(".//alto:TextBlock", ns):
21
- for text_line in text_block.findall("alto:TextLine", ns):
22
- shape = text_line.find("alto:Shape", ns)
23
-
24
- if shape is not None:
25
- polygon = shape.find("alto:Polygon", ns)
26
- if polygon is not None:
27
- polygon_points = polygon.attrib["POINTS"]
28
- points = [
29
- tuple(map(int, point.split(",")))
30
- for point in polygon_points.split()
31
- ]
32
- else:
33
- hpos = int(text_line.attrib["HPOS"])
34
- vpos = int(text_line.attrib["VPOS"])
35
- width = int(text_line.attrib["WIDTH"])
36
- height = int(text_line.attrib["HEIGHT"])
37
- points = [
38
- (hpos, vpos),
39
- (hpos + width, vpos),
40
- (hpos + width, vpos + height),
41
- (hpos, vpos + height),
42
- ]
43
-
44
- content = " ".join(
45
- [
46
- string.attrib["CONTENT"]
47
- for string in text_line.findall("alto:String", ns)
48
- ]
49
- )
50
- label = text_line.attrib["ID"]
51
-
52
- annotations.append((points, label))
53
- transcriptions[label] = content
54
-
55
- text_area_content = "\n".join(transcriptions[label] for label in transcriptions)
56
-
57
- return annotations, transcriptions, text_area_content
58
-
59
-
60
- def visualize_polygons_on_image(
61
- image, annotations, alpha=0.5, include_reading_order=False
62
- ):
63
- """Visualize polygons on the image with an optional reading order overlay."""
64
- overlay = image.copy()
65
- for _, (polygon, label) in enumerate(annotations):
66
- color = (
67
- np.random.randint(0, 255),
68
- np.random.randint(0, 255),
69
- np.random.randint(0, 255),
70
- )
71
- cv2.fillPoly(overlay, [np.array(polygon, dtype=np.int32)], color)
72
-
73
- if include_reading_order:
74
- centroid = np.mean(np.array(polygon), axis=0).astype(int)
75
- cv2.putText(
76
- overlay,
77
- str(label),
78
- tuple(centroid),
79
- cv2.FONT_HERSHEY_SIMPLEX,
80
- 0.5,
81
- (0, 0, 0),
82
- 1,
83
- cv2.LINE_AA,
84
- )
85
-
86
- return cv2.addWeighted(overlay, alpha, image, 1 - alpha, 0)
87
-
88
-
89
- def visualize(
90
- xml_file, image_source, image_id, uploaded_image, include_reading_order=False
91
- ):
92
- if image_source == "Use IIIF image":
93
- if not image_id:
94
- raise gr.Error("Please enter an Image ID.")
95
- image_url = f"https://iiifintern.ra.se/arkis!{image_id}/full/max/0/default.jpg"
96
- response = requests.get(image_url)
97
- if response.status_code != 200:
98
- raise gr.Error(f"Failed to download image from {image_url}")
99
- image = np.array(Image.open(BytesIO(response.content)))
100
- else:
101
- if uploaded_image is None:
102
- raise gr.Error("Please upload an image.")
103
- image = uploaded_image
104
-
105
- annotations, transcriptions, text_area_content = parse_alto_xml(xml_file)
106
- annotated_image = visualize_polygons_on_image(
107
- image, annotations, include_reading_order=include_reading_order
108
- )
109
-
110
- return annotated_image, annotations, transcriptions, text_area_content
111
-
112
-
113
- def get_transcription_from_coords(annotations, transcriptions, evt: gr.SelectData):
114
- """Get the transcription for the polygon clicked in the annotated image."""
115
- x, y = evt.index[0], evt.index[1]
116
- for points, label in annotations:
117
- polygon = np.array(points, dtype=np.int32)
118
- if cv2.pointPolygonTest(polygon, (x, y), False) >= 0:
119
- return transcriptions.get(label, "No transcription available.")
120
- return "No transcription available."
121
-
122
-
123
- with gr.Blocks(title="XML Visualization App") as app:
124
- with gr.Tab("Visualize"):
125
- annotations_state = gr.State()
126
- transcriptions_state = gr.State()
127
-
128
- with gr.Row():
129
- with gr.Column():
130
- xml_input = gr.File(label="Upload ALTO XML File", file_types=[".xml"])
131
- with gr.Column():
132
- image_source = gr.Radio(
133
- choices=["Use IIIF image", "Upload your own image"],
134
- label="Image Source",
135
- value="Use IIIF image",
136
- )
137
- image_id_input = gr.Textbox(
138
- label="Image ID",
139
- placeholder="Enter image ID (e.g., 30003365_00001)",
140
- visible=True,
141
- )
142
- image_upload = gr.Image(
143
- label="Upload Image", type="numpy", visible=False
144
- )
145
- include_reading_order_input = gr.Checkbox(label="Include Reading Order")
146
- process_button = gr.Button("Visualize Alto", scale=0, variant="primary")
147
-
148
- def update_image_source(choice):
149
- if choice == "Use IIIF image":
150
- return [gr.update(visible=True), gr.update(visible=False)]
151
- else:
152
- return [gr.update(visible=False), gr.update(visible=True)]
153
-
154
- image_source.change(
155
- update_image_source,
156
- inputs=image_source,
157
- outputs=[image_id_input, image_upload],
158
- )
159
-
160
- with gr.Row():
161
- with gr.Column(scale=3):
162
- annotated_image_output = gr.Image(
163
- label="Annotated Image", interactive=True
164
- )
165
- with gr.Column(scale=2):
166
- transcription_output = gr.TextArea(
167
- label="Transcription",
168
- interactive=False,
169
- show_copy_button=True,
170
- lines=30,
171
- )
172
- transcription_selected = gr.Textbox(
173
- label="Selected Polygon", interactive=False, show_copy_button=True
174
- )
175
-
176
- process_button.click(
177
- visualize,
178
- inputs=[
179
- xml_input,
180
- image_source,
181
- image_id_input,
182
- image_upload,
183
- include_reading_order_input,
184
- ],
185
- outputs=[
186
- annotated_image_output,
187
- annotations_state,
188
- transcriptions_state,
189
- transcription_output,
190
- ],
191
- )
192
-
193
- annotated_image_output.select(
194
- get_transcription_from_coords,
195
- inputs=[annotations_state, transcriptions_state],
196
- outputs=transcription_selected,
197
- )
198
-
199
- app.queue()
200
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/tabs/adv_htrflow_tab.py CHANGED
@@ -1,35 +1,22 @@
1
- import time
2
-
3
  import gradio as gr
4
 
 
5
  with gr.Blocks() as adv_htrflow_pipeline:
6
  with gr.Row(variant="panel"):
7
  with gr.Column(scale=3):
8
 
9
- image_mask2 = gr.ImageEditor(
10
- label="Uploaded image",
11
- sources="upload",
12
- interactive=True,
13
- layers=False,
14
- eraser=False,
15
- brush=False,
16
- height=400,
17
- transforms="crop",
18
- crop_size="16,5",
19
- visible=False,
20
- )
21
-
22
- image_mask = gr.Gallery(
23
  file_types=["image"],
24
  label="Upload images",
25
  interactive=True,
26
- height=400,
27
  object_fit="cover",
 
28
  columns=5,
29
  )
 
30
  with gr.Row(visible=True) as yaml_pipeline:
31
  with gr.Accordion(label="Run Template", open=False):
32
- gr.Checkbox(value=True, label="Batch", container=False, scale=0)
33
  custom_template_yaml = gr.Code(
34
  value="Paste your custom pipeline here",
35
  language="yaml",
@@ -58,7 +45,11 @@ with gr.Blocks() as adv_htrflow_pipeline:
58
  info="Checkboxgroup should be basedon output structure from htrflow",
59
  )
60
 
61
- gr.Image(interactive=False)
 
 
 
 
62
 
63
  with gr.Tab("Table"):
64
  pass
@@ -67,6 +58,7 @@ with gr.Blocks() as adv_htrflow_pipeline:
67
  pass
68
 
69
  def foo():
 
70
  return gr.update(visible=True), "test"
71
 
72
  click_event = run_button.click(
@@ -79,21 +71,3 @@ with gr.Blocks() as adv_htrflow_pipeline:
79
  outputs=cancel_button,
80
  cancels=[click_event],
81
  )
82
-
83
- image_mask2.upload(
84
- fn=None,
85
- inputs=None,
86
- outputs=None,
87
- js="""
88
- () => {
89
- // Target the button using its attributes
90
- const button = document.querySelector('button[aria-label="Transform button"][title="Transform button"]');
91
- if (button) {
92
- button.click(); // Simulate a click
93
- console.log('Transform button clicked.');
94
- } else {
95
- console.error('Transform button not found.');
96
- }
97
- }
98
- """,
99
- ).then(fn=lambda: gr.update(crop=None), inputs=None, outputs=image_mask2)
 
 
 
1
  import gradio as gr
2
 
3
+
4
  with gr.Blocks() as adv_htrflow_pipeline:
5
  with gr.Row(variant="panel"):
6
  with gr.Column(scale=3):
7
 
8
+ image_batch_input = gr.Gallery(
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  file_types=["image"],
10
  label="Upload images",
11
  interactive=True,
 
12
  object_fit="cover",
13
+ preview=True,
14
  columns=5,
15
  )
16
+
17
  with gr.Row(visible=True) as yaml_pipeline:
18
  with gr.Accordion(label="Run Template", open=False):
19
+
20
  custom_template_yaml = gr.Code(
21
  value="Paste your custom pipeline here",
22
  language="yaml",
 
45
  info="Checkboxgroup should be basedon output structure from htrflow",
46
  )
47
 
48
+ gr.Image(
49
+ interactive=False,
50
+ show_fullscreen_button=True,
51
+ show_share_button=True,
52
+ )
53
 
54
  with gr.Tab("Table"):
55
  pass
 
58
  pass
59
 
60
  def foo():
61
+ gr.Info("hello morgan")
62
  return gr.update(visible=True), "test"
63
 
64
  click_event = run_button.click(
 
71
  outputs=cancel_button,
72
  cancels=[click_event],
73
  )