PromptPilotPro
A Freelance Ladder AI Training Product
Free Lesson 2 of 3
Add a Chat Interface
Wrap your RAG system in a Streamlit chat interface so anyone can use it in a browser.
Your Pilot

In Lesson 1, you built a RAG system in Colab. Now let's turn it into a real web app with Streamlit. By the end of this lesson, anyone can upload a document and ask questions — all from a browser.

✈️ Prerequisite: Lesson 1 — working RAG system in Google Colab.

Step-by-Step Instructions

STEP 1
Install Streamlit

On your local computer, install Python from python.org first, then run:

pip install streamlit langchain-openai langchain-community langchain-chroma langchain-text-splitters chromadb openai
STEP 2
Create app.py

Copy the complete code below into a file named app.py. This version includes full RAG — chunking, retrieval, AND generation — so the app gives real answers, not just raw document chunks.

STEP 3
Run the App
streamlit run app.py
💡 Open http://localhost:8501 in your browser.
STEP 4
Deploy (Optional – Free)

Push your project to GitHub → go to share.streamlit.io → Deploy → Get public URL. Lesson 3 covers this in detail.

💡 Before deploying, update your API key handling: replace os.environ["OPENAI_API_KEY"] = openai_api_key with os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"] and remove the text input field. Lesson 3 explains this in full.

Full Code — app.py

import streamlit as st from langchain_community.document_loaders import TextLoader from langchain_text_splitters import RecursiveCharacterTextSplitter from langchain_openai import OpenAIEmbeddings from langchain_chroma import Chroma from openai import OpenAI import os st.set_page_config(page_title="PromptPilotPro RAG Chat", page_icon="✈️") st.title("✈️ PromptPilotPro RAG Assistant") st.markdown("Upload a Northwind practice file, ask questions, and get answers grounded in the document.") with st.sidebar: st.header("Step 1: Upload your document") uploaded_file = st.file_uploader("Choose a text file", type=["txt"]) openai_api_key = st.text_input("OpenAI API Key", type="password") st.markdown("[Get your OpenAI API key](https://platform.openai.com/api-keys)") if uploaded_file and openai_api_key: os.environ["OPENAI_API_KEY"] = openai_api_key with open("temp_upload.txt", "wb") as f: f.write(uploaded_file.getbuffer()) with st.spinner("Loading document and building RAG system..."): loader = TextLoader("temp_upload.txt") documents = loader.load() text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) chunks = text_splitter.split_documents(documents) embeddings = OpenAIEmbeddings() vectorstore = Chroma.from_documents(chunks, embeddings) st.success("✅ RAG system ready!") query = st.text_input("Your question:") if query: with st.spinner("Retrieving and generating answer..."): docs = vectorstore.similarity_search(query) context = "\n\n".join([d.page_content for d in docs]) client = OpenAI() response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "Answer the question based ONLY on the context provided. If the answer is not in the context, say you don't know."}, {"role": "user", "content": f"Context:\n{context}\n\nQuestion: {query}"} ] ) st.write(response.choices[0].message.content) else: st.info("📄 Upload a Northwind practice file and enter your OpenAI API key to begin.")

✈️ Portfolio Demo Checklist

Lesson 2 Complete — What's Next?

Your RAG app now has a chat interface. Time to deploy it to a live URL.

➡️ Go to Lesson 3 — Deploy to a Live URL