Advice needed: Converting Jupyter Notebook to Streamlit web app for LLM chatbot

Hello everyone,

I’m part of a team developing a chatbot for financial document Q&A using LLM. Our current process involves:

  1. Uploading financial reports (PDF, TXT, CSV, PNG) and streaming stock data.
  2. Chunking documents.
  3. Embedding chunks and storing them in Chroma DB (vector database).
  4. Retrieving relevant information and generating answers.

We’re using OpenAI’s LLM and Langchain for Retrieval-Augmented Generation (RAG). Initial development was done in Jupyter Notebook, and I now have a stockagent.py file that I want to convert into a Streamlit web app.

I have a few key questions:

  1. What’s the best approach to convert a Jupyter Notebook .py file to a Streamlit web app?
  2. How can I implement an interactive, multi-round Q&A system using Langchain’s memory for ongoing conversations? (The current notebook has hardcoded Q&A interactions.)
  3. I am considering designing a better UI to allow users to: a) Select different knowledge bases to query. b) Select different LLMs to generate answers. c) Provide references to answers, similar to Perplexity.

Based on my research, I saw people splitting stockagent.py into multiple files:

One for defined functions.
One for document embedding and storing multiple documentations in a single vector DB.
One for LLM retrieval and answer generation.
One is the main UI Streamlit app.py.

I am a beginner using Streamlit and I like what I have experienced so far. I really want to use some cool and advanced features from Streamlit to make it work.

Any advice or tips would be greatly appreciated!

Thanks,
Andrew

Your Streamlit structure is similar to what I’ve implemented. I also used the pages directory and had a sub-folder in there for the logic.
With regard to conversational memory, this may be helpful: Conversational RAG | 🦜️🔗 LangChain

1 Like

Thank you Vikram, I will review and give a try and report back…