Zubaish commited on
Commit ·
3f76bb4
1
Parent(s): 2d4b429
Fix langchain_chroma error; pin stable deps
Browse filesFiles changed (4)
- Dockerfile-6
- ingest.py+2-1
- rag.py+4-4
- requirements.txt+6-6
1 unmodified line23455678109101114121317141520161723181 unmodified line
WORKDIR /app
# System dependenciesRUN apt-get update && apt-get install -y \ git \ && rm -rf /var/lib/apt/lists/*
# Python dependenciesCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt
# Application codeCOPY app.py rag.py ingest.py guardrails.py config.py ./
# Create empty kb_docs directory (PDFs added later via HF UI)RUN mkdir -p kb_docs
# Hugging Face Spaces portEXPOSE 7860
# Start FastAPICMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]10 unmodified lines1112131414151617181 unmodified line202122232410 unmodified lines glob="**/*.pdf", loader_cls=PyPDFLoader ) docs = loader.load()
docs = loader.load() if not docs: return []
1 unmodified line chunk_size=800, chunk_overlap=100 )
return splitter.split_documents(docs)1223458 unmodified lines141516171718192011 unmodified lines32333435353637383940414242434445from langchain_community.vectorstores import Chromafrom langchain_huggingface import HuggingFaceEmbeddings, ChatHuggingFacefrom langchain_chroma import Chromafrom langchain.schema import SystemMessage, HumanMessage
from ingest import load_and_split_docs8 unmodified lines
if documents: vectorstore = Chroma.from_documents( documents, documents=documents, embedding=embeddings ) retriever = vectorstore.as_retriever(search_kwargs={"k": 3})11 unmodified lines if not retriever: return { "status": ["⚠️ No documents uploaded yet"], "answer": "Please upload PDF files to the kb_docs folder." "answer": "Please upload PDF files to the kb_docs folder and restart the Space." }
docs = retriever.get_relevant_documents(question) context = "\n\n".join(d.page_content for d in docs)
messages = [ SystemMessage(content="Answer using the provided context."), SystemMessage(content="Answer using only the provided context."), HumanMessage(content=f"Context:\n{context}\n\nQuestion: {question}") ]
2 unmodified lines34567896789111011121314142 unmodified linespydanticpython-dotenv
langchainlangchain-communitylangchain-corelangchain-huggingfacelangchain==0.2.17langchain-community==0.2.17langchain-huggingface==0.1.0
chromadbchromadb==0.5.5sentence-transformers
pypdfhuggingface_hubhuggingface_hub>=0.33.4,<1.0.0Dockerfile-6
ingest.py+2-1
rag.py+4-4
requirements.txt+6-6