gcharanteja commited on
Commit
d9b4eb6
·
1 Parent(s): 29096a2
Files changed (2) hide show
  1. Dockerfile +12 -11
  2. start.sh +10 -19
Dockerfile CHANGED
@@ -1,24 +1,24 @@
1
- FROM python:3.10-slim
2
 
3
- # Install system dependencies
4
  RUN apt-get update && apt-get install -y \
 
 
 
5
  curl \
6
- ca-certificates \
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
- # Install Ollama (more robust way)
10
- RUN curl -fsSL https://ollama.ai/install.sh | sh
11
-
12
- # Create Ollama directory with proper permissions (important for HF)
13
- RUN mkdir -p /root/.ollama && chmod 777 /root/.ollama
14
-
15
  WORKDIR /app
16
 
17
- # Copy requirements first (better caching)
 
 
 
 
18
  COPY requirements.txt .
19
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
20
 
21
- # Copy the rest of the files
22
  COPY . .
23
 
24
  # Make start script executable
@@ -26,4 +26,5 @@ RUN chmod +x start.sh
26
 
27
  EXPOSE 7860
28
 
 
29
  CMD ["./start.sh"]
 
1
+ FROM ollama/ollama:latest
2
 
3
+ # Install Python and dependencies
4
  RUN apt-get update && apt-get install -y \
5
+ python3 \
6
+ python3-pip \
7
+ python3-venv \
8
  curl \
 
9
  && rm -rf /var/lib/apt/lists/*
10
 
 
 
 
 
 
 
11
  WORKDIR /app
12
 
13
+ # Create virtual environment (safer)
14
+ RUN python3 -m venv /opt/venv
15
+ ENV PATH="/opt/venv/bin:$PATH"
16
+
17
+ # Copy requirements and install
18
  COPY requirements.txt .
19
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
20
 
21
+ # Copy app files
22
  COPY . .
23
 
24
  # Make start script executable
 
26
 
27
  EXPOSE 7860
28
 
29
+ # Use our start script
30
  CMD ["./start.sh"]
start.sh CHANGED
@@ -1,38 +1,29 @@
1
  #!/bin/bash
2
 
3
  echo "=== [HF Space] Starting Ollama + FastAPI ==="
4
- echo "Current time: $(date)"
5
 
6
- # Optimization
7
- export OMP_NUM_THREADS=4
8
- export MKL_NUM_THREADS=4
9
- export OLLAMA_HOST=0.0.0.0
10
-
11
- # Start Ollama
12
  echo "Starting Ollama server..."
13
  ollama serve &
14
- OLLAMA_PID=$!
15
 
16
  # Wait for Ollama
17
- echo "Waiting for Ollama to start..."
18
- for i in {1..60}; do
19
- if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
20
- echo "✅ Ollama is ready!"
21
  break
22
  fi
23
  sleep 3
24
- if [ $i -eq 30 ]; then
25
- echo "⚠️ Taking long... still waiting"
26
- fi
27
  done
28
 
29
- # Pull model
30
  if ! ollama list | grep -q "tinyllama"; then
31
- echo "📥 Downloading tinyllama (first build only - this takes time)..."
32
  ollama pull tinyllama
33
  else
34
- echo "✅ Model tinyllama already exists"
35
  fi
36
 
37
- echo "🚀 Starting FastAPI on port ${PORT:-7860}"
38
  uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860} --workers 2
 
1
  #!/bin/bash
2
 
3
  echo "=== [HF Space] Starting Ollama + FastAPI ==="
 
4
 
5
+ # Start Ollama in background (official image already has it)
 
 
 
 
 
6
  echo "Starting Ollama server..."
7
  ollama serve &
8
+ sleep 5
9
 
10
  # Wait for Ollama
11
+ echo "Waiting for Ollama..."
12
+ for i in {1..40}; do
13
+ if curl -s http://127.0.0.1:11434/api/tags >/dev/null; then
14
+ echo "✅ Ollama ready!"
15
  break
16
  fi
17
  sleep 3
 
 
 
18
  done
19
 
20
+ # Pull model (only first time)
21
  if ! ollama list | grep -q "tinyllama"; then
22
+ echo "📥 Pulling tinyllama... (this can take 2-5 mins on first build)"
23
  ollama pull tinyllama
24
  else
25
+ echo "✅ tinyllama already available"
26
  fi
27
 
28
+ echo "🚀 Starting FastAPI..."
29
  uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860} --workers 2