Skip to content

Instantly share code, notes, and snippets.

@s-espriz
Created January 9, 2025 21:11
Show Gist options
  • Save s-espriz/08c851c216b57065f53dcad4bfe8deac to your computer and use it in GitHub Desktop.
Save s-espriz/08c851c216b57065f53dcad4bfe8deac to your computer and use it in GitHub Desktop.
this is a simple UI suggestion for Using Piper Backend
import streamlit as st
import requests
url = 'http://127.0.0.1:8001/invoke/'
st.title("Piper")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("Ask your research Questions"):
# Display user message in chat message container
st.chat_message("user").markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
input = {"prompt" : prompt , "thread_id" : "6"}
res = requests.post(url, params= input)
res = res.json()
with st.sidebar:
# context
st.header("context")
if "queries" in res.keys():
st.markdown(f"- {res["queries"][-1]}")
else :
st.caption("None")
st.divider()
st.header("loaded papers")
if "loaded_papers" in res.keys():
for paper in res["loaded_papers"] :
st.markdown(f"- [{paper}](https://arxiv.org/abs/{paper})")
else:
st.caption("None")
response = f"{res["messages"][-1]['content']}"
# Display assistant response in chat message container
with st.chat_message("assistant"):
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment