Spaces:
Build error
Build error
freemt
commited on
Commit
·
6663376
1
Parent(s):
899f8ea
Fix gr.HTML outputs
Browse files- app.py +0 -1
- ubee/__main__.py +43 -33
app.py
CHANGED
@@ -4,4 +4,3 @@ from ubee import __main__
|
|
4 |
|
5 |
if __name__ == "__main__":
|
6 |
sys.exit(__main__.main())
|
7 |
-
|
|
|
4 |
|
5 |
if __name__ == "__main__":
|
6 |
sys.exit(__main__.main())
|
|
ubee/__main__.py
CHANGED
@@ -32,15 +32,14 @@ from icecream import ic
|
|
32 |
from icecream import install as ic_install
|
33 |
from logzero import logger
|
34 |
from set_loglevel import set_loglevel
|
35 |
-
logzero.loglevel(set_loglevel())
|
36 |
-
|
37 |
-
# for embeddable python
|
38 |
-
# if "." not in sys.path: sys.path.insert(0, ".")
|
39 |
|
40 |
from ubee import __version__
|
41 |
from ubee.ubee import ubee
|
42 |
|
43 |
-
#
|
|
|
|
|
|
|
44 |
logger.debug(" debug on ")
|
45 |
|
46 |
ic_install()
|
@@ -81,11 +80,7 @@ except Exception as _:
|
|
81 |
|
82 |
|
83 |
# segment: str
|
84 |
-
def ifn(
|
85 |
-
text1,
|
86 |
-
text2,
|
87 |
-
thresh
|
88 |
-
):
|
89 |
"""Take inputs, return outputs.
|
90 |
|
91 |
Args:
|
@@ -118,7 +113,17 @@ def ifn(
|
|
118 |
|
119 |
# return out_df, pd.DataFrame(res1_, columns=["text1", "text2", "likelihood"]), _
|
120 |
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
|
124 |
def main():
|
@@ -142,7 +147,8 @@ def main():
|
|
142 |
theme = "dark-grass"
|
143 |
theme = "grass"
|
144 |
description = """WIP showcasing a novel aligner"""
|
145 |
-
article = dedent(
|
|
|
146 |
## NB
|
147 |
|
148 |
* The ultimatumbee aligner (``ubee`` for short) is intended for aligning text blocks (be it paragraphs, sentences or words). Since it is rather slow (30 para pairs (Wuthering Height ch1. for example) can take 10 to 20 mniutes), anything more than 50 blocks should probably be avaoided. Nevertheless, you are welcome to try. No big brother is watching.
|
@@ -150,23 +156,26 @@ def main():
|
|
150 |
* ``thresh``: longer text blocks justify a larger value; `.5` appears to be just right for paragraphs for Wuthering Height ch1.
|
151 |
|
152 |
Stay tuned for more details coming soon...
|
153 |
-
"""
|
|
|
154 |
|
155 |
ex1_zh = [
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
162 |
]
|
163 |
ex1_en = [
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
"It glowed delightfully in the radiance of an immense fire, compounded of coal, peat, and wood; and near the table, laid for a plentiful evening meal, I was pleased to observe the `missis', an individual whose existence I had never previously suspected.",
|
168 |
-
|
169 |
-
|
170 |
]
|
171 |
shuffle(ex1_en)
|
172 |
ex1_zh = "\n".join(ex1_zh)
|
@@ -178,8 +187,8 @@ def main():
|
|
178 |
ex2_en = "\n".join(ex2_en)
|
179 |
|
180 |
examples = [
|
181 |
-
[ex2_zh, ex2_en, .3],
|
182 |
-
[text_zh, text_en, .5],
|
183 |
]
|
184 |
lines = 15
|
185 |
placeholder = "Type or paste text here"
|
@@ -188,14 +197,16 @@ def main():
|
|
188 |
|
189 |
with gr.Blocks() as blocks:
|
190 |
gr.Markdown(
|
191 |
-
dedent(
|
|
|
192 |
## Ultimatumbee-hf-dev {__version__}
|
193 |
|
194 |
Align non-sequential dualtexts.
|
195 |
|
196 |
可对词、句、段,每个词(或句或段)一行。可对任意语言对(英中、英德、德法、中日……等等)。建议 threshold 门槛值 -- 词: 0.3,句:0.5, 段: 0.7。如果太多 leftover,可适当调小 threshold。 如果太多误对则可以适当调大 threshold。
|
197 |
|
198 |
-
"""
|
|
|
199 |
)
|
200 |
with gr.Column():
|
201 |
with gr.Row():
|
@@ -204,7 +215,6 @@ def main():
|
|
204 |
)
|
205 |
text2 = gr.inputs.Textbox(
|
206 |
lines=lines, placeholder=placeholder, default=ex1_en, label="text2"
|
207 |
-
|
208 |
)
|
209 |
with gr.Row():
|
210 |
thresh = gr.Slider(
|
@@ -215,7 +225,7 @@ def main():
|
|
215 |
label="threshold",
|
216 |
)
|
217 |
btn = gr.Button("Run")
|
218 |
-
|
219 |
_ = """
|
220 |
out_df = gr.outputs.Dataframe(
|
221 |
headers=None,
|
@@ -226,7 +236,7 @@ def main():
|
|
226 |
label="To be aligned",
|
227 |
)
|
228 |
# """
|
229 |
-
|
230 |
with gr.Row():
|
231 |
_ = """
|
232 |
aligned = gr.Dataframe(
|
@@ -246,7 +256,7 @@ def main():
|
|
246 |
label="Leftover",
|
247 |
)
|
248 |
# """
|
249 |
-
|
250 |
aligned = gr.HTML(label="Aligned")
|
251 |
leftover = gr.HTML(label="Leftover")
|
252 |
|
@@ -261,7 +271,7 @@ def main():
|
|
261 |
# out_df,
|
262 |
aligned,
|
263 |
leftover,
|
264 |
-
]
|
265 |
)
|
266 |
|
267 |
# blocks.launch()
|
|
|
32 |
from icecream import install as ic_install
|
33 |
from logzero import logger
|
34 |
from set_loglevel import set_loglevel
|
|
|
|
|
|
|
|
|
35 |
|
36 |
from ubee import __version__
|
37 |
from ubee.ubee import ubee
|
38 |
|
39 |
+
# for embeddable python
|
40 |
+
# if "." not in sys.path: sys.path.insert(0, ".")
|
41 |
+
|
42 |
+
logzero.loglevel(set_loglevel())
|
43 |
logger.debug(" debug on ")
|
44 |
|
45 |
ic_install()
|
|
|
80 |
|
81 |
|
82 |
# segment: str
|
83 |
+
def ifn(text1, text2, thresh):
|
|
|
|
|
|
|
|
|
84 |
"""Take inputs, return outputs.
|
85 |
|
86 |
Args:
|
|
|
113 |
|
114 |
# return out_df, pd.DataFrame(res1_, columns=["text1", "text2", "likelihood"]), _
|
115 |
|
116 |
+
df = pd.DataFrame(res1_, columns=["text1", "text2", "likelihood"])
|
117 |
+
if df:
|
118 |
+
html1 = (df.to_html(),)
|
119 |
+
else:
|
120 |
+
html1 = ""
|
121 |
+
if _:
|
122 |
+
html2 = _.to_html()
|
123 |
+
else:
|
124 |
+
html2 = ""
|
125 |
+
|
126 |
+
return html1, html2
|
127 |
|
128 |
|
129 |
def main():
|
|
|
147 |
theme = "dark-grass"
|
148 |
theme = "grass"
|
149 |
description = """WIP showcasing a novel aligner"""
|
150 |
+
article = dedent(
|
151 |
+
"""
|
152 |
## NB
|
153 |
|
154 |
* The ultimatumbee aligner (``ubee`` for short) is intended for aligning text blocks (be it paragraphs, sentences or words). Since it is rather slow (30 para pairs (Wuthering Height ch1. for example) can take 10 to 20 mniutes), anything more than 50 blocks should probably be avaoided. Nevertheless, you are welcome to try. No big brother is watching.
|
|
|
156 |
* ``thresh``: longer text blocks justify a larger value; `.5` appears to be just right for paragraphs for Wuthering Height ch1.
|
157 |
|
158 |
Stay tuned for more details coming soon...
|
159 |
+
"""
|
160 |
+
).strip()
|
161 |
|
162 |
ex1_zh = [
|
163 |
+
"雪开始下大了。",
|
164 |
+
"我握住门柄又试一回。",
|
165 |
+
"这时一个没穿外衣的年轻人,扛着一根草耙,在后面院子里出现了。",
|
166 |
+
"他招呼我跟着他走,穿过了一个洗衣房和一片铺平的地,那儿有煤棚、抽水机和鸽笼,我们终于到了我上次被接待过的那间温暖的、热闹的大屋子。",
|
167 |
+
"煤、炭和木材混合在一起燃起的熊熊炉火,使这屋子放着光彩。",
|
168 |
+
"在准备摆上丰盛晚餐的桌旁,我很高兴地看到了那位“太太”,以前我从未料想到会有这么一个人存在的。",
|
169 |
+
"我鞠躬等候,以为她会叫我坐下。",
|
170 |
+
"她望望我,往她的椅背一靠,不动,也不出声。",
|
171 |
]
|
172 |
ex1_en = [
|
173 |
+
"The snow began to drive thickly.",
|
174 |
+
"I seized the handle to essay another trial; when a young man without coat, and shouldering a pitchfork, appeared in the yard behind.",
|
175 |
+
"He hailed me to follow him, and, after marching through a wash-house, and a paved area containing a coal shed, pump, and pigeon cot, we at length arrived in the huge, warm, cheerful apartment, where I was formerly received.",
|
176 |
"It glowed delightfully in the radiance of an immense fire, compounded of coal, peat, and wood; and near the table, laid for a plentiful evening meal, I was pleased to observe the `missis', an individual whose existence I had never previously suspected.",
|
177 |
+
"I bowed and waited, thinking she would bid me take a seat.",
|
178 |
+
"She looked at me, leaning back in her chair, and remained motionless and mute.",
|
179 |
]
|
180 |
shuffle(ex1_en)
|
181 |
ex1_zh = "\n".join(ex1_zh)
|
|
|
187 |
ex2_en = "\n".join(ex2_en)
|
188 |
|
189 |
examples = [
|
190 |
+
[ex2_zh, ex2_en, 0.3],
|
191 |
+
[text_zh, text_en, 0.5],
|
192 |
]
|
193 |
lines = 15
|
194 |
placeholder = "Type or paste text here"
|
|
|
197 |
|
198 |
with gr.Blocks() as blocks:
|
199 |
gr.Markdown(
|
200 |
+
dedent(
|
201 |
+
f"""
|
202 |
## Ultimatumbee-hf-dev {__version__}
|
203 |
|
204 |
Align non-sequential dualtexts.
|
205 |
|
206 |
可对词、句、段,每个词(或句或段)一行。可对任意语言对(英中、英德、德法、中日……等等)。建议 threshold 门槛值 -- 词: 0.3,句:0.5, 段: 0.7。如果太多 leftover,可适当调小 threshold。 如果太多误对则可以适当调大 threshold。
|
207 |
|
208 |
+
"""
|
209 |
+
).strip()
|
210 |
)
|
211 |
with gr.Column():
|
212 |
with gr.Row():
|
|
|
215 |
)
|
216 |
text2 = gr.inputs.Textbox(
|
217 |
lines=lines, placeholder=placeholder, default=ex1_en, label="text2"
|
|
|
218 |
)
|
219 |
with gr.Row():
|
220 |
thresh = gr.Slider(
|
|
|
225 |
label="threshold",
|
226 |
)
|
227 |
btn = gr.Button("Run")
|
228 |
+
|
229 |
_ = """
|
230 |
out_df = gr.outputs.Dataframe(
|
231 |
headers=None,
|
|
|
236 |
label="To be aligned",
|
237 |
)
|
238 |
# """
|
239 |
+
|
240 |
with gr.Row():
|
241 |
_ = """
|
242 |
aligned = gr.Dataframe(
|
|
|
256 |
label="Leftover",
|
257 |
)
|
258 |
# """
|
259 |
+
|
260 |
aligned = gr.HTML(label="Aligned")
|
261 |
leftover = gr.HTML(label="Leftover")
|
262 |
|
|
|
271 |
# out_df,
|
272 |
aligned,
|
273 |
leftover,
|
274 |
+
],
|
275 |
)
|
276 |
|
277 |
# blocks.launch()
|