Spaces:
Paused
Paused
Commit
·
c12b0ec
1
Parent(s):
ceb42dc
Update app.
Browse files
app.py
CHANGED
@@ -360,68 +360,71 @@ def main():
|
|
360 |
|
361 |
|
362 |
if submit:
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
ents
|
412 |
-
|
413 |
-
|
414 |
-
ents=
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
|
|
|
|
|
|
425 |
|
426 |
|
427 |
# Show output
|
|
|
360 |
|
361 |
|
362 |
if submit:
|
363 |
+
if ex_s != '...':
|
364 |
+
st.warning('Please choose an example.')
|
365 |
+
else:
|
366 |
+
with st.spinner("Processing (may take a couple of minutes) ..."):
|
367 |
+
output = run_model(modes_s,user_input)
|
368 |
+
|
369 |
+
# get latest generated reasons, conclusions, argdown
|
370 |
+
argdown_raw = [out['output'] for out in output if out['mode']['to']=='argdown_reconstruction']
|
371 |
+
argdown_raw = argdown_raw[-1] if len(argdown_raw)>0 else None
|
372 |
+
reasons_raw = [out['output'] for out in output if out['mode']['to']=='reason_statements']
|
373 |
+
reasons_raw = reasons_raw[-1] if len(reasons_raw)>0 else None
|
374 |
+
concl_raw = [out['output'] for out in output if out['mode']['to']=='conclusion_statements']
|
375 |
+
concl_raw = concl_raw[-1] if len(concl_raw)>0 else None
|
376 |
+
pform_raw = [out['output'] for out in output if out['mode']['to']=='premises_formalized']
|
377 |
+
pform_raw = pform_raw[-1] if len(pform_raw)>0 else None
|
378 |
+
#pform_raw = "(x): F x -> (G x v H x) (ref: (1)) | (x): F x -> not G x (ref: (3))" # TEST
|
379 |
+
cform_raw = [out['output'] for out in output if out['mode']['to']=='conclusion_formalized']
|
380 |
+
cform_raw = cform_raw[-1] if len(cform_raw)>0 else None
|
381 |
+
#cform_raw = "(x): F x -> H x (ref: (4))" # TEST
|
382 |
+
|
383 |
+
# parse raw output
|
384 |
+
argdown_parsed = aaac.AAACParser.parse_argdown_block(argdown_raw) if argdown_raw else None
|
385 |
+
reasons_parsed = aaac.AAACParser.parse_statements(reasons_raw) if reasons_raw else None
|
386 |
+
concl_parsed = aaac.AAACParser.parse_statements(concl_raw) if concl_raw else None
|
387 |
+
pform_parsed = aaac.AAACParser.parse_formalizations(pform_raw) if pform_raw else None
|
388 |
+
cform_parsed = aaac.AAACParser.parse_formalizations(cform_raw) if cform_raw else None
|
389 |
+
|
390 |
+
|
391 |
+
# check syntactic validity
|
392 |
+
argdown_valid = (
|
393 |
+
aaac.ad_valid_syntax(argdown_parsed) &
|
394 |
+
aaac.ad_last_st_concl(argdown_parsed) &
|
395 |
+
aaac.used_prem_exist(argdown_parsed) #&
|
396 |
+
#1-aaac.prem_non_used(argdown_parsed)
|
397 |
+
) if argdown_parsed else False
|
398 |
+
reasons_valid = (
|
399 |
+
aaac.s_ord_me_subsseq(reasons_parsed,user_input['argument_source'])
|
400 |
+
) if reasons_parsed else False
|
401 |
+
concl_valid = (
|
402 |
+
aaac.s_ord_me_subsseq(concl_parsed,user_input['argument_source'])
|
403 |
+
) if concl_parsed else False
|
404 |
+
reasons_concl_mc = (
|
405 |
+
aaac.reason_concl_mutually_exclusive(reasons_parsed,concl_parsed)
|
406 |
+
) if reasons_parsed and concl_parsed else False
|
407 |
+
pform_valid = True if pform_parsed else False
|
408 |
+
cform_valid = True if cform_parsed else False
|
409 |
+
|
410 |
+
# get and merge entities and colors for displacy
|
411 |
+
ents = []
|
412 |
+
colors={}
|
413 |
+
if concl_valid:
|
414 |
+
ents,colors = get_ds_entities(user_input['argument_source'],concl_parsed,type="conclusions")
|
415 |
+
if reasons_valid and reasons_concl_mc:
|
416 |
+
ents_r,colors_r = get_ds_entities(user_input['argument_source'],reasons_parsed,type="reasons")
|
417 |
+
ents= ents+ents_r
|
418 |
+
colors.update(colors_r)
|
419 |
+
ents = sorted(ents, key=lambda item: item["start"])
|
420 |
+
elif reasons_valid:
|
421 |
+
ents,colors = get_ds_entities(user_input['argument_source'],reasons_parsed,type="reasons")
|
422 |
+
|
423 |
+
options = {"colors":colors}
|
424 |
+
ex = [{"text": user_input['argument_source'],"ents": ents,"title": None}]
|
425 |
+
displacy_html = displacy.render(ex, style="ent", options=options, manual=True)
|
426 |
+
|
427 |
+
graphviz_graph = get_inference_graph(argdown_parsed,colors) if argdown_valid else None
|
428 |
|
429 |
|
430 |
# Show output
|