Hemang Thakur commited on
Commit
979861e
·
1 Parent(s): 95aeccb

full read and write permissions to the working directory

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -2
  2. main.py +3 -1
  3. src/helpers/helper.py +1 -1
Dockerfile CHANGED
@@ -5,8 +5,17 @@ FROM node:20-alpine AS builder
5
  RUN apk add --no-cache libc6-compat
6
  WORKDIR /app
7
 
8
- # Give permissions to the app directory
9
- RUN chmod -R 777 /app
 
 
 
 
 
 
 
 
 
10
 
11
  # Copy the 'frontend' folder from the project root into the container
12
  COPY frontend ./frontend
 
5
  RUN apk add --no-cache libc6-compat
6
  WORKDIR /app
7
 
8
+ # Create writable directories for Hugging Face Spaces
9
+ RUN mkdir -p /tmp/huggingface && \
10
+ chmod -R 777 /tmp/huggingface && \
11
+ mkdir -p /app/workspace && \
12
+ chmod -R 777 /app/workspace
13
+
14
+ # Set cache environment variables at build time
15
+ ENV HF_HOME=/tmp/huggingface \
16
+ TRANSFORMERS_CACHE=/tmp/huggingface \
17
+ XDG_CACHE_HOME=/tmp \
18
+ WRITABLE_DIR=/app/workspace
19
 
20
  # Copy the 'frontend' folder from the project root into the container
21
  COPY frontend ./frontend
main.py CHANGED
@@ -17,6 +17,8 @@ from google.api_core.exceptions import ResourceExhausted
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,7 +37,7 @@ def format_error_sse(event_type: str, data: str) -> str:
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
 
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
 
38
  # Initialize the components
39
  def initialize_components():
40
+ load_dotenv(ENV_FILE_PATH, override=True)
41
 
42
  from src.search.search_engine import SearchEngine
43
  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.path.dirname(__file__), "../../.env").replace("\\", "/")
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.getenv("WRITABLE_DIR", "/tmp"), ".env")
9
 
10
  def remove_markdown(text: str) -> str:
11
  # Remove code block format type and the code block itself