mikeee commited on
Commit
6b770bd
Β·
1 Parent(s): 2f81e02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
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 != 6:
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
- else:
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
- # os.environ["OPENAI_API_KEY"] = api_key_
189
- # if ns.counter: # this does not work
190
- if 'key' in st.session_state:
191
- msg = "Just one sec"
192
- else:
193
- msg = "Um... excuse me but... this can take about a minute, or two, for your first question because some stuff needs to be downloaded πŸ₯ΊπŸ‘‰πŸ»πŸ‘ˆπŸ»"
194
- st.session_state.key = 'value'
195
- # ns.counter = 1
196
- with st.spinner(msg):
197
- try:
198
- answer, pages, extract = get_answer(question=user_input)
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