Spaces:
Runtime error
Runtime error
Commit
·
c78eaed
1
Parent(s):
c28ffd1
added postprocessing to return multiple answers
Browse files
app.py
CHANGED
@@ -29,6 +29,21 @@ def choose_model():
|
|
29 |
return model_cp, model_cp
|
30 |
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
# Page config
|
33 |
title = "Recipe Improver"
|
34 |
icon = "🍣"
|
@@ -47,14 +62,17 @@ with st.expander("Upload csv file"):
|
|
47 |
uploaded_file = st.file_uploader("Choose a csv file", type="csv", key='file_uploader')
|
48 |
|
49 |
|
50 |
-
# If file is uploaded, run inference
|
51 |
if uploaded_file is not None:
|
52 |
df = load_data(uploaded_file)
|
53 |
|
54 |
# Run inference on first example
|
55 |
first_example = df['review'][0]
|
56 |
question = "How was the recipe improved?"
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
# Present results
|
60 |
st.markdown(f"""
|
@@ -64,8 +82,16 @@ if uploaded_file is not None:
|
|
64 |
|
65 |
{first_example}
|
66 |
|
67 |
-
The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
{
|
70 |
|
71 |
""")
|
|
|
29 |
return model_cp, model_cp
|
30 |
|
31 |
|
32 |
+
def postprocess(resp):
|
33 |
+
"""Function filters postprocessed model output to remove answers that
|
34 |
+
are substrings of another answer."""
|
35 |
+
answers = [answer['answer'] for answer in resp]
|
36 |
+
|
37 |
+
answers.sort(key=lambda s: len(s), reverse=True)
|
38 |
+
filtered_answers = []
|
39 |
+
for s in answers:
|
40 |
+
if not any([s in o for o in filtered_answers]):
|
41 |
+
filtered_answers.append(s)
|
42 |
+
|
43 |
+
filtered_resp = list(filter(lambda r: r['answer'] in filtered_answers, resp))
|
44 |
+
return filtered_resp
|
45 |
+
|
46 |
+
|
47 |
# Page config
|
48 |
title = "Recipe Improver"
|
49 |
icon = "🍣"
|
|
|
62 |
uploaded_file = st.file_uploader("Choose a csv file", type="csv", key='file_uploader')
|
63 |
|
64 |
|
65 |
+
# If file is uploaded, run inference - QA pipelines can't run batch ATM
|
66 |
if uploaded_file is not None:
|
67 |
df = load_data(uploaded_file)
|
68 |
|
69 |
# Run inference on first example
|
70 |
first_example = df['review'][0]
|
71 |
question = "How was the recipe improved?"
|
72 |
+
resp = question_answer(question=question,
|
73 |
+
context=first_example,
|
74 |
+
top_k=5)
|
75 |
+
filtered_resp = postprocess(resp)
|
76 |
|
77 |
# Present results
|
78 |
st.markdown(f"""
|
|
|
82 |
|
83 |
{first_example}
|
84 |
|
85 |
+
The question was:
|
86 |
+
|
87 |
+
{question}
|
88 |
+
|
89 |
+
The unfiltered answers were:
|
90 |
+
|
91 |
+
{resp}
|
92 |
+
|
93 |
+
The filtered answers were:
|
94 |
|
95 |
+
{filtered_resp}
|
96 |
|
97 |
""")
|