Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,7 @@ from textblob import TextBlob
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
os.system("python -m textblob.download_corpora")
|
5 |
-
string_json={
|
6 |
-
'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN',
|
7 |
-
}
|
8 |
cont_list=list(string_json['control'])
|
9 |
def get_nouns(text):
|
10 |
json_object={}
|
@@ -13,14 +11,11 @@ def get_nouns(text):
|
|
13 |
noun_box=[]
|
14 |
blob = TextBlob(text)
|
15 |
for sentence in blob.sentences:
|
16 |
-
#print(sentence)
|
17 |
sen_list.append(str(sentence))
|
18 |
-
|
19 |
key_cnt=len(sen_list)
|
20 |
cnt=0
|
21 |
go=True
|
22 |
a="Z"
|
23 |
-
g="W"
|
24 |
if go:
|
25 |
for ea in range(10):
|
26 |
if go:
|
@@ -30,46 +25,32 @@ def get_nouns(text):
|
|
30 |
if go:
|
31 |
for d in range(50):
|
32 |
if go:
|
33 |
-
#for i,ea in enumerate(key_list):
|
34 |
-
#json_object[sen_list[cnt]]=f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}'
|
35 |
blob_n = TextBlob(sen_list[cnt])
|
36 |
noun_p=blob_n.noun_phrases
|
37 |
noun_box=[]
|
38 |
-
|
39 |
for ea in blob_n.parse().split(" "):
|
40 |
n=ea.split("/")
|
41 |
if n[1] == "NN":
|
42 |
noun_box.append(n[0])
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']={'sentence':sen_list[cnt],'noun_phrase':noun_p,'nouns':noun_box}
|
47 |
-
|
48 |
for noun in noun_p:
|
49 |
if noun in list(noun_list.keys()):
|
50 |
noun_list[str(noun)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
|
51 |
else:
|
52 |
noun_list[str(noun)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
|
53 |
-
|
54 |
-
|
55 |
for nn in noun_box:
|
56 |
if nn in list(noun_list.keys()):
|
57 |
noun_list[str(nn)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
|
58 |
else:
|
59 |
noun_list[str(nn)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
|
60 |
-
|
61 |
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
|
62 |
-
#if json_object[sen_list[cnt]]=='ZNNN':
|
63 |
-
#print ("Y")
|
64 |
a="Y"
|
65 |
-
g="V"
|
66 |
b=0
|
67 |
c=0
|
68 |
d=0
|
69 |
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='YNNN':
|
70 |
#print("X")
|
71 |
a="X"
|
72 |
-
g="U"
|
73 |
b=0
|
74 |
c=0
|
75 |
d=0
|
@@ -78,17 +59,7 @@ def get_nouns(text):
|
|
78 |
go=False
|
79 |
print(list(json_object.keys())[-1])
|
80 |
else:
|
81 |
-
|
82 |
cnt+=1
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
#print(blob.tags) # [('The', 'DT'), ('titular', 'JJ'),
|
87 |
-
# ('threat', 'NN'), ('of', 'IN'), ...]
|
88 |
-
#print(blob.parse())
|
89 |
-
#print(blob.noun_phrases) # WordList(['titular threat', 'blob',
|
90 |
-
# 'ultimate movie monster',
|
91 |
-
# 'amoeba-like mass', ...])
|
92 |
return json_object,noun_list
|
93 |
def find_query(query,sen,nouns):
|
94 |
blob_f = TextBlob(query)
|
@@ -98,7 +69,6 @@ def find_query(query,sen,nouns):
|
|
98 |
for ea in blob_f.parse().split(" "):
|
99 |
n=ea.split("/")
|
100 |
if n[1] == "NN":
|
101 |
-
|
102 |
noun_list.append(n[0])
|
103 |
nouns_l=list(nouns.keys())
|
104 |
for nn in nouns_l:
|
@@ -114,8 +84,6 @@ def find_query(query,sen,nouns):
|
|
114 |
for ea in noun_box.values():
|
115 |
for vals in ea:
|
116 |
sen_box.append(sen[vals]['sentence'])
|
117 |
-
|
118 |
-
|
119 |
return noun_box,sen_box
|
120 |
|
121 |
with gr.Blocks() as app:
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
os.system("python -m textblob.download_corpora")
|
5 |
+
string_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN'}
|
|
|
|
|
6 |
cont_list=list(string_json['control'])
|
7 |
def get_nouns(text):
|
8 |
json_object={}
|
|
|
11 |
noun_box=[]
|
12 |
blob = TextBlob(text)
|
13 |
for sentence in blob.sentences:
|
|
|
14 |
sen_list.append(str(sentence))
|
|
|
15 |
key_cnt=len(sen_list)
|
16 |
cnt=0
|
17 |
go=True
|
18 |
a="Z"
|
|
|
19 |
if go:
|
20 |
for ea in range(10):
|
21 |
if go:
|
|
|
25 |
if go:
|
26 |
for d in range(50):
|
27 |
if go:
|
|
|
|
|
28 |
blob_n = TextBlob(sen_list[cnt])
|
29 |
noun_p=blob_n.noun_phrases
|
30 |
noun_box=[]
|
|
|
31 |
for ea in blob_n.parse().split(" "):
|
32 |
n=ea.split("/")
|
33 |
if n[1] == "NN":
|
34 |
noun_box.append(n[0])
|
|
|
|
|
|
|
35 |
json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']={'sentence':sen_list[cnt],'noun_phrase':noun_p,'nouns':noun_box}
|
|
|
36 |
for noun in noun_p:
|
37 |
if noun in list(noun_list.keys()):
|
38 |
noun_list[str(noun)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
|
39 |
else:
|
40 |
noun_list[str(noun)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
|
|
|
|
|
41 |
for nn in noun_box:
|
42 |
if nn in list(noun_list.keys()):
|
43 |
noun_list[str(nn)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
|
44 |
else:
|
45 |
noun_list[str(nn)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
|
|
|
46 |
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
|
|
|
|
|
47 |
a="Y"
|
|
|
48 |
b=0
|
49 |
c=0
|
50 |
d=0
|
51 |
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='YNNN':
|
52 |
#print("X")
|
53 |
a="X"
|
|
|
54 |
b=0
|
55 |
c=0
|
56 |
d=0
|
|
|
59 |
go=False
|
60 |
print(list(json_object.keys())[-1])
|
61 |
else:
|
|
|
62 |
cnt+=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
return json_object,noun_list
|
64 |
def find_query(query,sen,nouns):
|
65 |
blob_f = TextBlob(query)
|
|
|
69 |
for ea in blob_f.parse().split(" "):
|
70 |
n=ea.split("/")
|
71 |
if n[1] == "NN":
|
|
|
72 |
noun_list.append(n[0])
|
73 |
nouns_l=list(nouns.keys())
|
74 |
for nn in nouns_l:
|
|
|
84 |
for ea in noun_box.values():
|
85 |
for vals in ea:
|
86 |
sen_box.append(sen[vals]['sentence'])
|
|
|
|
|
87 |
return noun_box,sen_box
|
88 |
|
89 |
with gr.Blocks() as app:
|