mikeee commited on
Commit
ccede54
Β·
1 Parent(s): f77b83a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import streamlit as st
 
3
 
4
  from langchain.embeddings import HuggingFaceInstructEmbeddings
5
  from langchain.vectorstores.faiss import FAISS
@@ -8,6 +9,7 @@ from huggingface_hub import snapshot_download
8
  from langchain import OpenAI
9
  from langchain import PromptTemplate
10
 
 
11
 
12
  st.set_page_config(page_title="Talk2Book", page_icon="πŸ“–")
13
 
@@ -169,11 +171,16 @@ if ask:
169
  st.write(f"**{BOOK_NAME}:** Whoops looks like you forgot your API key buddy")
170
  st.stop()
171
  else:
172
- with st.spinner("Um... excuse me but... this can take about a minute for your first question because some stuff have to be downloaded πŸ₯ΊπŸ‘‰πŸ»πŸ‘ˆπŸ»"):
 
 
 
 
 
173
  try:
174
  answer, pages, extract = get_answer(question=user_input)
175
- except:
176
- st.write(f"**{BOOK_NAME}:** What\'s going on? That's not the right API key")
177
  st.stop()
178
 
179
  st.write(f"**{BOOK_NAME}:** {answer}")
 
1
  import os
2
  import streamlit as st
3
+ from types import SimpleNamespace
4
 
5
  from langchain.embeddings import HuggingFaceInstructEmbeddings
6
  from langchain.vectorstores.faiss import FAISS
 
9
  from langchain import OpenAI
10
  from langchain import PromptTemplate
11
 
12
+ ns = SimpleNamespace(counter=0)
13
 
14
  st.set_page_config(page_title="Talk2Book", page_icon="πŸ“–")
15
 
 
171
  st.write(f"**{BOOK_NAME}:** Whoops looks like you forgot your API key buddy")
172
  st.stop()
173
  else:
174
+ if ns.counter:
175
+ msg = "Um... excuse me but... this can take about a minute for your first question because some stuff have to be downloaded πŸ₯ΊπŸ‘‰πŸ»πŸ‘ˆπŸ»"
176
+ ns.counter = 1
177
+ else:
178
+ msg = "Just one sec"
179
+ with st.spinner(msg):
180
  try:
181
  answer, pages, extract = get_answer(question=user_input)
182
+ except Exception as exc:
183
+ st.write(f"**{BOOK_NAME}:**: {exc}")
184
  st.stop()
185
 
186
  st.write(f"**{BOOK_NAME}:** {answer}")