suriya7 commited on
Commit
9d6ad70
1 Parent(s): bb31c00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -58,17 +58,16 @@ def handle_query(query):
58
  )
59
  ]
60
  text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
61
- with st.chat_message("assistant"):
62
- with st.spinner("Thinking..."):
63
- query_engine = index.as_query_engine(text_qa_template=text_qa_template)
64
- answer = query_engine.query(query)
65
-
66
- if hasattr(answer, 'response'):
67
- return answer.response
68
- elif isinstance(answer, dict) and 'response' in answer:
69
- return answer['response']
70
- else:
71
- return "Sorry, I couldn't find an answer."
72
 
73
 
74
  # Streamlit app initialization
@@ -94,9 +93,16 @@ with st.sidebar:
94
  user_prompt = st.chat_input("Ask me anything about the content of the PDF:")
95
  if user_prompt:
96
  st.session_state.messages.append({'role': 'user', "content": user_prompt})
 
 
 
97
  response = handle_query(user_prompt)
 
 
 
 
98
  st.session_state.messages.append({'role': 'assistant', "content": response})
99
 
100
- for message in st.session_state.messages:
101
- with st.chat_message(message['role']):
102
- st.write(message['content'])
 
58
  )
59
  ]
60
  text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
61
+
62
+ query_engine = index.as_query_engine(text_qa_template=text_qa_template)
63
+ answer = query_engine.query(query)
64
+
65
+ if hasattr(answer, 'response'):
66
+ return answer.response
67
+ elif isinstance(answer, dict) and 'response' in answer:
68
+ return answer['response']
69
+ else:
70
+ return "Sorry, I couldn't find an answer."
 
71
 
72
 
73
  # Streamlit app initialization
 
93
  user_prompt = st.chat_input("Ask me anything about the content of the PDF:")
94
  if user_prompt:
95
  st.session_state.messages.append({'role': 'user', "content": user_prompt})
96
+ for message in st.session_state.messages:
97
+ with st.chat_message(message['role']):
98
+ st.write(message['content'])
99
  response = handle_query(user_prompt)
100
+ if st.session_state.messages[-1]["role"] != "assistant":
101
+ with st.chat_message("assistant"):
102
+ with st.spinner("Thinking..."):
103
+ st.write(response)
104
  st.session_state.messages.append({'role': 'assistant', "content": response})
105
 
106
+ # for message in st.session_state.messages:
107
+ # with st.chat_message(message['role']):
108
+ # st.write(message['content'])