File size: 3,633 Bytes
0d3b770
 
09b648b
 
a14002e
 
 
 
0d3b770
e9b7721
 
85a22b9
0d3b770
a14002e
85a22b9
c63e932
618bce3
31ba554
a14002e
 
 
 
 
 
 
 
 
 
 
 
 
a463b89
618bce3
85a22b9
 
 
98a2e37
1dc77a9
85a22b9
1dc77a9
a463b89
 
a14002e
 
 
 
 
a463b89
a14002e
 
 
 
 
 
 
 
 
 
618bce3
a14002e
618bce3
 
a14002e
 
0d3b770
a14002e
 
0d3b770
 
deb32c3
0d3b770
 
 
2792c91
 
0d3b770
618bce3
 
0d3b770
a14002e
618bce3
0d3b770
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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()