Flavio de Oliveira
commited on
Commit
•
8235d5d
1
Parent(s):
e411600
Cosmetic changes
Browse files- app.py +27 -15
- assets/bullinger-digital.png +0 -0
- assets/bullinger_logo.png +0 -0
- assets/uzh_logo.png +0 -0
- assets/uzh_logo_mod.png +0 -0
app.py
CHANGED
@@ -109,10 +109,11 @@ def process_image(image, ground_truth):
|
|
109 |
# )
|
110 |
|
111 |
# Encode images
|
112 |
-
with open("assets/
|
113 |
logo_html = base64.b64encode(img_file.read()).decode('utf-8')
|
114 |
|
115 |
-
with open("assets/bullinger-digital.png", "rb") as img_file:
|
|
|
116 |
footer_html = base64.b64encode(img_file.read()).decode('utf-8')
|
117 |
|
118 |
# App header
|
@@ -123,7 +124,7 @@ title = """
|
|
123 |
description = """
|
124 |
Use of Microsoft's [TrOCR](https://arxiv.org/abs/2109.10282), an encoder-decoder model consisting of an \
|
125 |
image Transformer encoder and a text Transformer decoder for state-of-the-art optical character recognition \
|
126 |
-
(OCR) on
|
127 |
This particular model was fine-tuned on [Bullinger Dataset](https://github.com/pstroe/bullinger-htr) \
|
128 |
as part of the project [Bullinger Digital](https://www.bullinger-digital.ch)
|
129 |
([References](https://www.cl.uzh.ch/de/people/team/compling/pstroebel.html#Publications)).
|
@@ -142,6 +143,7 @@ examples = get_example_data()
|
|
142 |
|
143 |
# load_metric() is deprecated
|
144 |
# cer_metric = load_metric("cer")
|
|
|
145 |
# pip install evaluate
|
146 |
cer_metric = evaluate.load("cer")
|
147 |
|
@@ -152,7 +154,7 @@ with gr.Blocks(
|
|
152 |
|
153 |
gr.HTML(
|
154 |
f"""
|
155 |
-
<div style='display: flex; justify-content:
|
156 |
<img src='data:image/png;base64,{logo_html}' class='img-fluid' width='200px'>
|
157 |
</div>
|
158 |
"""
|
@@ -192,12 +194,22 @@ with gr.Blocks(
|
|
192 |
|
193 |
with gr.Row():
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
gr.HTML(
|
196 |
f"""
|
197 |
<div style="display: flex; align-items: center; justify-content: center">
|
198 |
-
<img src="data:image/png;base64,{footer_html}" style="
|
199 |
<p style="font-size: 13px">
|
200 |
-
| Institut für Computerlinguistik, Universität Zürich, 2023
|
201 |
</p>
|
202 |
</div>
|
203 |
"""
|
@@ -208,16 +220,16 @@ with gr.Blocks(
|
|
208 |
button.click(process_image, inputs=[input, ground_truth], outputs=[output, cer_output])
|
209 |
btn_clear.click(lambda: [None, "", "", ""], outputs=[input, output, ground_truth, cer_output])
|
210 |
|
211 |
-
# Try to force light mode
|
212 |
-
js = """
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
}"""
|
219 |
|
220 |
-
demo.load(_js=js)
|
221 |
|
222 |
if __name__ == "__main__":
|
223 |
|
|
|
109 |
# )
|
110 |
|
111 |
# Encode images
|
112 |
+
with open("assets/uzh_logo_mod.png", "rb") as img_file:
|
113 |
logo_html = base64.b64encode(img_file.read()).decode('utf-8')
|
114 |
|
115 |
+
# with open("assets/bullinger-digital.png", "rb") as img_file:
|
116 |
+
with open("assets/bullinger_logo.png", "rb") as img_file:
|
117 |
footer_html = base64.b64encode(img_file.read()).decode('utf-8')
|
118 |
|
119 |
# App header
|
|
|
124 |
description = """
|
125 |
Use of Microsoft's [TrOCR](https://arxiv.org/abs/2109.10282), an encoder-decoder model consisting of an \
|
126 |
image Transformer encoder and a text Transformer decoder for state-of-the-art optical character recognition \
|
127 |
+
(OCR) and handwritten text recognition (HTR) on text line images. \
|
128 |
This particular model was fine-tuned on [Bullinger Dataset](https://github.com/pstroe/bullinger-htr) \
|
129 |
as part of the project [Bullinger Digital](https://www.bullinger-digital.ch)
|
130 |
([References](https://www.cl.uzh.ch/de/people/team/compling/pstroebel.html#Publications)).
|
|
|
143 |
|
144 |
# load_metric() is deprecated
|
145 |
# cer_metric = load_metric("cer")
|
146 |
+
# pip install jiwer
|
147 |
# pip install evaluate
|
148 |
cer_metric = evaluate.load("cer")
|
149 |
|
|
|
154 |
|
155 |
gr.HTML(
|
156 |
f"""
|
157 |
+
<div style='display: flex; justify-content: right; width: 100%;'>
|
158 |
<img src='data:image/png;base64,{logo_html}' class='img-fluid' width='200px'>
|
159 |
</div>
|
160 |
"""
|
|
|
194 |
|
195 |
with gr.Row():
|
196 |
|
197 |
+
# gr.HTML(
|
198 |
+
# f"""
|
199 |
+
# <div style="display: flex; align-items: center; justify-content: center">
|
200 |
+
# <img src="data:image/png;base64,{footer_html}" style="width: 150px; height: 60px; object-fit: contain; margin-right: 5px; margin-bottom: 5px">
|
201 |
+
# <p style="font-size: 13px">
|
202 |
+
# Bullinger Digital | Institut für Computerlinguistik, Universität Zürich, 2023
|
203 |
+
# </p>
|
204 |
+
# </div>
|
205 |
+
# """
|
206 |
+
# )
|
207 |
gr.HTML(
|
208 |
f"""
|
209 |
<div style="display: flex; align-items: center; justify-content: center">
|
210 |
+
<img src="data:image/png;base64,{footer_html}" style="height: 40px; object-fit: contain; margin-right: 5px; margin-bottom: 5px">
|
211 |
<p style="font-size: 13px">
|
212 |
+
<strong>Bullinger</strong><u>Digital</u> | Institut für Computerlinguistik, Universität Zürich, 2023
|
213 |
</p>
|
214 |
</div>
|
215 |
"""
|
|
|
220 |
button.click(process_image, inputs=[input, ground_truth], outputs=[output, cer_output])
|
221 |
btn_clear.click(lambda: [None, "", "", ""], outputs=[input, output, ground_truth, cer_output])
|
222 |
|
223 |
+
# # Try to force light mode
|
224 |
+
# js = """
|
225 |
+
# function () {
|
226 |
+
# gradioURL = window.location.href
|
227 |
+
# if (!gradioURL.endsWith('?__theme=light')) {
|
228 |
+
# window.location.replace(gradioURL + '?__theme=light');
|
229 |
+
# }
|
230 |
+
# }"""
|
231 |
|
232 |
+
# demo.load(_js=js)
|
233 |
|
234 |
if __name__ == "__main__":
|
235 |
|
assets/bullinger-digital.png
DELETED
Binary file (19.7 kB)
|
|
assets/bullinger_logo.png
ADDED
assets/uzh_logo.png
DELETED
Binary file (49.9 kB)
|
|
assets/uzh_logo_mod.png
ADDED