tuxedocat commited on
Commit
918d142
1 Parent(s): 248afb0

Use new auth lib

Browse files
Files changed (2) hide show
  1. Dockerfile +5 -16
  2. app.py +3 -19
Dockerfile CHANGED
@@ -1,27 +1,16 @@
1
- FROM google/cloud-sdk:slim AS retriever
2
- # Get service account key from HF Spaces' secrets
3
- # https://huggingface.co/docs/hub/spaces-sdks-docker#buildtime
4
- RUN --mount=type=secret,id=BUILD_CREDENTIALS,mode=0444,required=true \
5
- --mount=type=secret,id=BUILD_ASSET_BUCKET,mode=0444,required=true \
6
- --mount=type=secret,id=BUILD_ASSET_NAME,mode=0444,required=true \
7
- cat /run/secrets/BUILD_CREDENTIALS > /tmp/creds.json && \
8
- /bin/gcloud auth activate-service-account --key-file=/tmp/creds.json > /dev/null 2>&1 && \
9
- GOOGLE_APPLICATION_CREDENTIALS=/tmp/creds.json /bin/gcloud storage cp gs://$(cat /run/secrets/BUILD_ASSET_BUCKET)/$(cat /run/secrets/BUILD_ASSET_NAME) /tmp/ > /dev/null 2>&1 && \
10
- rm /tmp/creds.json
11
-
12
  FROM python:3.11-slim AS gradio
13
  RUN useradd -m -u 1000 app
14
  USER app
15
  ENV HOME=/home/app \
16
- PATH=/home/app/.local/bin:$PATH
17
  WORKDIR ${HOME}
18
- COPY --from=retriever /tmp/*_linux_amd64.tar.gz ${HOME}/
19
- RUN tar -xf *_linux_amd64.tar.gz && rm *_linux_amd64.tar.gz
20
-
21
  COPY . .
 
 
 
22
  RUN pip install --no-cache-dir -r requirements.txt
23
  RUN --mount=type=secret,id=LLM_CREDENTIALS,mode=0444,required=true \
24
- cat /run/secrets/LLM_CREDENTIALS > ${HOME}/credentials.json
25
  EXPOSE 7860
26
 
27
  ENV GRADIO_SERVER_NAME="0.0.0.0"
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.11-slim AS gradio
2
  RUN useradd -m -u 1000 app
3
  USER app
4
  ENV HOME=/home/app \
5
+ PATH=/home/app/.local/bin:$PATH
6
  WORKDIR ${HOME}
 
 
 
7
  COPY . .
8
+ # https://huggingface.co/docs/hub/spaces-sdks-docker#buildtime
9
+ RUN --mount=type=secret,id=EXTRA_INDEX_URL,mode=0444,required=true \
10
+ pip install --no-cache-dir --extra-index-url=$(cat /run/secrets/EXTRA_INDEX_URL) cycloud-sdk-python-auth > /dev/null 2>&1
11
  RUN pip install --no-cache-dir -r requirements.txt
12
  RUN --mount=type=secret,id=LLM_CREDENTIALS,mode=0444,required=true \
13
+ cat /run/secrets/LLM_CREDENTIALS > ${HOME}/credentials.json
14
  EXPOSE 7860
15
 
16
  ENV GRADIO_SERVER_NAME="0.0.0.0"
app.py CHANGED
@@ -4,6 +4,7 @@ import httpx
4
  import subprocess
5
  import os
6
  from openai import OpenAI
 
7
 
8
  from const import (
9
  LLM_BASE_URL,
@@ -19,27 +20,10 @@ from const import (
19
  )
20
 
21
 
22
- def get_token() -> str:
23
- try:
24
- t = (
25
- subprocess.run(
26
- AUTH_CMD,
27
- stdout=subprocess.PIPE,
28
- stderr=subprocess.DEVNULL,
29
- env=os.environ.copy(),
30
- )
31
- .stdout.decode("utf-8")
32
- .strip()
33
- )
34
- assert t, "Failed to get auth token"
35
- return t
36
- except Exception:
37
- raise ValueError("Failed to get auth token")
38
-
39
-
40
  def get_headers(host: str) -> dict:
 
41
  return {
42
- "Authorization": f"Bearer {get_token()}",
43
  "Host": host,
44
  "Accept": "application/json",
45
  "Content-Type": "application/json",
 
4
  import subprocess
5
  import os
6
  from openai import OpenAI
7
+ from cycloud.auth import load_default_credentials
8
 
9
  from const import (
10
  LLM_BASE_URL,
 
20
  )
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def get_headers(host: str) -> dict:
24
+ creds = load_default_credentials()
25
  return {
26
+ "Authorization": f"Bearer {creds.access_token}",
27
  "Host": host,
28
  "Accept": "application/json",
29
  "Content-Type": "application/json",