roygryan commited on
Commit
b257da3
·
1 Parent(s): c8e9c01

Create gradio.py

Browse files
Files changed (1) hide show
  1. gradio.py +44 -0
gradio.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def TextProcessor(txt):
4
+ # ASCII code greater than 122 will be zh
5
+ if ord(str(txt)[0]) > 122:
6
+ # convert to zh_sim
7
+ sim_text = jio.tra2sim(txt, mode='char')
8
+ zh2en_trans = pipeline("translation_zh_to_en", model = model, tokenizer = tokenizer)
9
+ results = zh2en_trans(sim_text)[0]['translation_text']
10
+ # ASCII code less than 122 will be en
11
+ else:
12
+ # if length greater than 1, sentences; otherwise, words
13
+ if len(txt.split()) < 2:
14
+ blob = TextBlob(txt)
15
+ POS_List = blob.tags
16
+ results = POS_List[0][1]
17
+ else:
18
+ # if txt contains ..., do text generation; otherwise do summary, NER, noun and verb phrases
19
+ if "..." in str(txt):
20
+ txt = str(txt)
21
+ text = txt[0:-3]
22
+ txt_generation = generator(text, max_length = 50, num_return_sequences = 1)
23
+ results = txt_generation[0]["generated_text"]
24
+ else:
25
+ txt = str(txt)
26
+ txt_summarization = summarizer(txt)
27
+ result_01 = txt_summarization[0]
28
+
29
+ result_02 = ner(txt)
30
+
31
+ blob = TextBlob(txt)
32
+ POS_List = blob.tags
33
+
34
+ noun_phrases = [np for np in POS_List if "N" in np[1][0]]
35
+ result_03 = noun_phrases
36
+
37
+ verb_phrases = [vp for vp in POS_List if "V" in vp[1][0]]
38
+ result_04 = verb_phrases
39
+ results = ("Summary:", result_01['summary_text'], "NER:", result_02, "noun_phrases:", result_03, "verb_phrases:", result_04)
40
+
41
+ return results
42
+
43
+ final = gr.Interface(fn = TextProcessor, inputs = "text", outputs = "text")
44
+ final.launch()