Anne31415 commited on
Commit
48a4a46
·
1 Parent(s): 6f8c132

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -115,10 +115,10 @@ def main():
115
 
116
  pdf = st.file_uploader("Upload your PDF", type="pdf")
117
 
118
- if pdf is not None:
119
- query = st.text_input("Ask questions about your PDF file (in any preferred language):")
120
 
121
- if st.button("Ask") or (query and query != st.session_state.get('last_input', '')):
 
122
  st.session_state['last_input'] = query
123
  st.session_state['chat_history'].append(("User", query, "new"))
124
 
@@ -144,12 +144,19 @@ def main():
144
  background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
145
  new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
146
 
 
 
147
  loading_message.empty()
148
 
149
  query = ""
 
 
150
 
151
  st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
152
 
 
 
 
153
  # Displaying example questions
154
  if not st.session_state['chat_history']:
155
  st.markdown("""
 
115
 
116
  pdf = st.file_uploader("Upload your PDF", type="pdf")
117
 
118
+ query = st.text_input("Ask questions about your PDF file (in any preferred language):")
 
119
 
120
+ if st.button("Ask") or (query and query != st.session_state.get('last_input', '')):
121
+ if pdf is not None:
122
  st.session_state['last_input'] = query
123
  st.session_state['chat_history'].append(("User", query, "new"))
124
 
 
144
  background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
145
  new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
146
 
147
+ st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
148
+
149
  loading_message.empty()
150
 
151
  query = ""
152
+ else:
153
+ st.warning("Please upload a PDF file before asking questions.")
154
 
155
  st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
156
 
157
+
158
+
159
+
160
  # Displaying example questions
161
  if not st.session_state['chat_history']:
162
  st.markdown("""