Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -190,12 +190,42 @@ def find_query(query,sen,nouns):
|
|
| 190 |
sen_box.append({'sen_num':sen[vals]['sen_num'],'sentence':sen[vals]['sentence']})
|
| 191 |
return noun_box,sen_box
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
with gr.Blocks() as app:
|
| 194 |
inp = gr.Textbox(label="Paste Text",lines=10)
|
| 195 |
btn = gr.Button("Load Document")
|
| 196 |
with gr.Row():
|
| 197 |
query=gr.Textbox(label="Search query")
|
| 198 |
search_btn=gr.Button("Search")
|
|
|
|
| 199 |
out_box=gr.Textbox(label="Results")
|
| 200 |
sen_box=gr.JSON(label="Sentences")
|
| 201 |
with gr.Row():
|
|
@@ -204,6 +234,7 @@ with gr.Blocks() as app:
|
|
| 204 |
with gr.Column(scale=1):
|
| 205 |
nouns=gr.JSON(label="Nouns")
|
| 206 |
search_btn.click(find_query,[query,sen,nouns],[out_box,sen_box])
|
|
|
|
| 207 |
btn.click(sort_doc,[inp],[sen,nouns])
|
| 208 |
app.launch()
|
| 209 |
|
|
|
|
| 190 |
sen_box.append({'sen_num':sen[vals]['sen_num'],'sentence':sen[vals]['sentence']})
|
| 191 |
return noun_box,sen_box
|
| 192 |
|
| 193 |
+
def find_query_sen(query,sen,nouns):
|
| 194 |
+
blob_f = TextBlob(query)
|
| 195 |
+
noun_box={}
|
| 196 |
+
noun_list=[]
|
| 197 |
+
sen_box=[]
|
| 198 |
+
for ea in blob_f.parse().split(" "):
|
| 199 |
+
n=ea.split("/")
|
| 200 |
+
if n[1] == "NN":
|
| 201 |
+
noun_list.append(n[0])
|
| 202 |
+
nouns_l=list(nouns.keys())
|
| 203 |
+
for nn in nouns_l:
|
| 204 |
+
for nl in noun_list:
|
| 205 |
+
if nl in nn:
|
| 206 |
+
if nl in noun_box:
|
| 207 |
+
for ea_n in nouns[nn]:
|
| 208 |
+
noun_box[str(nl)].append(ea_n)
|
| 209 |
+
else:
|
| 210 |
+
noun_box[str(nl)]=[]
|
| 211 |
+
for ea_n in nouns[nn]:
|
| 212 |
+
noun_box[str(nl)].append(ea_n)
|
| 213 |
+
sen_out=""
|
| 214 |
+
for ea in noun_box.values():
|
| 215 |
+
for vals in ea:
|
| 216 |
+
sen_out+=f'{sen[vals]['sentence']}\n'
|
| 217 |
+
|
| 218 |
+
#sen_box.append({'sen_num':sen[vals]['sen_num'],'sentence':sen[vals]['sentence']})
|
| 219 |
+
return sen_out
|
| 220 |
+
|
| 221 |
+
|
| 222 |
with gr.Blocks() as app:
|
| 223 |
inp = gr.Textbox(label="Paste Text",lines=10)
|
| 224 |
btn = gr.Button("Load Document")
|
| 225 |
with gr.Row():
|
| 226 |
query=gr.Textbox(label="Search query")
|
| 227 |
search_btn=gr.Button("Search")
|
| 228 |
+
search_btn2=gr.Button("Search2")
|
| 229 |
out_box=gr.Textbox(label="Results")
|
| 230 |
sen_box=gr.JSON(label="Sentences")
|
| 231 |
with gr.Row():
|
|
|
|
| 234 |
with gr.Column(scale=1):
|
| 235 |
nouns=gr.JSON(label="Nouns")
|
| 236 |
search_btn.click(find_query,[query,sen,nouns],[out_box,sen_box])
|
| 237 |
+
search_btn2.click(find_query_sen,[query,sen,nouns],[out_box])
|
| 238 |
btn.click(sort_doc,[inp],[sen,nouns])
|
| 239 |
app.launch()
|
| 240 |
|