Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from pythainlp.tokenize import word_tokenize | |
| thai_consonants = "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮ" # 44 chars | |
| thai_vowels = ( | |
| "\u0e24\u0e26\u0e30\u0e31\u0e32\u0e33\u0e34\u0e35\u0e36\u0e37" | |
| + "\u0e38\u0e39\u0e40\u0e41\u0e42\u0e43\u0e44\u0e45\u0e4d\u0e47" | |
| ) # 20 | |
| thai_lead_vowels = "\u0e40\u0e41\u0e42\u0e43\u0e44" # 5 | |
| thai_follow_vowels = "\u0e30\u0e32\u0e33\u0e45" # 4 | |
| thai_above_vowels = "\u0e31\u0e34\u0e35\u0e36\u0e37\u0e4d\u0e47" # 7 | |
| thai_below_vowels = "\u0e38\u0e39" # 2 | |
| thai_tonemarks = "\u0e48\u0e49\u0e4a\u0e4b" # 4 | |
| all_thai = list(thai_consonants + thai_vowels + thai_tonemarks) | |
| def count_words(text): | |
| return len(word_tokenize(text)) | |
| def greet(text): | |
| _temp = [] | |
| _n = count_words(text) | |
| for i in all_thai: | |
| if i not in text: | |
| _temp.append(i) | |
| if len(_temp)>0: | |
| return "Not complete: "+" ".join(_temp)+"\n\nNumber: "+str(_n)+" words" | |
| return "Complete!!! :D"+"\n\nNumber: "+str(_n)+" words" | |
| demo = gr.Interface(fn=greet, inputs="text", outputs="text",live=True) | |
| demo.launch() |