File size: 1,171 Bytes
d0d81c3
74216f2
d0d81c3
 
 
 
 
 
 
 
 
 
 
 
 
 
c334c88
d0d81c3
74216f2
 
 
 
0761583
d0d81c3
0761583
d0d81c3
0761583
d0d81c3
 
74216f2
 
d0d81c3
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()