Ashvanth.S commited on
Commit
e660288
1 Parent(s): 56ca6bf

Updated files

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -17
  2. main_app.py +7 -5
Dockerfile CHANGED
@@ -1,21 +1,14 @@
1
- # Use an official Python runtime as a parent image
2
  FROM python:3.9-slim
3
-
4
- # Set the working directory in the container
5
  WORKDIR /app
6
-
7
- # Copy the current directory contents into the container at /app
 
 
 
 
 
 
8
  COPY . /app
9
 
10
- # Install any needed packages specified in requirements.txt
11
- RUN pip install --no-cache-dir -r requirements.txt
12
-
13
- # Make port 7860 available to the world outside this container
14
- EXPOSE 7860
15
-
16
- # Create a non-root user and switch to it
17
- RUN adduser --disabled-password --gecos '' appuser
18
- USER appuser
19
-
20
- # Run main_app.py when the container launches
21
- CMD ["python", "main_app.py"]
 
 
1
  FROM python:3.9-slim
 
 
2
  WORKDIR /app
3
+ COPY requirements.txt ./requirements.txt
4
+ RUN apt-get update \
5
+ && apt-get -y install libpq-dev gcc \
6
+ && pip install psycopg2
7
+ # Install uvicorn
8
+ RUN pip install uvicorn
9
+ # Install dependencies
10
+ RUN pip install -r requirements.txt
11
  COPY . /app
12
 
13
+ ENTRYPOINT ["uvicorn", "main_app:app"]
14
+ CMD ["--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
main_app.py CHANGED
@@ -21,10 +21,12 @@ class AnswerResponse(BaseModel):
21
  answer: str
22
 
23
  def init_rag_system():
24
- pdf_path = os.environ.get("SOURCE_DATA")
25
- vector_store_path = os.environ.get("VECTOR_STORE")
 
26
  # Load embeddings
27
  embeddings = get_embeddings()
 
28
  if os.path.exists(vector_store_path) and os.listdir(vector_store_path):
29
  print("Loading existing vector store...")
30
  vector_store = load_vector_store(embeddings)
@@ -33,6 +35,7 @@ def init_rag_system():
33
  documents = load_pdf(pdf_path)
34
  unique_ids = create_unique_ids(documents)
35
  vector_store = create_vector_store(documents, unique_ids, embeddings)
 
36
  retriever = get_retriever(vector_store)
37
  model = get_model()
38
  rag_chain = create_rag_chain(model, retriever)
@@ -66,7 +69,6 @@ if __name__ == "__main__":
66
  import uvicorn
67
  uvicorn.run(
68
  app,
69
- host=os.getenv("UVICORN_HOST"),
70
- port=int(os.getenv("UVICORN_PORT")),
71
- # reload=True
72
  )
 
21
  answer: str
22
 
23
  def init_rag_system():
24
+ pdf_path = os.environ.get("SOURCE_DATA", "iesc111.pdf")
25
+ vector_store_path = os.environ.get("VECTOR_STORE", "chroma_langchain_db")
26
+
27
  # Load embeddings
28
  embeddings = get_embeddings()
29
+
30
  if os.path.exists(vector_store_path) and os.listdir(vector_store_path):
31
  print("Loading existing vector store...")
32
  vector_store = load_vector_store(embeddings)
 
35
  documents = load_pdf(pdf_path)
36
  unique_ids = create_unique_ids(documents)
37
  vector_store = create_vector_store(documents, unique_ids, embeddings)
38
+
39
  retriever = get_retriever(vector_store)
40
  model = get_model()
41
  rag_chain = create_rag_chain(model, retriever)
 
69
  import uvicorn
70
  uvicorn.run(
71
  app,
72
+ host=os.getenv("UVICORN_HOST", "0.0.0.0"),
73
+ port=int(os.getenv("UVICORN_PORT", 7860)),
 
74
  )