sort_document / app.py
Omnibus's picture
Update app.py
1dc77a9 verified
raw
history blame
3.63 kB
from textblob import TextBlob
import gradio as gr
import os
os.system("python -m textblob.download_corpora")
string_json={
'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN',
}
cont_list=list(string_json['control'])
def get_nouns(text):
json_object={}
sen_list=[]
noun_list={}
blob = TextBlob(text)
for sentence in blob.sentences:
#print(sentence)
sen_list.append(str(sentence))
key_cnt=len(sen_list)
cnt=0
go=True
a="Z"
if go:
for ea in range(10):
if go:
for b in range(50):
if go:
for c in range(50):
if go:
for d in range(50):
if go:
#for i,ea in enumerate(key_list):
#json_object[sen_list[cnt]]=f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}'
blob_n = TextBlob(sen_list[cnt])
noun_p=blob_n.noun_phrases
json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']={'sentence':sen_list[cnt],'nouns':noun_p}
for noun in noun_p:
if noun in list(noun_list.keys()):
noun_list[str(noun)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
else:
noun_list[str(noun)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
#if json_object[sen_list[cnt]]=='ZNNN':
#print ("Y")
a="Y"
b=0
c=0
d=0
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='YNNN':
#print("X")
a="X"
b=0
c=0
d=0
if cnt == key_cnt-1:
print('done')
go=False
print(list(json_object.keys())[-1])
else:
cnt+=1
#print(blob.tags) # [('The', 'DT'), ('titular', 'JJ'),
# ('threat', 'NN'), ('of', 'IN'), ...]
#print(blob.parse())
#print(blob.noun_phrases) # WordList(['titular threat', 'blob',
# 'ultimate movie monster',
# 'amoeba-like mass', ...])
return json_object,noun_list
with gr.Blocks() as app:
inp = gr.Textbox(lines=10)
btn = gr.Button()
with gr.Row():
with gr.Column(scale=2):
sen=gr.JSON(label="Sentences")
with gr.Column(scale=1):
nouns=gr.JSON(label="Nouns")
btn.click(get_nouns,inp,[sen,nouns])
app.launch()