37-AN commited on
Commit
8faa239
·
1 Parent(s): c7d6600

Initial commit for Hugging Face Space deployment

Browse files
Files changed (2) hide show
  1. Dockerfile +14 -2
  2. app/core/llm.py +12 -1
Dockerfile CHANGED
@@ -14,14 +14,26 @@ COPY requirements.txt .
14
  # Install Python dependencies
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
 
 
 
 
 
 
 
 
 
17
  # Copy the rest of the application
18
  COPY . .
19
 
20
- # Create necessary directories
21
- RUN mkdir -p data/documents data/vector_db
 
22
 
23
  # Set environment variable to avoid TOKENIZERS_PARALLELISM warning
24
  ENV TOKENIZERS_PARALLELISM=false
 
 
25
 
26
  # Expose the port required by Hugging Face Spaces
27
  EXPOSE 7860
 
14
  # Install Python dependencies
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
+ # Create cache directories with proper permissions
18
+ RUN mkdir -p /.cache && chmod 777 /.cache
19
+ RUN mkdir -p /root/.cache && chmod 777 /root/.cache
20
+ RUN mkdir -p /app/.cache && chmod 777 /app/.cache
21
+
22
+ # Create models directory for Hugging Face
23
+ RUN mkdir -p /app/models && chmod 777 /app/models
24
+ ENV TRANSFORMERS_CACHE=/app/models
25
+
26
  # Copy the rest of the application
27
  COPY . .
28
 
29
+ # Create necessary directories with proper permissions
30
+ RUN mkdir -p data/documents data/vector_db && \
31
+ chmod -R 777 data
32
 
33
  # Set environment variable to avoid TOKENIZERS_PARALLELISM warning
34
  ENV TOKENIZERS_PARALLELISM=false
35
+ ENV HF_HOME=/app/.cache
36
+ ENV XDG_CACHE_HOME=/app/.cache
37
 
38
  # Expose the port required by Hugging Face Spaces
39
  EXPOSE 7860
app/core/llm.py CHANGED
@@ -28,9 +28,20 @@ def get_llm():
28
 
29
  def get_embeddings():
30
  """Initialize and return the embeddings model."""
 
 
 
 
 
 
 
 
 
 
31
  # SentenceTransformers can be used locally without an API key
32
  return HuggingFaceEmbeddings(
33
- model_name=EMBEDDING_MODEL
 
34
  )
35
 
36
  def get_chat_model():
 
28
 
29
  def get_embeddings():
30
  """Initialize and return the embeddings model."""
31
+ # Set up cache directories with proper permissions
32
+ cache_dir = "/app/models"
33
+ if not os.path.exists(cache_dir):
34
+ try:
35
+ os.makedirs(cache_dir, exist_ok=True)
36
+ os.chmod(cache_dir, 0o777)
37
+ except Exception as e:
38
+ print(f"Warning: Could not create cache directory: {e}")
39
+ cache_dir = None
40
+
41
  # SentenceTransformers can be used locally without an API key
42
  return HuggingFaceEmbeddings(
43
+ model_name=EMBEDDING_MODEL,
44
+ cache_folder=cache_dir
45
  )
46
 
47
  def get_chat_model():