kxx-kkk commited on
Commit
6ac0564
·
verified ·
1 Parent(s): 5761cd1

Update app.py

Browse files

debugging file uploader

Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -111,7 +111,10 @@ with tab1:
111
  with tab2:
112
  # provide upload place
113
  uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt","pdf"])
114
- text = ""
 
 
 
115
 
116
  # transfer file to context and allow ask question, then perform question answering
117
  if uploaded_file is not None:
@@ -126,16 +129,16 @@ with tab2:
126
  raw_text = extract_text(temp_file.name)
127
  text = str(raw_text)
128
 
129
- question = st.text_input(label="Enter your question")
130
- context = st.text_area("Your essay context: ", value=text, height=330)
131
-
132
- # perform question answering when "get answer" button clicked
133
- button2 = st.button("Get answer", key="fileInput")
134
- if button2:
135
- if context=="" or question=="":
136
- st.error ("Please enter BOTH the context and the question", icon="🚨")
137
- else:
138
- question_answering(context, question)
139
 
140
  st.markdown("<br><br><br><br><br>", unsafe_allow_html=True)
141
 
 
111
  with tab2:
112
  # provide upload place
113
  uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt","pdf"])
114
+
115
+ # Get the initial values of context and question
116
+ context = st.session_state.get("contextInput", "")
117
+ question = st.session_state.get("questionInput", "")
118
 
119
  # transfer file to context and allow ask question, then perform question answering
120
  if uploaded_file is not None:
 
129
  raw_text = extract_text(temp_file.name)
130
  text = str(raw_text)
131
 
132
+ question = st.text_input(label="Enter your question", key="questionInput")
133
+ context = st.text_area("Your essay context: ", value=text, height=330, key="contextInput")
134
+
135
+ # perform question answering when "get answer" button clicked
136
+ button2 = st.button("Get answer", key="fileInput")
137
+ if button2:
138
+ if context=="" or question=="":
139
+ st.error ("Please enter BOTH the context and the question", icon="🚨")
140
+ else:
141
+ question_answering(context, question)
142
 
143
  st.markdown("<br><br><br><br><br>", unsafe_allow_html=True)
144