sujitb commited on
Commit
503beb8
1 Parent(s): 670418a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -186,7 +186,7 @@ QUESTION = st.chat_input('Ask a question -e.g How to prepare for Verbal section
186
  #QUESTION=st.text_area('Ask a question -e.g How to prepare for Verbal section for CAT?') ##' How to prepare for Verbal section ?'
187
  score=0
188
  testing=True
189
-
190
 
191
  if QUESTION:
192
 
@@ -278,6 +278,25 @@ if QUESTION:
278
  else:
279
  ans='Weak match to your query. Please try reframing your question'
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  #st.write("Matched URL:{} Score:{}".format(url,score))
282
  testing = False
283
  if testing:
@@ -285,6 +304,8 @@ if QUESTION:
285
  st.write("2nd Matched URL:{} Score:{}".format(resp[1]['id'],resp[1]['score']))
286
  if len(resp)>=2:
287
  st.write("3rd Matched URL:{} Score:{}".format(resp[2]['id'],resp[2]['score']))
 
 
288
  ## Send RESPONSE
289
  with st.chat_message("assistant"):
290
  response = st.write_stream(response_generator(ans))
@@ -301,9 +322,11 @@ if QUESTION:
301
  break
302
  st.write("["+disp_title+"]("+disp_url+")")
303
 
304
- else:
305
- st.write('Resources:',top_2[0]['score'], ' confidence')
306
- st.write(top_2[0]['url'])
 
 
307
  # Add assistant response to chat history
308
  st.session_state.messages.append({"role": "assistant", "content": response})
309
  #st.write(ans)
 
186
  #QUESTION=st.text_area('Ask a question -e.g How to prepare for Verbal section for CAT?') ##' How to prepare for Verbal section ?'
187
  score=0
188
  testing=True
189
+ ext_url=''
190
 
191
  if QUESTION:
192
 
 
278
  else:
279
  ans='Weak match to your query. Please try reframing your question'
280
 
281
+ ## Call Tavily
282
+ tavily_key= os.environ["TAVILY_KEY"]
283
+
284
+ tavily = TavilyClient(api_key=tavily_key)
285
+
286
+ success= 0
287
+ while success<3:
288
+ success+=1
289
+ try:
290
+ resp=tavily.search(query=QUESTION)
291
+ with st.chat_message("assistant"):
292
+ ans=resp['results'][0]['content']
293
+
294
+ ext_url= resp['results'][0]['url']
295
+ break
296
+ except:
297
+ pass
298
+
299
+
300
  #st.write("Matched URL:{} Score:{}".format(url,score))
301
  testing = False
302
  if testing:
 
304
  st.write("2nd Matched URL:{} Score:{}".format(resp[1]['id'],resp[1]['score']))
305
  if len(resp)>=2:
306
  st.write("3rd Matched URL:{} Score:{}".format(resp[2]['id'],resp[2]['score']))
307
+
308
+
309
  ## Send RESPONSE
310
  with st.chat_message("assistant"):
311
  response = st.write_stream(response_generator(ans))
 
322
  break
323
  st.write("["+disp_title+"]("+disp_url+")")
324
 
325
+ else: # not a good match
326
+
327
+ if len(ext_url)>5:
328
+ st.write('External Site:',ext_url)
329
+ #st.write(top_2[0]['url'])
330
  # Add assistant response to chat history
331
  st.session_state.messages.append({"role": "assistant", "content": response})
332
  #st.write(ans)