docker 설정 수정

This commit is contained in:
2025-03-07 19:22:05 +09:00
parent 9118c40c56
commit 309e98f47d
3 changed files with 21 additions and 4 deletions

9
docker-compose.yml Normal file
View File

@@ -0,0 +1,9 @@
version: "3"
services:
app:
build: .
volumes:
- .:/opt/workspace # 로컬 디렉토리와 컨테이너 디렉토리 동기화
ports:
- "8501:8501" # Streamlit 앱 포트 설정
container_name: streamlit-rag # 컨테이너 이름 설정

View File

@@ -1,6 +1,7 @@
FROM pytorch/pytorch:latest FROM pytorch/pytorch:latest
WORKDIR /app
ADD . /opt/workspace
WORKDIR /opt/workspace
# 필수 패키지 설치 # 필수 패키지 설치
RUN apt-get update && apt-get install -y python3-pip RUN apt-get update && apt-get install -y python3-pip

13
main.py
View File

@@ -84,10 +84,15 @@ def load_and_process_documents(directory_path):
def save_faiss_index(faiss_index, path="faiss_index"): def save_faiss_index(faiss_index, path="faiss_index"):
faiss_index.save_local(path) faiss_index.save_local(path)
print("-------------------------------------------")
print("save_faiss_index")
print("-------------------------------------------")
def load_faiss_index(path="faiss_index"): def load_faiss_index(path="faiss_index"):
embeddings = embedding() embeddings = embedding()
print("-------------------------------------------")
print("load_faiss_index")
print("-------------------------------------------")
return FAISS.load_local(path, embeddings, allow_dangerous_deserialization=True) return FAISS.load_local(path, embeddings, allow_dangerous_deserialization=True)
@@ -101,6 +106,7 @@ def initialize_processing():
try: try:
faiss_index = load_faiss_index(SAVE_VD) faiss_index = load_faiss_index(SAVE_VD)
except Exception: except Exception:
print("no load_faiss_index")
embeddings = embedding() embeddings = embedding()
faiss_index = FAISS.from_documents(docs, embeddings) faiss_index = FAISS.from_documents(docs, embeddings)
save_faiss_index(faiss_index, SAVE_VD) save_faiss_index(faiss_index, SAVE_VD)
@@ -168,10 +174,11 @@ if user_input := st.chat_input():
with st.spinner("문서 검색 및 답변 생성 중..."): with st.spinner("문서 검색 및 답변 생성 중..."):
docs = reranker.invoke(user_input) docs = reranker.invoke(user_input)
print(docs)
context_texts = "\n\n".join( context_texts = "\n\n".join(
[ [
f"- {doc[0].metadata['source']} (유사도: {doc[1]}): {doc[0].page_content}" f"- {doc[0].metadata['source']} (유사도: {doc[1]}): {doc[0].page_content}"
for doc in docs for doc in docs
] ]
) )