Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,4 @@
|
|
| 1 |
-
from textblob import TextBlob
|
| 2 |
import gradio as gr
|
| 3 |
-
import math
|
| 4 |
-
import os
|
| 5 |
-
os.system("python -m textblob.download_corpora")
|
| 6 |
-
|
| 7 |
-
def get_sen_list(text):
|
| 8 |
-
sen_list=[]
|
| 9 |
-
blob = TextBlob(text)
|
| 10 |
-
for sentence in blob.sentences:
|
| 11 |
-
sen_list.append(str(sentence))
|
| 12 |
-
return sen_list
|
| 13 |
-
|
| 14 |
-
def proc_sen(sen_list,cnt):
|
| 15 |
-
blob_n = TextBlob(sen_list[cnt])
|
| 16 |
-
noun_p=blob_n.noun_phrases
|
| 17 |
-
#print(dir(noun_p))
|
| 18 |
-
noun_box1=[]
|
| 19 |
-
for ea in blob_n.parse().split(" "):
|
| 20 |
-
n=ea.split("/")
|
| 21 |
-
if n[1] == "NN":
|
| 22 |
-
if not n[0] in noun_box1:
|
| 23 |
-
noun_box1.append(n[0])
|
| 24 |
-
json_object={'sen_num':cnt,'sentence':str(sen_list[cnt]),'noun_phrase':noun_p.copy(),'nouns':noun_box1}
|
| 25 |
-
return json_object
|
| 26 |
-
|
| 27 |
-
def proc_nouns(sen_list):
|
| 28 |
-
print("get nouns")
|
| 29 |
-
noun_list={}
|
| 30 |
-
for nn in list(sen_list.keys()):
|
| 31 |
-
try:
|
| 32 |
-
for nnn in sen_list[nn]['nouns']:
|
| 33 |
-
if nnn in list(noun_list.keys()):
|
| 34 |
-
noun_list[str(nnn)].append(nn)
|
| 35 |
-
else:
|
| 36 |
-
noun_list[str(nnn)]=[nn]
|
| 37 |
-
for nnnn in sen_list[nn]['noun_phrase']:
|
| 38 |
-
if nnnn in list(noun_list.keys()):
|
| 39 |
-
noun_list[str(nnnn)].append(nn)
|
| 40 |
-
else:
|
| 41 |
-
noun_list[str(nnnn)]=[nn]
|
| 42 |
-
except Exception as e:
|
| 43 |
-
print (e)
|
| 44 |
-
pass
|
| 45 |
-
print("done nouns")
|
| 46 |
-
return noun_list
|
| 47 |
|
| 48 |
def sort_doc(in_list: list, steps_in: int, control: int, prev_list: str):
|
| 49 |
control_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','char':'','leng':62}
|
|
@@ -163,6 +118,7 @@ with gr.Blocks() as app:
|
|
| 163 |
with gr.Row():
|
| 164 |
steps=gr.Slider(label="Steps",minimum=0,maximum=12,step=1,value=0)
|
| 165 |
control=gr.Slider(label="Control",minimum=0,maximum=32,step=1,value=0)
|
|
|
|
| 166 |
btn = gr.Button("Load Document")
|
| 167 |
with gr.Row():
|
| 168 |
query=gr.Textbox(label="Search query")
|
|
@@ -175,7 +131,7 @@ with gr.Blocks() as app:
|
|
| 175 |
with gr.Column(scale=1):
|
| 176 |
nouns=gr.JSON(label="Nouns")
|
| 177 |
search_btn.click(find_query,[query,sen,nouns],[out_box])
|
| 178 |
-
btn.click(sort_doc,[inp,steps,control],[sen])
|
| 179 |
app.launch()
|
| 180 |
|
| 181 |
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def sort_doc(in_list: list, steps_in: int, control: int, prev_list: str):
|
| 4 |
control_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','char':'','leng':62}
|
|
|
|
| 118 |
with gr.Row():
|
| 119 |
steps=gr.Slider(label="Steps",minimum=0,maximum=12,step=1,value=0)
|
| 120 |
control=gr.Slider(label="Control",minimum=0,maximum=32,step=1,value=0)
|
| 121 |
+
prev_doc=gr.File()
|
| 122 |
btn = gr.Button("Load Document")
|
| 123 |
with gr.Row():
|
| 124 |
query=gr.Textbox(label="Search query")
|
|
|
|
| 131 |
with gr.Column(scale=1):
|
| 132 |
nouns=gr.JSON(label="Nouns")
|
| 133 |
search_btn.click(find_query,[query,sen,nouns],[out_box])
|
| 134 |
+
btn.click(sort_doc,[inp,steps,control,prev_doc],[sen])
|
| 135 |
app.launch()
|
| 136 |
|
| 137 |
|