User interface
- Options:
- RAG will be invoked as api from chat interface (javascript)
- POC:
- Streamlit
- Gradio
Streamlit
-
Refer Here for the streamlit docs
-
Add a package
uv add streamlit
-
create a file called as app.py and to run use
streamlit run app.py -
use playground
-
Streamlit session state: Refer Here
Session state
using local values vs session state keys
- local value: the count will always be 1 after n clicks on button as entire code is running
import streamlit as st
count = 0
if st.button("Increment"):
count += 1
st.write(f"Count: {count}")
- session state key: Rather than using a local variable we are using session state key
import streamlit as st
if "count" not in st.session_state:
st.session_state.count = 0
if st.button("Increment"):
st.session_state.count += 1
st.write(f"Count: {st.session_state.count}")
Widget’s value: plain variable vs its key
- plain variable
import streamlit as st
name = st.text_input("Name")
st.write(f"Hello {name}!")
- key
import streamlit as st
st.text_input("Name", key="name")
st.write(f"Hello {st.session_state.name}")
def greet():
st.write(f"Call back sees: {st.session_state.name}")
st.button("Greet", on_click=greet)
Caching:
- To avoid recomputing expensive resources like db or files or llm streamlit supports caching Refer Here
-
It has
- cache data
- cache resource
-
Refer Here for the changes done
