LiamKhoaLe commited on
Commit
20efc7b
·
1 Parent(s): 5bb4004

Ensure cache is writtable

Browse files
Files changed (2) hide show
  1. Dockerfile +14 -13
  2. app.py +3 -0
Dockerfile CHANGED
@@ -1,31 +1,32 @@
1
  FROM python:3.11-slim
2
 
3
- # Set environment variables (may need to change authority)
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
- PYTHONUNBUFFERED=1
 
 
 
6
 
7
- # Create working directory (and authorised token)
8
  WORKDIR /app
9
 
10
- # Add to Dockerfile
11
- ENV TRANSFORMERS_CACHE=/app/model_cache
12
- ENV HF_HOME=/app/.cache/huggingface
13
- ENV SENTENCE_TRANSFORMERS_HOME=/app/.cache/huggingface/sentence-transformers
14
-
15
- # Install SSL root certs and system deps required by pymongo + DNS
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
  ca-certificates curl dnsutils gcc openssl && \
18
  rm -rf /var/lib/apt/lists/*
19
 
20
- # Copy and install dependencies
21
  COPY requirements.txt .
22
  RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
23
 
24
- # Copy source code (app files)
 
 
 
25
  COPY . .
26
 
27
- # Expose the port used by Uvicorn
28
  EXPOSE 7860
29
 
30
- # Run the FastAPI application using Uvicorn
31
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--log-level", "debug"]
 
1
  FROM python:3.11-slim
2
 
3
+ # Set environment variables
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
+ PYTHONUNBUFFERED=1 \
6
+ TRANSFORMERS_CACHE=/app/model_cache \
7
+ HF_HOME=/app/.cache/huggingface \
8
+ SENTENCE_TRANSFORMERS_HOME=/app/.cache/huggingface/sentence-transformers
9
 
10
+ # Create working directory
11
  WORKDIR /app
12
 
13
+ # Install system dependencies
 
 
 
 
 
14
  RUN apt-get update && apt-get install -y --no-install-recommends \
15
  ca-certificates curl dnsutils gcc openssl && \
16
  rm -rf /var/lib/apt/lists/*
17
 
18
+ # Install Python dependencies
19
  COPY requirements.txt .
20
  RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
21
 
22
+ # Create writable model cache directory to avoid permission error
23
+ RUN mkdir -p /app/model_cache /app/.cache/huggingface
24
+
25
+ # Copy app source code
26
  COPY . .
27
 
28
+ # Expose app port
29
  EXPOSE 7860
30
 
31
+ # Run app
32
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--log-level", "debug"]
app.py CHANGED
@@ -115,6 +115,7 @@ check_system_resources()
115
  @app.get("/")
116
  async def root() -> FileResponse:
117
  """Serve the single‑page app."""
 
118
  return FileResponse(Path("statics/index.html"))
119
 
120
 
@@ -136,6 +137,7 @@ async def voice_transcribe(file: UploadFile = File(...)): # noqa: B008
136
  question = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
137
  if not question:
138
  raise ValueError("Empty transcription")
 
139
  # ── 2. LLM answer
140
  prompt = build_prompt(question)
141
  # Gemini Flash 2.5 – tuned for short latency
@@ -145,6 +147,7 @@ async def voice_transcribe(file: UploadFile = File(...)): # noqa: B008
145
  contents=prompt
146
  )
147
  answer = response.text.strip()
 
148
  return JSONResponse(
149
  {
150
  "question": question,
 
115
  @app.get("/")
116
  async def root() -> FileResponse:
117
  """Serve the single‑page app."""
118
+ logger.info("[STATIC] Serving frontend")
119
  return FileResponse(Path("statics/index.html"))
120
 
121
 
 
137
  question = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
138
  if not question:
139
  raise ValueError("Empty transcription")
140
+ logger.info(f"[VOICE] Detected transcribe: {question}")
141
  # ── 2. LLM answer
142
  prompt = build_prompt(question)
143
  # Gemini Flash 2.5 – tuned for short latency
 
147
  contents=prompt
148
  )
149
  answer = response.text.strip()
150
+ logger.info(f"[LLM] Decision answer: {answer}")
151
  return JSONResponse(
152
  {
153
  "question": question,