Spaces:
Running
on
Zero
Running
on
Zero
carpelan
commited on
Commit
·
6baad51
1
Parent(s):
d6ff627
fixed spaces zerogpu
Browse files- README.md +6 -2
- app/assets/templates/nested_swe_ra.yaml +5 -1
- app/assets/templates/simple_eng_modern.yaml +2 -0
- app/assets/templates/simple_medival.yaml +2 -0
- app/assets/templates/simple_nordhand.yaml +2 -0
- app/assets/templates/simple_pylaia_french.yaml +0 -12
- app/assets/templates/simple_swe_ra.yaml +2 -0
- app/main.py +1 -1
- app/pipelines.py +0 -5
- app/tabs/submit.py +20 -16
- pyproject.toml +3 -3
- requirements.txt +5 -0
- uv.lock +0 -0
README.md
CHANGED
@@ -3,9 +3,13 @@ title: HTRFLOW
|
|
3 |
emoji: 🏢
|
4 |
colorFrom: purple
|
5 |
colorTo: green
|
6 |
-
sdk:
|
|
|
7 |
pinned: false
|
8 |
license: mit
|
9 |
short_description: htrflow demo app
|
10 |
header: mini
|
11 |
-
|
|
|
|
|
|
|
|
3 |
emoji: 🏢
|
4 |
colorFrom: purple
|
5 |
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
app_file: app/main.py
|
8 |
pinned: false
|
9 |
license: mit
|
10 |
short_description: htrflow demo app
|
11 |
header: mini
|
12 |
+
thumbnail: >-
|
13 |
+
https://cdn-uploads.huggingface.co/production/uploads/60a4e677917119d38f6bbff8/-qMf3PaegicobqW5hXyiA.png
|
14 |
+
sdk_version: 5.17.0
|
15 |
+
---
|
app/assets/templates/nested_swe_ra.yaml
CHANGED
@@ -4,18 +4,22 @@ steps:
|
|
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 |
generation_settings:
|
18 |
-
batch_size:
|
19 |
- step: ReadingOrderMarginalia
|
20 |
settings:
|
21 |
two_page: True
|
|
|
4 |
model: yolo
|
5 |
model_settings:
|
6 |
model: Riksarkivet/yolov9-regions-1
|
7 |
+
generation_settings:
|
8 |
+
batch_size: 4
|
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: 8
|
16 |
- step: TextRecognition
|
17 |
settings:
|
18 |
model: TrOCR
|
19 |
model_settings:
|
20 |
model: Riksarkivet/trocr-base-handwritten-hist-swe-2
|
21 |
generation_settings:
|
22 |
+
batch_size: 16
|
23 |
- step: ReadingOrderMarginalia
|
24 |
settings:
|
25 |
two_page: True
|
app/assets/templates/simple_eng_modern.yaml
CHANGED
@@ -9,4 +9,6 @@ steps:
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: microsoft/trocr-base-handwritten
|
|
|
|
|
12 |
- step: OrderLines
|
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: microsoft/trocr-base-handwritten
|
12 |
+
generation_settings:
|
13 |
+
batch_size: 16
|
14 |
- step: OrderLines
|
app/assets/templates/simple_medival.yaml
CHANGED
@@ -9,4 +9,6 @@ steps:
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: medieval-data/trocr-medieval-base
|
|
|
|
|
12 |
- step: OrderLines
|
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: medieval-data/trocr-medieval-base
|
12 |
+
generation_settings:
|
13 |
+
batch_size: 16
|
14 |
- step: OrderLines
|
app/assets/templates/simple_nordhand.yaml
CHANGED
@@ -9,4 +9,6 @@ steps:
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: Sprakbanken/TrOCR-norhand-v3
|
|
|
|
|
12 |
- step: OrderLines
|
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: Sprakbanken/TrOCR-norhand-v3
|
12 |
+
generation_settings:
|
13 |
+
batch_size: 16
|
14 |
- step: OrderLines
|
app/assets/templates/simple_pylaia_french.yaml
DELETED
@@ -1,12 +0,0 @@
|
|
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: Pylaia
|
10 |
-
model_settings:
|
11 |
-
model: Teklia/pylaia-belfort
|
12 |
-
- step: OrderLines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/assets/templates/simple_swe_ra.yaml
CHANGED
@@ -9,4 +9,6 @@ steps:
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: Riksarkivet/trocr-base-handwritten-hist-swe-2
|
|
|
|
|
12 |
- step: OrderLines
|
|
|
9 |
model: TrOCR
|
10 |
model_settings:
|
11 |
model: Riksarkivet/trocr-base-handwritten-hist-swe-2
|
12 |
+
generation_settings:
|
13 |
+
batch_size: 16
|
14 |
- step: OrderLines
|
app/main.py
CHANGED
@@ -113,5 +113,5 @@ demo.queue()
|
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
demo.launch(
|
116 |
-
server_name="0.0.0.0", server_port=7860, enable_monitoring=
|
117 |
)
|
|
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
demo.launch(
|
116 |
+
server_name="0.0.0.0", server_port=7860, enable_monitoring=False, show_api=False
|
117 |
)
|
app/pipelines.py
CHANGED
@@ -23,11 +23,6 @@ PIPELINES = {
|
|
23 |
"description": "This pipeline works well on handwritten historic letters and other documents written in Norwegian with only one text region. The model is developed by the <a href='https://huggingface.co/Sprakbanken/TrOCR-norhand-v3'>Language Bank</a> at The National Library of Norway.",
|
24 |
"examples": ["norhand_fmgh040_4.jpg"],
|
25 |
},
|
26 |
-
"French - Single page and snippets": {
|
27 |
-
"file": "app/assets/templates/simple_pylaia_french.yaml",
|
28 |
-
"description": "This pipeline works well on handwritten historic letters and other documents written in French. The model is developed by <a href='https://huggingface.co/Teklia/pylaia-belfort'>Teklia</a>.",
|
29 |
-
"examples": ["belfort_snippet.jpg"],
|
30 |
-
},
|
31 |
"Medival - Single page and snippets": {
|
32 |
"file": "app/assets/templates/simple_medival.yaml",
|
33 |
"description": "This pipeline works well for medieval scripts written in single-page running text. It is a base model from <a href='https://huggingface.co/medieval-data'>Medieval Data</a>, but other models can be selected from here: <a href='https://huggingface.co/collections/medieval-data/trocr-medieval-htr-66871faba03abfbb1b66ab69'>Medieval Models</a>.",
|
|
|
23 |
"description": "This pipeline works well on handwritten historic letters and other documents written in Norwegian with only one text region. The model is developed by the <a href='https://huggingface.co/Sprakbanken/TrOCR-norhand-v3'>Language Bank</a> at The National Library of Norway.",
|
24 |
"examples": ["norhand_fmgh040_4.jpg"],
|
25 |
},
|
|
|
|
|
|
|
|
|
|
|
26 |
"Medival - Single page and snippets": {
|
27 |
"file": "app/assets/templates/simple_medival.yaml",
|
28 |
"description": "This pipeline works well for medieval scripts written in single-page running text. It is a base model from <a href='https://huggingface.co/medieval-data'>Medieval Data</a>, but other models can be selected from here: <a href='https://huggingface.co/collections/medieval-data/trocr-medieval-htr-66871faba03abfbb1b66ab69'>Medieval Models</a>.",
|
app/tabs/submit.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
import time
|
4 |
|
5 |
import gradio as gr
|
|
|
6 |
import yaml
|
7 |
from gradio_modal import Modal
|
8 |
from htrflow.pipeline.pipeline import Pipeline
|
@@ -64,6 +65,7 @@ class PipelineWithProgress(Pipeline):
|
|
64 |
return collection
|
65 |
|
66 |
|
|
|
67 |
def run_htrflow(custom_template_yaml, batch_image_gallery, progress=gr.Progress()):
|
68 |
"""
|
69 |
Executes the HTRflow pipeline based on the provided YAML configuration and batch images.
|
@@ -105,7 +107,7 @@ def run_htrflow(custom_template_yaml, batch_image_gallery, progress=gr.Progress(
|
|
105 |
|
106 |
progress(1, desc="HTRflow: Finish, redirecting to 'Results tab'")
|
107 |
time.sleep(2)
|
108 |
-
gr.Info("
|
109 |
|
110 |
yield collection, gr.skip()
|
111 |
|
@@ -156,11 +158,24 @@ def get_selected_example_pipeline(event: gr.SelectData) -> str | None:
|
|
156 |
return name
|
157 |
|
158 |
|
159 |
-
def
|
160 |
"""
|
161 |
-
Get URL of
|
|
|
|
|
162 |
"""
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
|
166 |
with gr.Blocks() as submit:
|
@@ -279,17 +294,8 @@ with gr.Blocks() as submit:
|
|
279 |
return gr.update(value=None)
|
280 |
return images
|
281 |
|
282 |
-
def return_iiif_url(image_ids):
|
283 |
-
if isinstance(image_ids, str):
|
284 |
-
image_ids = image_ids.split(",")
|
285 |
-
|
286 |
-
return [
|
287 |
-
f"https://lbiiif.riksarkivet.se/arkis!{image_id.strip()}/full/max/0/default.jpg"
|
288 |
-
for image_id in image_ids
|
289 |
-
]
|
290 |
-
|
291 |
image_iiif_url.submit(
|
292 |
-
fn=
|
293 |
).then(fn=lambda: "Swedish - Spreads", outputs=pipeline_dropdown)
|
294 |
|
295 |
run_button.click(
|
@@ -302,5 +308,3 @@ with gr.Blocks() as submit:
|
|
302 |
examples.select(get_selected_example_pipeline, None, pipeline_dropdown)
|
303 |
|
304 |
edit_pipeline_button.click(lambda: Modal(visible=True), None, edit_pipeline_modal)
|
305 |
-
|
306 |
-
# TODO: submit on image_id .. --> yaml swedish - spreads
|
|
|
3 |
import time
|
4 |
|
5 |
import gradio as gr
|
6 |
+
import spaces
|
7 |
import yaml
|
8 |
from gradio_modal import Modal
|
9 |
from htrflow.pipeline.pipeline import Pipeline
|
|
|
65 |
return collection
|
66 |
|
67 |
|
68 |
+
@spaces.GPU
|
69 |
def run_htrflow(custom_template_yaml, batch_image_gallery, progress=gr.Progress()):
|
70 |
"""
|
71 |
Executes the HTRflow pipeline based on the provided YAML configuration and batch images.
|
|
|
107 |
|
108 |
progress(1, desc="HTRflow: Finish, redirecting to 'Results tab'")
|
109 |
time.sleep(2)
|
110 |
+
gr.Info("Completed succesfully ✨")
|
111 |
|
112 |
yield collection, gr.skip()
|
113 |
|
|
|
158 |
return name
|
159 |
|
160 |
|
161 |
+
def get_image_from_image_url(input_value):
|
162 |
"""
|
163 |
+
Get URL of the image from either an image_id (from Riksarkivet) or an image_url directly.
|
164 |
+
If input_value is an image_id, it constructs the IIIF URL.
|
165 |
+
If input_value is an image_url, it returns the URL as-is.
|
166 |
"""
|
167 |
+
|
168 |
+
if input_value.startswith("http"):
|
169 |
+
return [input_value]
|
170 |
+
else:
|
171 |
+
input_value = input_value.split(",")
|
172 |
+
|
173 |
+
return [
|
174 |
+
(
|
175 |
+
f"https://lbiiif.riksarkivet.se/arkis!{item.strip()}/full/max/0/default.jpg"
|
176 |
+
)
|
177 |
+
for item in input_value
|
178 |
+
]
|
179 |
|
180 |
|
181 |
with gr.Blocks() as submit:
|
|
|
294 |
return gr.update(value=None)
|
295 |
return images
|
296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
image_iiif_url.submit(
|
298 |
+
fn=get_image_from_image_url, inputs=image_iiif_url, outputs=batch_image_gallery
|
299 |
).then(fn=lambda: "Swedish - Spreads", outputs=pipeline_dropdown)
|
300 |
|
301 |
run_button.click(
|
|
|
308 |
examples.select(get_selected_example_pipeline, None, pipeline_dropdown)
|
309 |
|
310 |
edit_pipeline_button.click(lambda: Modal(visible=True), None, edit_pipeline_modal)
|
|
|
|
pyproject.toml
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
[project]
|
2 |
name = "htrflow-app"
|
3 |
-
version = "1.0.
|
4 |
description = "htrflow-app is developed at Riksarkivet's AI-lab as a poc frontend to showcase HTRflow"
|
5 |
readme = "README.md"
|
6 |
license = {file = "LICENSE"}
|
@@ -18,11 +18,11 @@ requires-python = ">=3.10,<3.13"
|
|
18 |
|
19 |
dependencies = [
|
20 |
"htrflow==0.2.5",
|
21 |
-
"gradio>=5.
|
22 |
"tqdm>=4.67.1",
|
23 |
"gradio-modal>=0.0.4",
|
24 |
"dill>=0.3.9",
|
25 |
-
"
|
26 |
]
|
27 |
|
28 |
[project.urls]
|
|
|
1 |
[project]
|
2 |
name = "htrflow-app"
|
3 |
+
version = "1.0.1"
|
4 |
description = "htrflow-app is developed at Riksarkivet's AI-lab as a poc frontend to showcase HTRflow"
|
5 |
readme = "README.md"
|
6 |
license = {file = "LICENSE"}
|
|
|
18 |
|
19 |
dependencies = [
|
20 |
"htrflow==0.2.5",
|
21 |
+
"gradio>=5.17.0",
|
22 |
"tqdm>=4.67.1",
|
23 |
"gradio-modal>=0.0.4",
|
24 |
"dill>=0.3.9",
|
25 |
+
"spaces>=0.32.0",
|
26 |
]
|
27 |
|
28 |
[project.urls]
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
htrflow==0.2.5
|
2 |
+
gradio>=5.17.0
|
3 |
+
tqdm>=4.67.1
|
4 |
+
gradio-modal>=0.0.4
|
5 |
+
dill>=0.3.9
|
uv.lock
CHANGED
The diff for this file is too large to render.
See raw diff
|
|