Update app.py
Browse files
app.py
CHANGED
@@ -171,13 +171,28 @@ def generate_response(query, model, template):
|
|
171 |
logger.info(f"Total Execution Time: {time.time() - start_time}")
|
172 |
|
173 |
my_bar.progress(0.9, "Post Processing. Please wait.")
|
174 |
-
|
|
|
175 |
my_bar.progress(1.0, "Done")
|
176 |
time.sleep(1)
|
177 |
my_bar.empty()
|
178 |
return response
|
179 |
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
# show background image
|
182 |
def convert_to_base64(bin_file):
|
183 |
with open(bin_file, 'rb') as f:
|
@@ -201,21 +216,7 @@ def set_as_background_img(png_file):
|
|
201 |
return
|
202 |
|
203 |
|
204 |
-
def stream_to_screen(response):
|
205 |
-
for word in response.split():
|
206 |
-
yield word + " "
|
207 |
-
time.sleep(0.15)
|
208 |
|
209 |
-
def post_process(response):
|
210 |
-
"""Remove if last sentence is unfinished"""
|
211 |
-
if response[-1] != '.':
|
212 |
-
sentences = response.split('.')
|
213 |
-
del sentences[-1]
|
214 |
-
return '.'.join(sentences) + '.'
|
215 |
-
|
216 |
-
return response
|
217 |
-
|
218 |
-
|
219 |
|
220 |
if __name__=="__main__":
|
221 |
|
@@ -283,6 +284,7 @@ if __name__=="__main__":
|
|
283 |
|
284 |
Question: {question}\n> Context:\n>>>\n{context}\n>>>\nRelevant parts"""}
|
285 |
|
|
|
286 |
# Loading and caching db and model
|
287 |
bar = st.progress(0, "Loading Database. Please wait.")
|
288 |
bar.progress(0.1, "Loading Embedding & Database. Please wait.")
|
@@ -303,7 +305,7 @@ if __name__=="__main__":
|
|
303 |
st.write(user_question)
|
304 |
|
305 |
response = generate_response(user_question, model, all_templates)
|
306 |
-
|
307 |
with st.chat_message("AI", avatar="🏛️"):
|
308 |
st.write(response)
|
309 |
#st.write_stream(stream_to_screen(response))
|
|
|
171 |
logger.info(f"Total Execution Time: {time.time() - start_time}")
|
172 |
|
173 |
my_bar.progress(0.9, "Post Processing. Please wait.")
|
174 |
+
response = post_process(response)
|
175 |
+
|
176 |
my_bar.progress(1.0, "Done")
|
177 |
time.sleep(1)
|
178 |
my_bar.empty()
|
179 |
return response
|
180 |
|
181 |
|
182 |
+
def stream_to_screen(response):
|
183 |
+
for word in response.split():
|
184 |
+
yield word + " "
|
185 |
+
time.sleep(0.15)
|
186 |
+
|
187 |
+
|
188 |
+
def post_process(response):
|
189 |
+
"""Remove if last sentence is unfinished"""
|
190 |
+
if response[-1] != '.':
|
191 |
+
sentences = response.split('.')
|
192 |
+
del sentences[-1]
|
193 |
+
return '.'.join(sentences) + '.'
|
194 |
+
return response
|
195 |
+
|
196 |
# show background image
|
197 |
def convert_to_base64(bin_file):
|
198 |
with open(bin_file, 'rb') as f:
|
|
|
216 |
return
|
217 |
|
218 |
|
|
|
|
|
|
|
|
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
|
221 |
if __name__=="__main__":
|
222 |
|
|
|
284 |
|
285 |
Question: {question}\n> Context:\n>>>\n{context}\n>>>\nRelevant parts"""}
|
286 |
|
287 |
+
|
288 |
# Loading and caching db and model
|
289 |
bar = st.progress(0, "Loading Database. Please wait.")
|
290 |
bar.progress(0.1, "Loading Embedding & Database. Please wait.")
|
|
|
305 |
st.write(user_question)
|
306 |
|
307 |
response = generate_response(user_question, model, all_templates)
|
308 |
+
|
309 |
with st.chat_message("AI", avatar="🏛️"):
|
310 |
st.write(response)
|
311 |
#st.write_stream(stream_to_screen(response))
|