Sai809701 commited on
Commit
ee1d54c
·
2 Parent(s): 7b3d05b d9d9f74

Merge branch 'main' of https://huggingface.co/spaces/Sp2503/Muril-Model

Browse files
Files changed (2) hide show
  1. Dockerfile +28 -26
  2. requirements.txt +5 -1
Dockerfile CHANGED
@@ -1,36 +1,38 @@
1
- # Use official Python image
2
  FROM python:3.10-slim
3
 
 
 
 
 
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
- # Copy requirements and install dependencies
8
  COPY requirements.txt .
9
 
10
- # Upgrade pip and install pinned dependencies
11
- RUN pip install --no-cache-dir --upgrade pip \
12
- && pip install --no-cache-dir -r requirements.txt
 
13
 
14
- # Copy all code and model files
15
  COPY . .
16
 
17
- # Set Transformers cache to a writable folder
18
- ENV TRANSFORMERS_CACHE=/tmp/hf_cache
19
-
20
- # Expose FastAPI port
21
- EXPOSE 7860
22
-
23
- # Precompute embeddings at build time (optional: adjust if dataset is large)
24
- RUN python -c "\
25
- import os, torch, pandas as pd;\
26
- from sentence_transformers import SentenceTransformer;\
27
- model = SentenceTransformer('./muril_combined_multilingual_model');\
28
- df = pd.read_csv('./muril_multilingual_dataset.csv').dropna(subset=['question','answer']);\
29
- answers = df['answer'].tolist();\
30
- embeddings = model.encode(answers, convert_to_tensor=True);\
31
- torch.save(embeddings, './answer_embeddings.pt');\
32
- print('✅ Precomputed embeddings saved');\
33
- "
34
-
35
- # Run FastAPI with uvicorn
36
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "]()
 
1
+ # Use a lightweight Python base image
2
  FROM python:3.10-slim
3
 
4
+ # Disable CUDA since we're using CPU-only
5
+ ENV TORCH_DISABLE_CUDA=1
6
+ ENV TRANSFORMERS_CACHE=/app/hf_cache
7
+ ENV HF_HOME=/app/hf_cache
8
+
9
  # Set working directory
10
  WORKDIR /app
11
 
12
+ # Copy dependency list
13
  COPY requirements.txt .
14
 
15
+ # Install dependencies efficiently
16
+ RUN apt-get update && apt-get install -y git && \
17
+ pip install --no-cache-dir -r requirements.txt && \
18
+ rm -rf /var/lib/apt/lists/*
19
 
20
+ # Copy application code
21
  COPY . .
22
 
23
+ # Make cache folder writable
24
+ RUN mkdir -p /app/hf_cache && chmod -R 777 /app/hf_cache
25
+
26
+ # Expose port
27
+ EXPOSE 8080
28
+
29
+ # Preload model embeddings (optional)
30
+ # Commented out to speed up Cloud Build — will load at runtime in main.py
31
+ # RUN python -c "import torch, pandas as pd; from sentence_transformers import SentenceTransformer; \
32
+ # model = SentenceTransformer('./muril_combined_multilingual_model'); \
33
+ # df = pd.read_csv('./muril_multilingual_dataset.csv').dropna(subset=['question','answer']); \
34
+ # embeddings = model.encode(df['answer'].tolist(), convert_to_tensor=True); \
35
+ # torch.save(embeddings, './answer_embeddings.pt'); print('✅ Precomputed embeddings saved');"
36
+
37
+ # Run the FastAPI app with uvicorn
38
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
 
 
 
 
requirements.txt CHANGED
@@ -1,6 +1,9 @@
 
1
  fastapi==0.118.0
2
  uvicorn==0.37.0
3
- torch==2.1.0
 
 
4
  sentence-transformers==2.2.2
5
  transformers==4.33.2
6
  huggingface-hub==0.16.4
@@ -10,3 +13,4 @@ langdetect==1.0.9
10
  requests==2.31.0
11
  tqdm==4.65.0
12
  PyMuPDF==1.23.0
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cpu
2
  fastapi==0.118.0
3
  uvicorn==0.37.0
4
+ torch==2.1.0+cpu
5
+ torchvision==0.16.0+cpu
6
+ torchaudio==2.1.0+cpu
7
  sentence-transformers==2.2.2
8
  transformers==4.33.2
9
  huggingface-hub==0.16.4
 
13
  requests==2.31.0
14
  tqdm==4.65.0
15
  PyMuPDF==1.23.0
16
+