Spaces:
Sleeping
Sleeping
Gabriel
commited on
Commit
·
5eb89c4
1
Parent(s):
381bbf4
data explorer
Browse files- app/main.py +20 -5
- app/tabs/adv_htrflow_tab.py +46 -10
- app/tabs/data_explorer_tab.py +63 -0
- app/tabs/examples_tab.py +73 -0
- app/tabs/htrflow_tab.py +87 -107
- app/translation.yaml +0 -13
- pyproject.toml +1 -0
- todo.txt +3 -0
- translation.yaml +0 -10
- uv.lock +0 -0
app/main.py
CHANGED
@@ -1,17 +1,26 @@
|
|
|
|
|
|
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.htrflow_tab import htrflow_pipeline
|
6 |
from app.tabs.overview_tab import overview, overview_language
|
7 |
from app.utils.lang_helper import get_tab_updates
|
8 |
from app.utils.md_helper import load_markdown
|
9 |
|
|
|
|
|
|
|
10 |
TAB_LABELS = {
|
11 |
-
"ENG": ["Home", "Simple HTR", "Custom HTR"],
|
12 |
-
"SWE": ["Hem", "Enkel HTR", "Anpassad HTR"],
|
13 |
}
|
14 |
|
|
|
|
|
15 |
with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
|
16 |
with gr.Row():
|
17 |
local_language = gr.BrowserState(default_value="ENG", storage_key="selected_language")
|
@@ -19,7 +28,7 @@ with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
|
|
19 |
|
20 |
with gr.Column(scale=1):
|
21 |
language_selector = gr.Dropdown(
|
22 |
-
choices=
|
23 |
)
|
24 |
|
25 |
with gr.Column(scale=2):
|
@@ -37,6 +46,12 @@ with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
|
|
37 |
with gr.Tab(label="Custom HTR") as tab_custom_htr:
|
38 |
adv_htrflow_pipeline.render()
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@demo.load(inputs=[local_language], outputs=[language_selector, main_language, overview_language])
|
41 |
def load_language(saved_values):
|
42 |
return (saved_values,) * 3
|
@@ -64,8 +79,8 @@ with gr.Blocks(title="HTRflow", theme=theme, css=css) as demo:
|
|
64 |
return (*get_tab_updates(selected_language, TAB_LABELS),)
|
65 |
|
66 |
@main_language.change(inputs=[main_language])
|
67 |
-
def
|
68 |
-
|
69 |
|
70 |
|
71 |
demo.queue()
|
|
|
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 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(default_value="ENG", storage_key="selected_language")
|
|
|
28 |
|
29 |
with gr.Column(scale=1):
|
30 |
language_selector = gr.Dropdown(
|
31 |
+
choices=LANG_CHOICES, value="ENG", container=False, min_width=50, scale=0, elem_id="langdropdown"
|
32 |
)
|
33 |
|
34 |
with gr.Column(scale=2):
|
|
|
46 |
with gr.Tab(label="Custom HTR") as tab_custom_htr:
|
47 |
adv_htrflow_pipeline.render()
|
48 |
|
49 |
+
with gr.Tab(label="Examples") as tab_examples:
|
50 |
+
examples.render()
|
51 |
+
|
52 |
+
with gr.Tab(label="Data Explorer") as tab_data_explorer:
|
53 |
+
data_explorer.render()
|
54 |
+
|
55 |
@demo.load(inputs=[local_language], outputs=[language_selector, main_language, overview_language])
|
56 |
def load_language(saved_values):
|
57 |
return (saved_values,) * 3
|
|
|
79 |
return (*get_tab_updates(selected_language, TAB_LABELS),)
|
80 |
|
81 |
@main_language.change(inputs=[main_language])
|
82 |
+
def log_on_language_change(selected_language):
|
83 |
+
logger.info(f"Language changed to: {selected_language}")
|
84 |
|
85 |
|
86 |
demo.queue()
|
app/tabs/adv_htrflow_tab.py
CHANGED
@@ -1,27 +1,53 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
with gr.Blocks() as adv_htrflow_pipeline:
|
4 |
with gr.Row(variant="panel"):
|
5 |
with gr.Column():
|
6 |
-
gr.Markdown("<h2>Templates</h2>")
|
7 |
# TODO: We want to either crop or draw polygon or bbox and send it to the custom model. Or just as the image is.
|
8 |
# TODO: For the viewer we should be able to select from the output of the model what for values we want to
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
with gr.Group():
|
12 |
with gr.Row(visible=True) as yaml_pipeline:
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
interactive=True,
|
18 |
)
|
19 |
|
20 |
with gr.Row():
|
21 |
-
gr.Button("Submit", variant="primary", scale=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
with gr.Column():
|
24 |
-
gr.Markdown("<h2>Viewer</h2>")
|
25 |
with gr.Tabs():
|
26 |
with gr.Tab("HTR ouput"):
|
27 |
gr.CheckboxGroup(
|
@@ -30,9 +56,19 @@ with gr.Blocks() as adv_htrflow_pipeline:
|
|
30 |
)
|
31 |
|
32 |
gr.Image()
|
33 |
-
|
34 |
-
pass
|
35 |
with gr.Tab("Table"):
|
36 |
pass
|
37 |
with gr.Tab("Analysis"):
|
|
|
38 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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():
|
|
|
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 |
+
|
13 |
+
image_mask = gr.ImageMask(interactive=True)
|
14 |
|
15 |
with gr.Group():
|
16 |
with gr.Row(visible=True) as yaml_pipeline:
|
17 |
+
with gr.Accordion(label="Insert Yaml", open=False):
|
18 |
+
custom_template_yaml = gr.Code(
|
19 |
+
value="Paste your custom pipeline here",
|
20 |
+
language="yaml",
|
21 |
+
label="yaml",
|
22 |
+
interactive=True,
|
23 |
+
)
|
24 |
+
test = gr.Dropdown( # TODO: This should be a dropdown to decide input image or mask or s3 or local path
|
25 |
+
["Upload", "Draw", "s3", "local"],
|
26 |
+
value="Upload",
|
27 |
+
multiselect=False,
|
28 |
+
label="Upload method",
|
29 |
+
container=False,
|
30 |
+
scale=0,
|
31 |
interactive=True,
|
32 |
)
|
33 |
|
34 |
with gr.Row():
|
35 |
+
run_button = gr.Button("Submit", variant="primary", scale=0)
|
36 |
+
cancel_button = gr.Button(
|
37 |
+
"stop", variant="stop", scale=0
|
38 |
+
) # TODO: This should be a cancel button and be hidden until the run button is clicked
|
39 |
+
d = gr.DownloadButton(
|
40 |
+
"Download the file", visible=True, scale=0
|
41 |
+
) # TODO: This should be hidden until the run button is clicked
|
42 |
+
|
43 |
+
textbox = gr.Textbox(
|
44 |
+
scale=0
|
45 |
+
) # This is for debugging runnr when run button is clicked and the stop button is clicked
|
46 |
+
|
47 |
+
# TODO: add a upload to hf datasets
|
48 |
+
# TODO: add a hf login button to login to upload datasets
|
49 |
|
50 |
with gr.Column():
|
|
|
51 |
with gr.Tabs():
|
52 |
with gr.Tab("HTR ouput"):
|
53 |
gr.CheckboxGroup(
|
|
|
56 |
)
|
57 |
|
58 |
gr.Image()
|
59 |
+
|
|
|
60 |
with gr.Tab("Table"):
|
61 |
pass
|
62 |
with gr.Tab("Analysis"):
|
63 |
+
# TODO add https://www.gradio.app/docs/gradio/highlightedtext and graph of run graph
|
64 |
pass
|
65 |
+
|
66 |
+
test.select(lambda: gr.update(visible=True), None, image_mask)
|
67 |
+
|
68 |
+
def foo():
|
69 |
+
for i in range(300):
|
70 |
+
yield i
|
71 |
+
time.sleep(0.5)
|
72 |
+
|
73 |
+
click_event = run_button.click(fn=foo, inputs=None, outputs=textbox)
|
74 |
+
cancel_button.click(fn=None, inputs=None, outputs=None, cancels=[click_event])
|
app/tabs/data_explorer_tab.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
app/tabs/examples_tab.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_modal import Modal
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
from app.assets.examples import DemoImages
|
6 |
+
|
7 |
+
images_for_demo = DemoImages()
|
8 |
+
|
9 |
+
|
10 |
+
output_image_placehholder = gr.Image(
|
11 |
+
label="Output 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):
|
19 |
+
needs_yaml_to_forward_tohtrflow_ = """steps:
|
20 |
+
"""
|
21 |
+
print(method)
|
22 |
+
|
23 |
+
return txt, method, image
|
24 |
+
|
25 |
+
|
26 |
+
with gr.Blocks() as examples:
|
27 |
+
with gr.Row(variant="panel"):
|
28 |
+
with gr.Column():
|
29 |
+
example_text_input_placeholder = gr.Markdown(visible=False, container=False)
|
30 |
+
example_method_input_placeholder = gr.Markdown(visible=False, container=False)
|
31 |
+
example_text_output_placeholder = gr.Markdown(visible=False, container=False)
|
32 |
+
|
33 |
+
user_image_input = gr.Image(visible=False, container=False)
|
34 |
+
|
35 |
+
gr.Examples( # TODO: add so example has a alto xml file on hf datasets
|
36 |
+
fn=htr_image_placehholder,
|
37 |
+
examples=images_for_demo.examples_list,
|
38 |
+
inputs=[
|
39 |
+
example_text_input_placeholder,
|
40 |
+
example_method_input_placeholder,
|
41 |
+
user_image_input,
|
42 |
+
],
|
43 |
+
outputs=[example_text_output_placeholder, markdown_selected_option, output_image_placehholder],
|
44 |
+
cache_examples=True,
|
45 |
+
cache_mode="eager",
|
46 |
+
label="Example images",
|
47 |
+
examples_per_page=6,
|
48 |
+
)
|
49 |
+
|
50 |
+
with gr.Column():
|
51 |
+
with gr.Tabs():
|
52 |
+
with gr.Tab("Viewer"):
|
53 |
+
with gr.Group():
|
54 |
+
with gr.Row():
|
55 |
+
output_image_placehholder.render()
|
56 |
+
with gr.Row():
|
57 |
+
markdown_selected_option.render()
|
58 |
+
show_output_modal = gr.Button("Show output", variant="secondary", scale=0)
|
59 |
+
with gr.Row():
|
60 |
+
output_dataframe_pipeline = gr.Textbox(label="Click text", info="click on image bla bla..")
|
61 |
+
with gr.Tab("YAML, DF, Graph?") as htrflow_output_table_tab:
|
62 |
+
with gr.Group():
|
63 |
+
with gr.Row():
|
64 |
+
output_dataframe_pipeline = gr.Image(label="Output image", interactive=False, height="100")
|
65 |
+
with gr.Row():
|
66 |
+
output_dataframe_pipeline = gr.Dataframe(label="Output image", col_count=2)
|
67 |
+
|
68 |
+
with Modal(visible=False) as output_modal:
|
69 |
+
output_files_pipeline = gr.Files(label="Output files", height=100, visible=True, scale=0)
|
70 |
+
output_yaml_code = gr.Code(language="yaml", label="yaml", interactive=True, visible=True, scale=0)
|
71 |
+
# TODO: yaml should parse from datasets.. and show the yaml code
|
72 |
+
|
73 |
+
show_output_modal.click(lambda: Modal(visible=True), None, output_modal)
|
app/tabs/htrflow_tab.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
3 |
from jinja2 import Environment, FileSystemLoader
|
4 |
|
5 |
from app.assets.examples import DemoImages
|
@@ -37,14 +38,6 @@ def submit_button_pipeline_fn(method, input_image, yaml_str):
|
|
37 |
return f"Selected Option: {method}", input_image, serialized_files, gr.update(visible=True), df
|
38 |
|
39 |
|
40 |
-
def htr_image_placehholder(txt, method, image):
|
41 |
-
needs_yaml_to_forward_tohtrflow_ = """steps:
|
42 |
-
"""
|
43 |
-
print(method)
|
44 |
-
|
45 |
-
return txt, method, image
|
46 |
-
|
47 |
-
|
48 |
def get_yaml_button_fn(
|
49 |
method,
|
50 |
output_formats,
|
@@ -116,7 +109,7 @@ def get_yaml_button_fn(
|
|
116 |
return f"Error generating YAML: {str(e)}"
|
117 |
|
118 |
|
119 |
-
output_image_placehholder = gr.Image(label="Output image", height=
|
120 |
markdown_selected_option = gr.Markdown(container=True)
|
121 |
|
122 |
inital_state_selection_option = "Simple layout"
|
@@ -125,105 +118,84 @@ with gr.Blocks() as htrflow_pipeline:
|
|
125 |
with gr.Row(variant="panel"):
|
126 |
with gr.Column():
|
127 |
# gr.Markdown("<h2>Control Panel</h2>")
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
value="txt",
|
197 |
-
multiselect=True,
|
198 |
-
label="Serialized Output",
|
199 |
-
info="Supported format are: ...",
|
200 |
-
)
|
201 |
-
|
202 |
-
with gr.Row():
|
203 |
-
submit_button_pipeline = gr.Button("Submit", variant="primary", scale=0)
|
204 |
-
get_yaml_button = gr.Button("Get Yaml", variant="secondary", scale=0)
|
205 |
-
|
206 |
-
with gr.Tab("Examples") as examples_tab:
|
207 |
-
# TODO: Perhaps we should move examples to a seperate tab for simplicity?
|
208 |
-
gr.Examples(
|
209 |
-
fn=htr_image_placehholder,
|
210 |
-
examples=images_for_demo.examples_list,
|
211 |
-
inputs=[
|
212 |
-
example_text_input_placeholder,
|
213 |
-
example_method_input_placeholder,
|
214 |
-
user_image_input,
|
215 |
-
],
|
216 |
-
outputs=[example_text_output_placeholder, markdown_selected_option, output_image_placehholder],
|
217 |
-
cache_examples=True,
|
218 |
-
cache_mode="lazy",
|
219 |
-
label="Example images",
|
220 |
-
examples_per_page=7,
|
221 |
)
|
222 |
|
|
|
|
|
|
|
|
|
|
|
223 |
with gr.Column():
|
224 |
-
# gr.Markdown("<h2>Output Panel</h2>")
|
225 |
with gr.Tabs():
|
226 |
-
with gr.Tab("Viewer"):
|
227 |
with gr.Group():
|
228 |
with gr.Row():
|
229 |
output_image_placehholder.render()
|
@@ -238,8 +210,14 @@ with gr.Blocks() as htrflow_pipeline:
|
|
238 |
with gr.Row():
|
239 |
output_dataframe_pipeline = gr.Dataframe(label="Output image", col_count=2)
|
240 |
|
241 |
-
|
242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
submit_button_pipeline.click(
|
245 |
get_yaml_button_fn,
|
@@ -268,7 +246,7 @@ with gr.Blocks() as htrflow_pipeline:
|
|
268 |
output_files_pipeline,
|
269 |
output_dataframe_pipeline,
|
270 |
],
|
271 |
-
)
|
272 |
|
273 |
get_yaml_button.click(
|
274 |
get_yaml_button_fn,
|
@@ -294,3 +272,5 @@ with gr.Blocks() as htrflow_pipeline:
|
|
294 |
inputs=template_method_radio,
|
295 |
outputs=[simple_pipeline, nested_pipeline, table_pipeline, selected_option],
|
296 |
)
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
from gradio_modal import Modal
|
4 |
from jinja2 import Environment, FileSystemLoader
|
5 |
|
6 |
from app.assets.examples import DemoImages
|
|
|
38 |
return f"Selected Option: {method}", input_image, serialized_files, gr.update(visible=True), df
|
39 |
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def get_yaml_button_fn(
|
42 |
method,
|
43 |
output_formats,
|
|
|
109 |
return f"Error generating YAML: {str(e)}"
|
110 |
|
111 |
|
112 |
+
output_image_placehholder = gr.Image(label="Output image", height=400, show_share_button=True)
|
113 |
markdown_selected_option = gr.Markdown(container=True)
|
114 |
|
115 |
inital_state_selection_option = "Simple layout"
|
|
|
118 |
with gr.Row(variant="panel"):
|
119 |
with gr.Column():
|
120 |
# gr.Markdown("<h2>Control Panel</h2>")
|
121 |
+
|
122 |
+
with gr.Group():
|
123 |
+
example_text_input_placeholder = gr.Markdown(visible=False, container=False)
|
124 |
+
example_method_input_placeholder = gr.Markdown(visible=False, container=False)
|
125 |
+
example_text_output_placeholder = gr.Markdown(visible=False, container=False)
|
126 |
+
|
127 |
+
selected_option = gr.State(inital_state_selection_option)
|
128 |
+
dummy_none = gr.State(0)
|
129 |
+
|
130 |
+
user_image_input = gr.Image(
|
131 |
+
interactive=True, sources=["upload", "clipboard"], label="Input image", height=300
|
132 |
+
)
|
133 |
+
|
134 |
+
template_method_radio = gr.Dropdown(
|
135 |
+
[inital_state_selection_option, "Nested segmentation", "Tables"],
|
136 |
+
value=inital_state_selection_option,
|
137 |
+
label="Select template",
|
138 |
+
info="Will add more templates later!",
|
139 |
+
)
|
140 |
+
|
141 |
+
with gr.Accordion(label="Pipeline", open=False):
|
142 |
+
with gr.Row() as simple_pipeline:
|
143 |
+
with gr.Column():
|
144 |
+
with gr.Row(): # TODO: use dynamic rendering instead to make it more clean :https://www.youtube.com/watch?v=WhAMvOEOWJw&ab_channel=HuggingFace
|
145 |
+
simple_segment_model = gr.Textbox(
|
146 |
+
"model1", label="Segmentation", info="Info about the Segmentation model"
|
147 |
+
)
|
148 |
+
simple_segment_model_type = gr.Dropdown(
|
149 |
+
choices=["yolo"], value="yolo", label="Segmentation", info="Model"
|
150 |
+
)
|
151 |
+
with gr.Row():
|
152 |
+
simple_htr_model = gr.Textbox("model1", label="HTR", info="Info about the HTR model")
|
153 |
+
simple_htr_model_type = gr.Dropdown(
|
154 |
+
choices=["TrOCR"], value="TrOCR", label="HTR", info="Model"
|
155 |
+
)
|
156 |
+
|
157 |
+
with gr.Row(visible=False) as nested_pipeline:
|
158 |
+
with gr.Column():
|
159 |
+
with gr.Row():
|
160 |
+
nested_segment_model_1 = gr.Textbox(
|
161 |
+
"model1", label="Segmentation", info="Info about the Segmentation model"
|
162 |
+
)
|
163 |
+
nested_segment_model_1_type = gr.Dropdown(
|
164 |
+
choices=["yolo"], value="yolo", label="Segmentation", info="Model"
|
165 |
+
)
|
166 |
+
with gr.Row():
|
167 |
+
nested_segment_model_2 = gr.Textbox(
|
168 |
+
"model2", label="Segmentation", info="Info about the Segmentation model"
|
169 |
+
)
|
170 |
+
nested_segment_model_2_type = gr.Dropdown(
|
171 |
+
choices=["yolo"], value="yolo", label="Segmentation", info="Model"
|
172 |
+
)
|
173 |
+
with gr.Row():
|
174 |
+
nested_htr_model = gr.Textbox("model1", label="HTR", info="Info about the HTR model")
|
175 |
+
nested_htr_model_type = gr.Dropdown(
|
176 |
+
choices=["TrOCR"], value="TrOCR", label="HTR", info="Model"
|
177 |
+
)
|
178 |
+
|
179 |
+
with gr.Row(visible=False) as table_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",
|
186 |
+
multiselect=True,
|
187 |
+
label="Serialized Output",
|
188 |
+
info="Supported format are: ...",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
)
|
190 |
|
191 |
+
with gr.Row():
|
192 |
+
submit_button_pipeline = gr.Button("Submit", variant="primary", scale=0)
|
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():
|
200 |
with gr.Row():
|
201 |
output_image_placehholder.render()
|
|
|
210 |
with gr.Row():
|
211 |
output_dataframe_pipeline = gr.Dataframe(label="Output image", col_count=2)
|
212 |
|
213 |
+
with Modal(visible=False) as yaml_modal:
|
214 |
+
with gr.Row():
|
215 |
+
with gr.Column(scale=0):
|
216 |
+
gr.Markdown("")
|
217 |
+
with gr.Column(scale=4):
|
218 |
+
output_yaml_code = gr.Code(language="yaml", label="yaml", interactive=True, visible=False)
|
219 |
+
with gr.Column(scale=0):
|
220 |
+
gr.Markdown("")
|
221 |
|
222 |
submit_button_pipeline.click(
|
223 |
get_yaml_button_fn,
|
|
|
246 |
output_files_pipeline,
|
247 |
output_dataframe_pipeline,
|
248 |
],
|
249 |
+
)
|
250 |
|
251 |
get_yaml_button.click(
|
252 |
get_yaml_button_fn,
|
|
|
272 |
inputs=template_method_radio,
|
273 |
outputs=[simple_pipeline, nested_pipeline, table_pipeline, selected_option],
|
274 |
)
|
275 |
+
|
276 |
+
get_yaml_button.click(lambda: Modal(visible=True), None, yaml_modal)
|
app/translation.yaml
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
ENG:
|
2 |
-
Language: Language
|
3 |
-
Home: Home
|
4 |
-
Simple HTR: Simple HTR
|
5 |
-
Custom HTR: Custom HTR
|
6 |
-
# Other translations...
|
7 |
-
|
8 |
-
SWE:
|
9 |
-
Language: Språk
|
10 |
-
Home: Hem
|
11 |
-
Simple HTR: Enkel HTR
|
12 |
-
Custom HTR: Anpassad HTR
|
13 |
-
# Other translations...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pyproject.toml
CHANGED
@@ -23,6 +23,7 @@ dependencies = [
|
|
23 |
"datasets>=3.2.0",
|
24 |
"pandas>=2.2.3",
|
25 |
"jinja2>=3.1.4",
|
|
|
26 |
]
|
27 |
|
28 |
[project.urls]
|
|
|
23 |
"datasets>=3.2.0",
|
24 |
"pandas>=2.2.3",
|
25 |
"jinja2>=3.1.4",
|
26 |
+
"gradio-modal>=0.0.4",
|
27 |
]
|
28 |
|
29 |
[project.urls]
|
todo.txt
CHANGED
@@ -12,3 +12,6 @@ TODO: ssr mode: https://www.gradio.app/docs/gradio/blocks
|
|
12 |
TODO: enable monitoring and test api mode: https://www.gradio.app/docs/gradio/blocks
|
13 |
TODO: tes usage of modal: https://www.gradio.app/custom-components/gallery
|
14 |
TODO: new docker container.. https://huggingface.co/spaces/pngwn/gradio-docker/blob/main/Dockerfile, need cuda and uv stuff..
|
|
|
|
|
|
|
|
12 |
TODO: enable monitoring and test api mode: https://www.gradio.app/docs/gradio/blocks
|
13 |
TODO: tes usage of modal: https://www.gradio.app/custom-components/gallery
|
14 |
TODO: new docker container.. https://huggingface.co/spaces/pngwn/gradio-docker/blob/main/Dockerfile, need cuda and uv stuff..
|
15 |
+
- use https://www.gradio.app/docs/gradio/set_static_paths
|
16 |
+
- https://huggingface.co/spaces/Wauplin/space_to_dataset_saver
|
17 |
+
- https://www.freddyboulton.com/blog/gradio-logfire
|
translation.yaml
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
ENG:
|
2 |
-
Language: Language
|
3 |
-
Home: Home
|
4 |
-
Simple HTR: Simple HTR
|
5 |
-
Custom HTR: Custom HTR
|
6 |
-
SWE:
|
7 |
-
Language: Language
|
8 |
-
Home: Home
|
9 |
-
Simple HTR: Simple HTR
|
10 |
-
Custom HTR: Custom HTR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uv.lock
CHANGED
The diff for this file is too large to render.
See raw diff
|
|