Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,12 @@ cont_list=list(string_json['control'])
|
|
| 9 |
def get_nouns(text):
|
| 10 |
json_object={}
|
| 11 |
sen_list=[]
|
|
|
|
| 12 |
blob = TextBlob(text)
|
| 13 |
for sentence in blob.sentences:
|
| 14 |
print(sentence)
|
| 15 |
sen_list.append(str(sentence))
|
|
|
|
| 16 |
key_cnt=len(sen_list)
|
| 17 |
cnt=0
|
| 18 |
go=True
|
|
@@ -28,7 +30,8 @@ def get_nouns(text):
|
|
| 28 |
if go:
|
| 29 |
#for i,ea in enumerate(key_list):
|
| 30 |
#json_object[sen_list[cnt]]=f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}'
|
| 31 |
-
|
|
|
|
| 32 |
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
|
| 33 |
#if json_object[sen_list[cnt]]=='ZNNN':
|
| 34 |
#print ("Y")
|
|
@@ -42,13 +45,15 @@ def get_nouns(text):
|
|
| 42 |
b=0
|
| 43 |
c=0
|
| 44 |
d=0
|
| 45 |
-
#print(cnt)
|
| 46 |
if cnt == key_cnt-1:
|
| 47 |
print('done')
|
| 48 |
go=False
|
| 49 |
print(list(json_object.keys())[-1])
|
| 50 |
else:
|
|
|
|
| 51 |
cnt+=1
|
|
|
|
|
|
|
| 52 |
|
| 53 |
#print(blob.tags) # [('The', 'DT'), ('titular', 'JJ'),
|
| 54 |
# ('threat', 'NN'), ('of', 'IN'), ...]
|
|
@@ -60,12 +65,13 @@ def get_nouns(text):
|
|
| 60 |
|
| 61 |
|
| 62 |
with gr.Blocks() as app:
|
|
|
|
|
|
|
| 63 |
with gr.Row():
|
| 64 |
-
with gr.Column(scale=
|
| 65 |
-
|
| 66 |
-
btn = gr.Button()
|
| 67 |
with gr.Column(scale=1):
|
| 68 |
nouns=gr.JSON(label="Nouns")
|
| 69 |
-
btn.click(get_nouns,inp,nouns)
|
| 70 |
app.launch()
|
| 71 |
|
|
|
|
| 9 |
def get_nouns(text):
|
| 10 |
json_object={}
|
| 11 |
sen_list=[]
|
| 12 |
+
noun_list=[]
|
| 13 |
blob = TextBlob(text)
|
| 14 |
for sentence in blob.sentences:
|
| 15 |
print(sentence)
|
| 16 |
sen_list.append(str(sentence))
|
| 17 |
+
|
| 18 |
key_cnt=len(sen_list)
|
| 19 |
cnt=0
|
| 20 |
go=True
|
|
|
|
| 30 |
if go:
|
| 31 |
#for i,ea in enumerate(key_list):
|
| 32 |
#json_object[sen_list[cnt]]=f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}'
|
| 33 |
+
blob_n = TextBlob(sen_list[cnt])
|
| 34 |
+
json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']={'sentence':sen_list[cnt],'nouns':blob_n.noun_phrases}
|
| 35 |
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
|
| 36 |
#if json_object[sen_list[cnt]]=='ZNNN':
|
| 37 |
#print ("Y")
|
|
|
|
| 45 |
b=0
|
| 46 |
c=0
|
| 47 |
d=0
|
|
|
|
| 48 |
if cnt == key_cnt-1:
|
| 49 |
print('done')
|
| 50 |
go=False
|
| 51 |
print(list(json_object.keys())[-1])
|
| 52 |
else:
|
| 53 |
+
|
| 54 |
cnt+=1
|
| 55 |
+
|
| 56 |
+
|
| 57 |
|
| 58 |
#print(blob.tags) # [('The', 'DT'), ('titular', 'JJ'),
|
| 59 |
# ('threat', 'NN'), ('of', 'IN'), ...]
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
with gr.Blocks() as app:
|
| 68 |
+
inp = gr.Textbox(lines=10)
|
| 69 |
+
btn = gr.Button()
|
| 70 |
with gr.Row():
|
| 71 |
+
with gr.Column(scale=2):
|
| 72 |
+
sen=gr.JSON(label="Sentences")
|
|
|
|
| 73 |
with gr.Column(scale=1):
|
| 74 |
nouns=gr.JSON(label="Nouns")
|
| 75 |
+
btn.click(get_nouns,inp,[sen,nouns])
|
| 76 |
app.launch()
|
| 77 |
|