Spaces:
Paused
Paused
Hemang Thakur
commited on
Commit
·
b2e81d3
1
Parent(s):
b2da7d4
changed working directory
Browse files- Dockerfile +29 -23
- main.py +1 -3
- src/helpers/helper.py +1 -1
- src/rag/neo4j_graphrag.py +1 -1
Dockerfile
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
# ----------------------------
|
2 |
-
# Stage 1:
|
3 |
# ----------------------------
|
4 |
-
FROM node:20-alpine AS
|
5 |
RUN apk add --no-cache libc6-compat
|
6 |
-
WORKDIR /app
|
7 |
|
8 |
-
#
|
|
|
|
|
|
|
9 |
RUN mkdir -p /tmp/huggingface && \
|
10 |
chmod -R 777 /tmp/huggingface && \
|
11 |
mkdir -p /app/workspace && \
|
@@ -17,55 +19,59 @@ ENV HF_HOME=/tmp/huggingface \
|
|
17 |
XDG_CACHE_HOME=/tmp \
|
18 |
WRITABLE_DIR=/app/workspace
|
19 |
|
20 |
-
#
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
|
26 |
-
# Install dependencies
|
27 |
RUN if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
28 |
elif [ -f package-lock.json ]; then npm ci; \
|
29 |
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
30 |
else echo "No lockfile found. Exiting." && exit 1; \
|
31 |
fi
|
32 |
|
33 |
-
# Build the React app
|
34 |
RUN npm run build
|
35 |
|
36 |
# ----------------------------
|
37 |
-
# Stage
|
38 |
# ----------------------------
|
39 |
FROM python:3.12-slim AS backend
|
40 |
-
|
|
|
41 |
|
42 |
# Install OS-level dependencies
|
43 |
RUN apt-get update --fix-missing && \
|
44 |
apt-get install --no-install-recommends -y git curl && \
|
45 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
46 |
|
47 |
-
# Install Node.js
|
48 |
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
49 |
apt-get update --fix-missing && \
|
50 |
apt-get install --no-install-recommends -y nodejs && \
|
51 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
52 |
|
53 |
-
# Copy
|
54 |
-
COPY
|
|
|
|
|
|
|
|
|
|
|
55 |
RUN pip install --no-cache-dir -r requirements.txt
|
56 |
|
57 |
# Install additional dependencies for torch and spaCy
|
58 |
RUN pip install --no-cache-dir torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
|
59 |
RUN python -m spacy download en_core_web_sm
|
60 |
|
61 |
-
#
|
62 |
-
COPY . .
|
63 |
-
|
64 |
-
# Copy the built React app from the builder stage into the same folder structure as used in your FastAPI code
|
65 |
-
COPY --from=builder /app/frontend/build ./frontend/build
|
66 |
-
|
67 |
-
# Expose the port
|
68 |
EXPOSE ${PORT:-7860}
|
69 |
|
70 |
-
# Start the FastAPI backend using Uvicorn
|
71 |
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]
|
|
|
1 |
# ----------------------------
|
2 |
+
# Stage 1: Setup - Create Writable Directories and Set Cache Variables
|
3 |
# ----------------------------
|
4 |
+
FROM node:20-alpine AS setup
|
5 |
RUN apk add --no-cache libc6-compat
|
|
|
6 |
|
7 |
+
# Set the entire project’s working/root directory as /app/workspace
|
8 |
+
WORKDIR /app/workspace
|
9 |
+
|
10 |
+
# Create writable directories for Hugging Face Spaces and ensure full permissions
|
11 |
RUN mkdir -p /tmp/huggingface && \
|
12 |
chmod -R 777 /tmp/huggingface && \
|
13 |
mkdir -p /app/workspace && \
|
|
|
19 |
XDG_CACHE_HOME=/tmp \
|
20 |
WRITABLE_DIR=/app/workspace
|
21 |
|
22 |
+
# ----------------------------
|
23 |
+
# Stage 2: Build the React Frontend
|
24 |
+
# ----------------------------
|
25 |
+
FROM setup AS frontend
|
26 |
+
# Switch to the frontend subdirectory under the project root
|
27 |
+
WORKDIR /app/workspace/frontend
|
28 |
|
29 |
+
# Copy the local 'frontend' folder (its contents) into /app/workspace/frontend
|
30 |
+
COPY frontend/ .
|
31 |
|
32 |
+
# Install dependencies using the appropriate package manager
|
33 |
RUN if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
34 |
elif [ -f package-lock.json ]; then npm ci; \
|
35 |
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
36 |
else echo "No lockfile found. Exiting." && exit 1; \
|
37 |
fi
|
38 |
|
39 |
+
# Build the React app
|
40 |
RUN npm run build
|
41 |
|
42 |
# ----------------------------
|
43 |
+
# Stage 3: Set Up the FastAPI Backend
|
44 |
# ----------------------------
|
45 |
FROM python:3.12-slim AS backend
|
46 |
+
# Set the entire project’s working/root directory as /app/workspace
|
47 |
+
WORKDIR /app/workspace
|
48 |
|
49 |
# Install OS-level dependencies
|
50 |
RUN apt-get update --fix-missing && \
|
51 |
apt-get install --no-install-recommends -y git curl && \
|
52 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
53 |
|
54 |
+
# Install Node.js
|
55 |
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
56 |
apt-get update --fix-missing && \
|
57 |
apt-get install --no-install-recommends -y nodejs && \
|
58 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
59 |
|
60 |
+
# Copy the entire project source into /app/workspace (includes backend code, requirements, etc.)
|
61 |
+
COPY . .
|
62 |
+
|
63 |
+
# Copy the built React app from the frontend stage into the appropriate location
|
64 |
+
COPY --from=frontend /app/workspace/frontend/build ./frontend/build
|
65 |
+
|
66 |
+
# Install Python dependencies from requirements.txt
|
67 |
RUN pip install --no-cache-dir -r requirements.txt
|
68 |
|
69 |
# Install additional dependencies for torch and spaCy
|
70 |
RUN pip install --no-cache-dir torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
|
71 |
RUN python -m spacy download en_core_web_sm
|
72 |
|
73 |
+
# Expose the port (using the PORT environment variable if provided, or default to 7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
EXPOSE ${PORT:-7860}
|
75 |
|
76 |
+
# Start the FastAPI backend using Uvicorn
|
77 |
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]
|
main.py
CHANGED
@@ -17,8 +17,6 @@ from google.api_core.exceptions import ResourceExhausted
|
|
17 |
logger = logging.getLogger()
|
18 |
logger.setLevel(logging.INFO)
|
19 |
|
20 |
-
ENV_FILE_PATH = os.getenv("WRITABLE_DIR", "/tmp") + "/.env"
|
21 |
-
|
22 |
CONTEXT_LENGTH = 128000
|
23 |
BUFFER = 10000
|
24 |
MAX_TOKENS_ALLOWED = CONTEXT_LENGTH - BUFFER
|
@@ -37,7 +35,7 @@ def format_error_sse(event_type: str, data: str) -> str:
|
|
37 |
|
38 |
# Initialize the components
|
39 |
def initialize_components():
|
40 |
-
load_dotenv(
|
41 |
|
42 |
from src.search.search_engine import SearchEngine
|
43 |
from src.query_processing.query_processor import QueryProcessor
|
|
|
17 |
logger = logging.getLogger()
|
18 |
logger.setLevel(logging.INFO)
|
19 |
|
|
|
|
|
20 |
CONTEXT_LENGTH = 128000
|
21 |
BUFFER = 10000
|
22 |
MAX_TOKENS_ALLOWED = CONTEXT_LENGTH - BUFFER
|
|
|
35 |
|
36 |
# Initialize the components
|
37 |
def initialize_components():
|
38 |
+
load_dotenv(override=True)
|
39 |
|
40 |
from src.search.search_engine import SearchEngine
|
41 |
from src.query_processing.query_processor import QueryProcessor
|
src/helpers/helper.py
CHANGED
@@ -5,7 +5,7 @@ import torch
|
|
5 |
import transformers
|
6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter, TokenTextSplitter
|
7 |
|
8 |
-
ENV_FILE_PATH = os.path.join(os.
|
9 |
|
10 |
def remove_markdown(text: str) -> str:
|
11 |
# Remove code block format type and the code block itself
|
|
|
5 |
import transformers
|
6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter, TokenTextSplitter
|
7 |
|
8 |
+
ENV_FILE_PATH = os.path.join(os.path.dirname(__file__), "../../.env").replace("\\", "/")
|
9 |
|
10 |
def remove_markdown(text: str) -> str:
|
11 |
# Remove code block format type and the code block itself
|
src/rag/neo4j_graphrag.py
CHANGED
@@ -1972,7 +1972,7 @@ class Neo4jGraphRAG:
|
|
1972 |
net.options["interaction"] = {"dragNodes": True}
|
1973 |
|
1974 |
# 5. Save to a temporary file, read it, then remove that file
|
1975 |
-
net.save_graph(
|
1976 |
with open("temp_graph.html", "r", encoding="utf-8") as f:
|
1977 |
html_str = f.read()
|
1978 |
|
|
|
1972 |
net.options["interaction"] = {"dragNodes": True}
|
1973 |
|
1974 |
# 5. Save to a temporary file, read it, then remove that file
|
1975 |
+
net.save_graph("temp_graph.html")
|
1976 |
with open("temp_graph.html", "r", encoding="utf-8") as f:
|
1977 |
html_str = f.read()
|
1978 |
|