aidan-o-brien commited on
Commit
124247d
1 Parent(s): 23e04e2

added default index

Browse files
Files changed (1) hide show
  1. app.py +37 -35
app.py CHANGED
@@ -106,38 +106,40 @@ with st.expander("Upload csv file"):
106
  if uploaded_file is not None:
107
  df = load_data(uploaded_file)
108
 
109
- # Run inference on first example
110
- user_idx = st.text_input('Enter index')
111
- first_example = df['review'][int(user_idx)]
112
- question = "How was the recipe improved?"
113
-
114
- if postprocessing == "no postprocessing":
115
- resp = question_answer(question=question,
116
- context=first_example,
117
- top_k=5)
118
- elif postprocessing == "remove substrings":
119
- resp = question_answer(question=question,
120
- context=first_example,
121
- top_k=5)
122
- resp = remove_substring(resp)
123
- elif postprocessing == "iteration":
124
- resp = remove_substring_iter(question_answer,
125
- question,
126
- first_example)
127
-
128
- # Present results
129
- st.markdown(f"""
130
- # Results
131
-
132
- The review provided was:
133
-
134
- {first_example}
135
-
136
- The question asked was:
137
-
138
- {question}
139
-
140
- The answers were:
141
-
142
- {resp}
143
- """)
 
 
106
  if uploaded_file is not None:
107
  df = load_data(uploaded_file)
108
 
109
+ # Ask user for index to try out
110
+ user_idx = st.text_input(f'Enter index (max {df.shape[0] - 1}', "0")
111
+
112
+ # Only run rest of script if user provides index
113
+ if user_idx is not None:
114
+ first_example = df['review'][int(user_idx)]
115
+ question = "How was the recipe improved?"
116
+ if postprocessing == "no postprocessing":
117
+ resp = question_answer(question=question,
118
+ context=first_example,
119
+ top_k=5)
120
+ elif postprocessing == "remove substrings":
121
+ resp = question_answer(question=question,
122
+ context=first_example,
123
+ top_k=5)
124
+ resp = remove_substring(resp)
125
+ elif postprocessing == "iteration":
126
+ resp = remove_substring_iter(question_answer,
127
+ question,
128
+ first_example)
129
+
130
+ # Present results
131
+ st.markdown(f"""
132
+ # Results
133
+
134
+ The review provided was:
135
+
136
+ {first_example}
137
+
138
+ The question asked was:
139
+
140
+ {question}
141
+
142
+ The answers were:
143
+
144
+ {resp}
145
+ """)