Spaces:
Running
Running
add sidebar buttons
Browse files
app.py
CHANGED
@@ -260,6 +260,73 @@ def main():
|
|
260 |
st.session_state.auto_submit = True
|
261 |
st.session_state.auto_submit_text = text
|
262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
# Accept user input
|
264 |
prompt = st.chat_input("Type your claim here")
|
265 |
if prompt:
|
|
|
260 |
st.session_state.auto_submit = True
|
261 |
st.session_state.auto_submit_text = text
|
262 |
|
263 |
+
# Quick input buttons - place these above the chat input
|
264 |
+
st.sidebar.subheader("Quick Inputs")
|
265 |
+
|
266 |
+
# Create buttons in the sidebar
|
267 |
+
if st.sidebar.button("Example 1 C"):
|
268 |
+
send_preset_message("The density of cytokine receptor bearing cells has no effect on the distance over which cytokines act.")
|
269 |
+
|
270 |
+
if st.sidebar.button("Example 2 C"):
|
271 |
+
send_preset_message("A total of 1,000 people in the UK are asymptomatic carriers of vCJD infection.")
|
272 |
+
|
273 |
+
if st.sidebar.button("Example 3 C"):
|
274 |
+
send_preset_message("Sepsis related mortality has risen from 2009 to 2014.")
|
275 |
+
|
276 |
+
if st.sidebar.button("Example 4 S"):
|
277 |
+
send_preset_message("IL-6 signaling plays a major role in atherosclerotic cardiovascular disease.")
|
278 |
+
|
279 |
+
if st.sidebar.button("Example 5 S"):
|
280 |
+
send_preset_message("The severity of cardiac involvement in amyloidosis can be described by the degree of transmurality of late gadolinium enhancement in MRI.")
|
281 |
+
|
282 |
+
if st.sidebar.button("Example 6 S"):
|
283 |
+
send_preset_message("There was an estimated 30 million cases of pneumonia in young children worldwide in 2010.")
|
284 |
+
|
285 |
+
# Handle auto-submission if a button was clicked
|
286 |
+
if "auto_submit" in st.session_state and st.session_state.auto_submit:
|
287 |
+
prompt = st.session_state.auto_submit_text
|
288 |
+
|
289 |
+
# Process the message - in this example we just echo it back
|
290 |
+
# In a real app, you would have more complex logic here
|
291 |
+
# st.session_state.messages.append({"role": "assistant", "content": f"You said: {prompt}"})
|
292 |
+
|
293 |
+
display_message = prompt + " \n"+ " \n"+ f"Retriever: {selected_retriever}, Reasoner: {selected_reasoner}"
|
294 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
295 |
+
st.session_state.messages.append({"role": "summary", "content": display_message})
|
296 |
+
|
297 |
+
# Display user message in chat message container
|
298 |
+
with st.chat_message("user"):
|
299 |
+
st.markdown(display_message)
|
300 |
+
|
301 |
+
retrieved_documents = retriever(prompt, selected_retriever)
|
302 |
+
reasoning, decision = reasoner(prompt, retrieved_documents, selected_reasoner, llm_client)
|
303 |
+
|
304 |
+
# Display assistant response in chat message container
|
305 |
+
with st.chat_message("assistant"):
|
306 |
+
message_placeholder = st.empty()
|
307 |
+
full_response = ""
|
308 |
+
if decision.lower() == 'support':
|
309 |
+
assistant_response = f'The claim is CORRECT because {reasoning}'
|
310 |
+
elif decision.lower() == 'contradict':
|
311 |
+
assistant_response = f'The claim is INCORRECT because {reasoning}'
|
312 |
+
else:
|
313 |
+
assistant_response = f'Sorry, the query failed due to an issue with connecting to the LLM service.'
|
314 |
+
|
315 |
+
# Simulate stream of response with milliseconds delay
|
316 |
+
for chunk in assistant_response.split():
|
317 |
+
full_response += chunk + " "
|
318 |
+
time.sleep(0.05)
|
319 |
+
# Add a blinking cursor to simulate typing
|
320 |
+
message_placeholder.markdown(full_response + "▌")
|
321 |
+
message_placeholder.markdown(full_response)
|
322 |
+
# Add assistant response to chat history
|
323 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
324 |
+
|
325 |
+
# Reset the auto_submit flag
|
326 |
+
st.session_state.auto_submit = False
|
327 |
+
# Rerun to update the UI immediately - may not be needed
|
328 |
+
# st.rerun()
|
329 |
+
|
330 |
# Accept user input
|
331 |
prompt = st.chat_input("Type your claim here")
|
332 |
if prompt:
|