ShynBui commited on
Commit
266419e
·
verified ·
1 Parent(s): b76bcf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -3
app.py CHANGED
@@ -1,7 +1,50 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ from pyvi import ViTokenizer, ViPosTagger
4
 
5
+ pos_mapping = {
6
+ "A": ("Adjective", "Tính từ"),
7
+ "C": ("Coordinating conjunction", "Liên từ kết hợp"),
8
+ "E": ("Preposition", "Giới từ"),
9
+ "I": ("Interjection", "Thán từ"),
10
+ "L": ("Determiner", "Hạn định từ"),
11
+ "M": ("Numeral", "Số từ"),
12
+ "N": ("Common noun", "Danh từ chung"),
13
+ "Nc": ("Noun Classifier", "Lượng từ"),
14
+ "Ny": ("Noun abbreviation", "Từ viết tắt danh từ"),
15
+ "Np": ("Proper noun", "Danh từ riêng"),
16
+ "Nu": ("Unit noun", "Danh từ đơn vị"),
17
+ "P": ("Pronoun", "Đại từ"),
18
+ "R": ("Adverb", "Trạng từ"),
19
+ "S": ("Subordinating conjunction", "Liên từ phụ thuộc"),
20
+ "T": ("Auxiliary, modal words", "Trợ từ, động từ tình thái"),
21
+ "V": ("Verb", "Động từ"),
22
+ "X": ("Unknown", "Không xác định"),
23
+ "F": ("Filtered out (punctuation)", "Bị loại bỏ (dấu câu)")
24
+ }
25
 
26
+ def change(sentence):
27
+ resutlt = ViPosTagger.postagging(ViTokenizer.tokenize(sentence))
28
+ print(resutlt)
29
+ words, pos_tags = resutlt
30
+ pos_tags_engs = []
31
+ pos_tags_vies = []
32
+ for i in pos_tags:
33
+ print(pos_mapping[i][0])
34
+ print(pos_mapping[i][1])
35
+ pos_tags_engs.append(pos_mapping[i][0])
36
+ pos_tags_vies.append(pos_mapping[i][1])
37
+ # final_result = ''''''
38
+ # for word, pos_tag, pos_tags_eng, pos_tags_vie in zip(words, pos_tags, pos_tags_engs, pos_tags_vies):
39
+ # final_result += f"Từ: {word}, Loại từ: {pos_tag} ({pos_tags_eng} - {pos_tags_vie})\n"
40
+ # return final_result
41
+
42
+ header = f"{'Từ':<15} {'Loại từ':<10} {'English POS':<20} {'Tiếng Việt POS'}\n"
43
+ header += "-" * 60 + "\n"
44
+ rows = [f"{word:<15} {pos_tag:<10} {pos_tags_eng:<20} {pos_tags_vie}"
45
+ for word, pos_tag, pos_tags_eng, pos_tags_vie in zip(words, pos_tags, pos_tags_engs, pos_tags_vies)]
46
+ final_result = header + "\n".join(rows)
47
+ return final_result
48
+
49
+ demo = gr.Interface(fn=change, inputs="text", outputs="text")
50
  demo.launch()