Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,82 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from collections import namedtuple
|
4 |
-
import re
|
5 |
-
import shlex
|
6 |
-
import tempfile
|
7 |
-
import subprocess
|
8 |
-
import khmercut
|
9 |
|
10 |
-
def phonemizer(text: str):
|
11 |
-
|
12 |
-
if not text:
|
13 |
-
return ""
|
14 |
-
|
15 |
-
|
16 |
-
text = text.lower()
|
17 |
-
env = phonetisaurus.guess_environment()
|
18 |
-
model_path = "./model.fst"
|
19 |
-
|
20 |
-
with tempfile.NamedTemporaryFile(suffix=".txt", mode="w+") as temp_file:
|
21 |
-
print(text, file=temp_file)
|
22 |
-
|
23 |
-
temp_file.seek(0)
|
24 |
-
|
25 |
-
phonetisaurus_cmd = [
|
26 |
-
"phonetisaurus-apply",
|
27 |
-
"--model",
|
28 |
-
shlex.quote(str(model_path)),
|
29 |
-
"--word_list",
|
30 |
-
shlex.quote(str(temp_file.name)),
|
31 |
-
"--nbest",
|
32 |
-
str(1),
|
33 |
-
]
|
34 |
-
|
35 |
-
result_str = subprocess.check_output(phonetisaurus_cmd, env=env, universal_newlines=True)
|
36 |
-
phoneme = result_str.split('\t')[1].strip()
|
37 |
-
#phoneme = re.sub(r'\s', "", phoneme)
|
38 |
-
return phoneme
|
39 |
-
|
40 |
-
|
41 |
-
def phonemizer_ipa(text: str):
|
42 |
-
|
43 |
-
if not text:
|
44 |
-
return ""
|
45 |
-
|
46 |
-
|
47 |
-
text = text.lower()
|
48 |
-
env = phonetisaurus.guess_environment()
|
49 |
-
model_path = "./model_ipa.fst"
|
50 |
-
|
51 |
-
with tempfile.NamedTemporaryFile(suffix=".txt", mode="w+") as temp_file:
|
52 |
-
print(text, file=temp_file)
|
53 |
-
|
54 |
-
temp_file.seek(0)
|
55 |
-
|
56 |
-
phonetisaurus_cmd = [
|
57 |
-
"phonetisaurus-apply",
|
58 |
-
"--model",
|
59 |
-
shlex.quote(str(model_path)),
|
60 |
-
"--word_list",
|
61 |
-
shlex.quote(str(temp_file.name)),
|
62 |
-
"--nbest",
|
63 |
-
str(1),
|
64 |
-
]
|
65 |
-
|
66 |
-
result_str = subprocess.check_output(phonetisaurus_cmd, env=env, universal_newlines=True)
|
67 |
-
phoneme = result_str.split('\t')[1].strip()
|
68 |
-
#phoneme = re.sub(r'\s', "", phoneme)
|
69 |
-
return phoneme
|
70 |
-
|
71 |
-
def processor(text: str):
|
72 |
-
tokens = khmercut.tokenize(text)
|
73 |
-
return "|".join(map(phonemizer, tokens)), "|".join(map(phonemizer_ipa, tokens))
|
74 |
-
|
75 |
iface = gr.Interface(
|
76 |
title="Khmer Phonemizer",
|
77 |
description="Convert Khmer & English into Phonetic Symbols",
|
78 |
-
fn=
|
79 |
-
outputs=["text"
|
80 |
allow_flagging="never",
|
81 |
)
|
82 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import khmerphonemizer
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
iface = gr.Interface(
|
5 |
title="Khmer Phonemizer",
|
6 |
description="Convert Khmer & English into Phonetic Symbols",
|
7 |
+
fn=khmerphonemizer.phonemize, inputs="text",
|
8 |
+
outputs=["text"],
|
9 |
allow_flagging="never",
|
10 |
)
|
11 |
|