Update app.py
Browse files
app.py
CHANGED
|
@@ -161,6 +161,7 @@ col1.write(f"**You:** {user_input}")
|
|
| 161 |
ask = col2.button("Ask", type="primary")
|
| 162 |
|
| 163 |
if ask:
|
|
|
|
| 164 |
if not api_key:
|
| 165 |
st.markdown(f"""**{BOOK_NAME}:** Whoops looks like you forgot your API key buddy.
|
| 166 |
We throw a dice. If it's 6, you can ask one question for free.
|
|
@@ -170,36 +171,31 @@ if ask:
|
|
| 170 |
|
| 171 |
dice = randint(1, 6)
|
| 172 |
logger.info(f" dice: {dice}")
|
| 173 |
-
if dice
|
| 174 |
-
api_key_ = api_key
|
| 175 |
-
# st.stop()
|
| 176 |
-
else: # use space secret[OPENAI_API_KEY/envion,
|
| 177 |
api_key_ = os.environ["OPENAI_API_KEY"]
|
| 178 |
st.write(f"**{BOOK_NAME}:** got {dice}, lucky you!")
|
| 179 |
-
|
| 180 |
-
# api_key_ = os.environ["OPENAI_API_KEY"]
|
| 181 |
-
api_key_ = api_key
|
| 182 |
-
|
| 183 |
openai.api_key = api_key_
|
| 184 |
if not api_key_:
|
| 185 |
st.write(f"**{BOOK_NAME}:** got {dice}, no luck, try again?")
|
| 186 |
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
else:
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
logger.info(f"answer: {answer}")
|
| 200 |
-
except Exception as exc:
|
| 201 |
-
st.write(f"**{BOOK_NAME}:**: {exc}")
|
| 202 |
-
st.stop()
|
| 203 |
|
| 204 |
st.write(f"**{BOOK_NAME}:** {answer}")
|
| 205 |
|
|
|
|
| 161 |
ask = col2.button("Ask", type="primary")
|
| 162 |
|
| 163 |
if ask:
|
| 164 |
+
api_key_ = api_key
|
| 165 |
if not api_key:
|
| 166 |
st.markdown(f"""**{BOOK_NAME}:** Whoops looks like you forgot your API key buddy.
|
| 167 |
We throw a dice. If it's 6, you can ask one question for free.
|
|
|
|
| 171 |
|
| 172 |
dice = randint(1, 6)
|
| 173 |
logger.info(f" dice: {dice}")
|
| 174 |
+
if dice == 6:
|
|
|
|
|
|
|
|
|
|
| 175 |
api_key_ = os.environ["OPENAI_API_KEY"]
|
| 176 |
st.write(f"**{BOOK_NAME}:** got {dice}, lucky you!")
|
| 177 |
+
|
|
|
|
|
|
|
|
|
|
| 178 |
openai.api_key = api_key_
|
| 179 |
if not api_key_:
|
| 180 |
st.write(f"**{BOOK_NAME}:** got {dice}, no luck, try again?")
|
| 181 |
st.stop()
|
| 182 |
+
|
| 183 |
+
# os.environ["OPENAI_API_KEY"] = api_key_
|
| 184 |
+
# if ns.counter: # this does not work
|
| 185 |
+
if 'key' in st.session_state:
|
| 186 |
+
msg = "Just one sec"
|
| 187 |
else:
|
| 188 |
+
msg = "Um... excuse me but... this can take about a minute, or two, for your first question because some stuff needs to be downloaded π₯Ίππ»ππ»"
|
| 189 |
+
st.session_state.key = 'value'
|
| 190 |
+
# ns.counter = 1
|
| 191 |
+
with st.spinner(msg):
|
| 192 |
+
try:
|
| 193 |
+
answer, pages, extract = get_answer(question=user_input)
|
| 194 |
+
logger.info(f"answer: {answer}")
|
| 195 |
+
except Exception as exc:
|
| 196 |
+
logger.error(exc)
|
| 197 |
+
st.write(f"**{BOOK_NAME}:**: {exc}")
|
| 198 |
+
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
st.write(f"**{BOOK_NAME}:** {answer}")
|
| 201 |
|