Charlie Li
commited on
Commit
β’
112fcdf
1
Parent(s):
9604304
update
Browse files- app.py +87 -11
- gifs/christians.gif +0 -0
- gifs/good.gif +0 -0
- gifs/letter.gif +0 -0
- gifs/october.gif +0 -0
- gifs/welcome.gif +0 -0
- gifs/you.gif +0 -0
- sketches/bird.gif +0 -0
- sketches/cat.gif +0 -0
- sketches/coffee.gif +0 -0
- sketches/penguin.gif +0 -0
- utils.py +6 -0
app.py
CHANGED
@@ -13,10 +13,38 @@ print("Downloaded and unzipped the file.")
|
|
13 |
|
14 |
diagram = get_svg_content("derendering_supp/derender_diagram.svg")
|
15 |
org = get_svg_content("org/cor.svg")
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
def demo(Dataset, Model, Output_Format):
|
@@ -97,17 +125,28 @@ def demo(Dataset, Model, Output_Format):
|
|
97 |
with gr.Blocks() as app:
|
98 |
gr.HTML(org_content)
|
99 |
gr.Markdown(
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
"""
|
107 |
)
|
108 |
with gr.Row():
|
109 |
dataset = gr.Dropdown(
|
110 |
-
["
|
111 |
)
|
112 |
model = gr.Dropdown(
|
113 |
["Small-i", "Large-i", "Small-p"],
|
@@ -156,4 +195,41 @@ with gr.Blocks() as app:
|
|
156 |
],
|
157 |
)
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
app.launch()
|
|
|
13 |
|
14 |
diagram = get_svg_content("derendering_supp/derender_diagram.svg")
|
15 |
org = get_svg_content("org/cor.svg")
|
16 |
+
org_content = f"{org}"
|
17 |
+
|
18 |
+
gif_filenames = [
|
19 |
+
"christians.gif",
|
20 |
+
"good.gif",
|
21 |
+
"october.gif",
|
22 |
+
"welcome.gif",
|
23 |
+
"you.gif",
|
24 |
+
"letter.gif",
|
25 |
+
]
|
26 |
+
captions = [
|
27 |
+
"CHRISTIANS",
|
28 |
+
"Good",
|
29 |
+
"October",
|
30 |
+
"WELOME",
|
31 |
+
"you",
|
32 |
+
"letter",
|
33 |
+
]
|
34 |
+
gif_base64_strings = {
|
35 |
+
caption: get_base64_encoded_gif(f"gifs/{name}")
|
36 |
+
for caption, name in zip(captions, gif_filenames)
|
37 |
+
}
|
38 |
+
|
39 |
+
sketches = [
|
40 |
+
"bird.gif",
|
41 |
+
"cat.gif",
|
42 |
+
"coffee.gif",
|
43 |
+
"penguin.gif",
|
44 |
+
]
|
45 |
+
sketches_base64_strings = {
|
46 |
+
name: get_base64_encoded_gif(f"sketches/{name}") for name in sketches
|
47 |
+
}
|
48 |
|
49 |
|
50 |
def demo(Dataset, Model, Output_Format):
|
|
|
125 |
with gr.Blocks() as app:
|
126 |
gr.HTML(org_content)
|
127 |
gr.Markdown(
|
128 |
+
"# InkSight: Offline-to-Online Handwriting Conversion by Learning to Read and Write"
|
129 |
+
)
|
130 |
+
gr.HTML(
|
131 |
+
"""
|
132 |
+
<div style="display: flex; align-items: center; margin-bottom: 20px;">
|
133 |
+
<a href="https://arxiv.org/abs/2402.05804" target="_blank" style="font-size: 16px; background-color: #4CAF50; color: white; padding: 5px 7px; text-decoration: none; border-radius: 2px;">
|
134 |
+
π Read the Paper
|
135 |
+
</a>
|
136 |
+
</div>
|
137 |
+
"""
|
138 |
+
)
|
139 |
+
gr.HTML(f"<div style='margin: 20px 0;'>{diagram}</div>")
|
140 |
+
gr.Markdown(
|
141 |
+
"""
|
142 |
+
π This demo showcases the outputs of **Small-i**, **Small-p**, and **Large-i** on three public datasets (word-level, 100 samples each).<br>
|
143 |
+
βΉοΈ Choose a model variant and dataset (IAM, IMGUR5K, HierText), then click 'Sample' to see an input with its corresponding outputs for all three inference types.<br>
|
144 |
+
π Output format: Image or Image+Video. While showing only images are faster, videos can demonstrate the writing process of the inks.<br>
|
145 |
"""
|
146 |
)
|
147 |
with gr.Row():
|
148 |
dataset = gr.Dropdown(
|
149 |
+
["IAM", "IMGUR5K", "HierText"], label="Dataset", value="IAM"
|
150 |
)
|
151 |
model = gr.Dropdown(
|
152 |
["Small-i", "Large-i", "Small-p"],
|
|
|
195 |
],
|
196 |
)
|
197 |
|
198 |
+
gr.Markdown("## Additional Word-level Samples")
|
199 |
+
|
200 |
+
html_content = """
|
201 |
+
<div style="display: flex; justify-content: space-around; flex-wrap: wrap; gap: 0px;">
|
202 |
+
"""
|
203 |
+
|
204 |
+
for caption, base64_string in gif_base64_strings.items():
|
205 |
+
title = caption
|
206 |
+
html_content += f"""
|
207 |
+
<div>
|
208 |
+
<img src="data:image/gif;base64,{base64_string}" alt="{title}" style="width: 100%; max-width: 200px;">
|
209 |
+
<p style="text-align: center;">{title}</p>
|
210 |
+
</div>
|
211 |
+
"""
|
212 |
+
|
213 |
+
html_content += "</div>"
|
214 |
+
|
215 |
+
gr.HTML(html_content)
|
216 |
+
|
217 |
+
# Sketches
|
218 |
+
gr.Markdown("## Additional Sketch Samples")
|
219 |
+
|
220 |
+
html_content = """
|
221 |
+
<div style="display: flex; justify-content: space-around; flex-wrap: wrap; gap: 0px;">
|
222 |
+
"""
|
223 |
+
|
224 |
+
for _, base64_string in sketches_base64_strings.items():
|
225 |
+
html_content += f"""
|
226 |
+
<div>
|
227 |
+
<img src="data:image/gif;base64,{base64_string}" style="width: 100%; max-width: 200px;">
|
228 |
+
</div>
|
229 |
+
"""
|
230 |
+
|
231 |
+
html_content += "</div>"
|
232 |
+
|
233 |
+
gr.HTML(html_content)
|
234 |
+
|
235 |
app.launch()
|
gifs/christians.gif
ADDED
gifs/good.gif
ADDED
gifs/letter.gif
ADDED
gifs/october.gif
ADDED
gifs/welcome.gif
ADDED
gifs/you.gif
ADDED
sketches/bird.gif
ADDED
sketches/cat.gif
ADDED
sketches/coffee.gif
ADDED
sketches/penguin.gif
ADDED
utils.py
CHANGED
@@ -20,6 +20,7 @@ from io import BytesIO
|
|
20 |
from matplotlib.animation import FuncAnimation, FFMpegWriter, PillowWriter
|
21 |
import requests
|
22 |
import zipfile
|
|
|
23 |
|
24 |
|
25 |
warnings.filterwarnings("ignore")
|
@@ -41,6 +42,11 @@ def unzip_file(filename, extract_to="."):
|
|
41 |
zip_ref.extractall(extract_to)
|
42 |
|
43 |
|
|
|
|
|
|
|
|
|
|
|
44 |
def load_and_pad_img_dir(file_dir):
|
45 |
image_path = os.path.join(file_dir)
|
46 |
image = Image.open(image_path)
|
|
|
20 |
from matplotlib.animation import FuncAnimation, FFMpegWriter, PillowWriter
|
21 |
import requests
|
22 |
import zipfile
|
23 |
+
import base64
|
24 |
|
25 |
|
26 |
warnings.filterwarnings("ignore")
|
|
|
42 |
zip_ref.extractall(extract_to)
|
43 |
|
44 |
|
45 |
+
def get_base64_encoded_gif(gif_path):
|
46 |
+
with open(gif_path, "rb") as gif_file:
|
47 |
+
return base64.b64encode(gif_file.read()).decode("utf-8")
|
48 |
+
|
49 |
+
|
50 |
def load_and_pad_img_dir(file_dir):
|
51 |
image_path = os.path.join(file_dir)
|
52 |
image = Image.open(image_path)
|