cdleong commited on
Commit
aa00be2
β€’
1 Parent(s): f18f4cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -19,6 +19,8 @@ def get_lang_description_from_mapping_name(string_to_check):
19
  substrings = string_to_check.split("-")
20
  substrings = substrings[:2] # first two are ISO 639-3 language, and ISO 15924 script
21
  string_to_check = "-".join(substrings)
 
 
22
 
23
  description = None
24
  lang = langcodes.get(string_to_check)
@@ -36,7 +38,7 @@ def get_lang_description_from_mapping_name(string_to_check):
36
  description = description + " (reduced)"
37
  return description
38
 
39
- #@st.cache
40
  def get_valid_epitran_mappings_list():
41
  map_path = Path(epitran.__path__[0]) / "data" / "map"
42
  map_files = map_path.glob("*.*")
@@ -55,41 +57,36 @@ def get_valid_epitran_mappings_list():
55
 
56
  return filtered_mappings
57
 
58
- ## TODO: Fix unhashable type in return
59
- #@st.cache
60
- #def get_epitran(selected_mapping):
61
- # if selected_mapping == "cmn-Hans":
62
- ## st.info("Chinese requires a special dictionary. Downloading now")
63
- # epitran.download.cedict()
64
- #
65
- # epi = epitran.Epitran(selected_mapping)
66
- # return epi
 
 
67
 
68
  st.write("# Phonemize your text with [Epitran](https://github.com/dmort27/epitran)!")
69
 
70
  st.write("Epitran is a library and tool for transliterating orthographic text as IPA (International Phonetic Alphabet), by Mortensen, David R. and Dalmia, Siddharth and Littell, Patrick.")
71
 
72
  valid_epitran_mappings = get_valid_epitran_mappings_list()
73
-
74
- index_of_default_language = valid_epitran_mappings.index("swa-Latn")
75
-
76
  st.write(f"It supports converting many writing sytems to IPA symbols, including approximately {len(valid_epitran_mappings)} languages/scripts, listed below:")
77
 
78
  #st.write(valid_epitran_mappings)
79
 
80
- selected_mapping = st.selectbox("Select input language/script:", valid_epitran_mappings, index=index_of_default_language)
81
 
82
 
83
  description = get_lang_description_from_mapping_name(selected_mapping)
84
  st.write(f"Selected input language/script: {description}")
85
 
86
- st.info("attempting to instantiate Epitran for your language/script")
87
-
88
- if selected_mapping == "cmn-Hans":
89
- st.info("Chinese requires a special dictionary. Downloading now")
90
- epitran.download.cedict()
91
-
92
- epi = epitran.Epitran(selected_mapping)
93
 
94
  examples = defaultdict(lambda: 'Try typing some words in the language you chose, and they will be transliterated.')
95
  examples['cmn-Hans'] = 'ε€ͺεˆζœ‰ι“οΌŒι“δΈŽη₯žεŒεœ¨οΌŒι“ε°±ζ˜―η₯žγ€‚'
@@ -97,6 +94,9 @@ def get_valid_epitran_mappings_list():
97
 
98
  input_text = st.text_area(label="Whatever you type here will be transliterated!", value=examples[selected_mapping])
99
 
 
 
 
100
 
101
  st.info(f"transliterating `{input_text}`\n\tusing {selected_mapping}...")
102
  transliteration = epi.transliterate(input_text)
@@ -107,7 +107,4 @@ def get_valid_epitran_mappings_list():
107
  }
108
 
109
  st.write(output)
110
-
111
-
112
-
113
 
 
19
  substrings = string_to_check.split("-")
20
  substrings = substrings[:2] # first two are ISO 639-3 language, and ISO 15924 script
21
  string_to_check = "-".join(substrings)
22
+
23
+
24
 
25
  description = None
26
  lang = langcodes.get(string_to_check)
 
38
  description = description + " (reduced)"
39
  return description
40
 
41
+ @st.cache
42
  def get_valid_epitran_mappings_list():
43
  map_path = Path(epitran.__path__[0]) / "data" / "map"
44
  map_files = map_path.glob("*.*")
 
57
 
58
  return filtered_mappings
59
 
60
+ @st.cache
61
+ def get_epitran(selected_mapping):
62
+ if selected_mapping == "cmn-Hans":
63
+ # st.info("Chinese requires a special dictionary. Downloading now")
64
+ epitran.download.cedict()
65
+
66
+ epi = epitran.Epitran(selected_mapping)
67
+ return epi
68
+
69
+
70
+ if __name__ == "__main__":
71
 
72
  st.write("# Phonemize your text with [Epitran](https://github.com/dmort27/epitran)!")
73
 
74
  st.write("Epitran is a library and tool for transliterating orthographic text as IPA (International Phonetic Alphabet), by Mortensen, David R. and Dalmia, Siddharth and Littell, Patrick.")
75
 
76
  valid_epitran_mappings = get_valid_epitran_mappings_list()
77
+ index_of_swa_latn = valid_epitran_mappings.index("swa-Latn")
 
 
78
  st.write(f"It supports converting many writing sytems to IPA symbols, including approximately {len(valid_epitran_mappings)} languages/scripts, listed below:")
79
 
80
  #st.write(valid_epitran_mappings)
81
 
82
+ selected_mapping = st.selectbox("Select input language/script:", valid_epitran_mappings, index=index_of_swa_latn)
83
 
84
 
85
  description = get_lang_description_from_mapping_name(selected_mapping)
86
  st.write(f"Selected input language/script: {description}")
87
 
88
+ st.info("attempting to instantiate epitran transliterator for your language/script")
89
+ epi = get_epitran(str(selected_mapping))
 
 
 
 
 
90
 
91
  examples = defaultdict(lambda: 'Try typing some words in the language you chose, and they will be transliterated.')
92
  examples['cmn-Hans'] = 'ε€ͺεˆζœ‰ι“οΌŒι“δΈŽη₯žεŒεœ¨οΌŒι“ε°±ζ˜―η₯žγ€‚'
 
94
 
95
  input_text = st.text_area(label="Whatever you type here will be transliterated!", value=examples[selected_mapping])
96
 
97
+ # combined_code = "-".join([iso_lang_code, iso_script_code])
98
+ # st.write(f"Combined code: {combined_code}")
99
+
100
 
101
  st.info(f"transliterating `{input_text}`\n\tusing {selected_mapping}...")
102
  transliteration = epi.transliterate(input_text)
 
107
  }
108
 
109
  st.write(output)
 
 
 
110