Spaces:
Paused
Paused
Commit
·
342b036
1
Parent(s):
28b8fc2
Update app.
Browse files
app.py
CHANGED
@@ -75,6 +75,7 @@ def params(config):
|
|
75 |
pass
|
76 |
|
77 |
|
|
|
78 |
def build_inference_api():
|
79 |
inference = InferenceApi(
|
80 |
repo_id="debatelab/argument-analyst",
|
@@ -87,7 +88,7 @@ def build_inference_api():
|
|
87 |
|
88 |
|
89 |
|
90 |
-
|
91 |
def aaac_fields():
|
92 |
fields = []
|
93 |
for m in MODES:
|
@@ -95,7 +96,7 @@ def aaac_fields():
|
|
95 |
return set(sorted(fields))
|
96 |
|
97 |
# defines how to present reason and conclusion statements to the model
|
98 |
-
|
99 |
def format_statements_list(statements: list) -> str:
|
100 |
if len(statements)==0:
|
101 |
return "None"
|
@@ -104,7 +105,7 @@ def format_statements_list(statements: list) -> str:
|
|
104 |
return list_as_string
|
105 |
|
106 |
# construct inference graph
|
107 |
-
|
108 |
def get_inference_graph(argdown_parsed,colors):
|
109 |
premise_template = """<
|
110 |
<TABLE BORDER="0" COLOR="#444444" CELLPADDING="10" CELLSPACING="2">
|
@@ -156,7 +157,7 @@ def get_inference_graph(argdown_parsed,colors):
|
|
156 |
|
157 |
|
158 |
# get entities for displacy
|
159 |
-
|
160 |
def get_ds_entities(argument_source,s_parsed,type="reasons"):
|
161 |
if type=="reasons":
|
162 |
lab_templ="P%d"
|
@@ -187,7 +188,7 @@ def get_ds_entities(argument_source,s_parsed,type="reasons"):
|
|
187 |
return ents,colors
|
188 |
|
189 |
# format raw argdown (inserting line breaks)
|
190 |
-
|
191 |
def format_argdown(raw_argdown: str, colors=None) -> str:
|
192 |
if not raw_argdown:
|
193 |
return "No argument reconstruction to display."
|
@@ -213,7 +214,7 @@ def format_argdown(raw_argdown: str, colors=None) -> str:
|
|
213 |
return argdown
|
214 |
|
215 |
# format formalization as markdown
|
216 |
-
|
217 |
def get_formalization_display(pform_parsed=None, cform_parsed=None):
|
218 |
# format premises and conclusion
|
219 |
premise_list = ['- `%s` (%d)'%(p['form'],p['ref_reco']) for p in pform_parsed]
|
@@ -261,7 +262,11 @@ def run_model(mode_set, user_input):
|
|
261 |
inquire_prompt = inquire_prompt + (f"{to_key}: {from_key}: {current_input[from_key]}")
|
262 |
# inquire model
|
263 |
inputs = inquire_prompt
|
264 |
-
out = inference(
|
|
|
|
|
|
|
|
|
265 |
out = out[0]['generated_text']
|
266 |
# cleanup formalization
|
267 |
if to_key in ['premises_formalized','conclusion_formalized']:
|
|
|
75 |
pass
|
76 |
|
77 |
|
78 |
+
@st.cache(allow_output_mutation=True)
|
79 |
def build_inference_api():
|
80 |
inference = InferenceApi(
|
81 |
repo_id="debatelab/argument-analyst",
|
|
|
88 |
|
89 |
|
90 |
|
91 |
+
@st.cache(allow_output_mutation=True)
|
92 |
def aaac_fields():
|
93 |
fields = []
|
94 |
for m in MODES:
|
|
|
96 |
return set(sorted(fields))
|
97 |
|
98 |
# defines how to present reason and conclusion statements to the model
|
99 |
+
@st.cache(allow_output_mutation=True)
|
100 |
def format_statements_list(statements: list) -> str:
|
101 |
if len(statements)==0:
|
102 |
return "None"
|
|
|
105 |
return list_as_string
|
106 |
|
107 |
# construct inference graph
|
108 |
+
@st.cache(allow_output_mutation=True)
|
109 |
def get_inference_graph(argdown_parsed,colors):
|
110 |
premise_template = """<
|
111 |
<TABLE BORDER="0" COLOR="#444444" CELLPADDING="10" CELLSPACING="2">
|
|
|
157 |
|
158 |
|
159 |
# get entities for displacy
|
160 |
+
@st.cache(allow_output_mutation=True)
|
161 |
def get_ds_entities(argument_source,s_parsed,type="reasons"):
|
162 |
if type=="reasons":
|
163 |
lab_templ="P%d"
|
|
|
188 |
return ents,colors
|
189 |
|
190 |
# format raw argdown (inserting line breaks)
|
191 |
+
@st.cache(allow_output_mutation=True)
|
192 |
def format_argdown(raw_argdown: str, colors=None) -> str:
|
193 |
if not raw_argdown:
|
194 |
return "No argument reconstruction to display."
|
|
|
214 |
return argdown
|
215 |
|
216 |
# format formalization as markdown
|
217 |
+
@st.cache(allow_output_mutation=True)
|
218 |
def get_formalization_display(pform_parsed=None, cform_parsed=None):
|
219 |
# format premises and conclusion
|
220 |
premise_list = ['- `%s` (%d)'%(p['form'],p['ref_reco']) for p in pform_parsed]
|
|
|
262 |
inquire_prompt = inquire_prompt + (f"{to_key}: {from_key}: {current_input[from_key]}")
|
263 |
# inquire model
|
264 |
inputs = inquire_prompt
|
265 |
+
out = inference(
|
266 |
+
inputs,
|
267 |
+
parameters=INFERENCE_PARAMS,
|
268 |
+
options={'use_cache':False}
|
269 |
+
)
|
270 |
out = out[0]['generated_text']
|
271 |
# cleanup formalization
|
272 |
if to_key in ['premises_formalized','conclusion_formalized']:
|