Spaces:
Running
Running
Commit
·
2df21ee
1
Parent(s):
3f15927
feat: add hf token secret accessor
Browse files
.github/workflows/ci-production.yml
CHANGED
@@ -4,6 +4,9 @@ on:
|
|
4 |
push:
|
5 |
branches:
|
6 |
- production
|
|
|
|
|
|
|
7 |
|
8 |
jobs:
|
9 |
setup-build-publish-deploy:
|
@@ -26,7 +29,7 @@ jobs:
|
|
26 |
gcloud auth configure-docker ${{ secrets.GCP_REPO_REGION }}-docker.pkg.dev --quiet
|
27 |
|
28 |
- name: Build image
|
29 |
-
working-directory: ./
|
30 |
run: docker build . --file Dockerfile --tag ${{ secrets.GCP_REPO_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/interview-ai-detector/model-prediction
|
31 |
|
32 |
- name: Push image
|
@@ -61,4 +64,5 @@ jobs:
|
|
61 |
--model=${{ env.MODEL_ID }} \
|
62 |
--display-name=interview-ai-detector-deployment \
|
63 |
--machine-type="n1-standard-4" \
|
64 |
-
--accelerator=count=1,type=nvidia-tesla-t4
|
|
|
|
4 |
push:
|
5 |
branches:
|
6 |
- production
|
7 |
+
path:
|
8 |
+
- "core-model-prediction/**"
|
9 |
+
- ".github/workflows/**"
|
10 |
|
11 |
jobs:
|
12 |
setup-build-publish-deploy:
|
|
|
29 |
gcloud auth configure-docker ${{ secrets.GCP_REPO_REGION }}-docker.pkg.dev --quiet
|
30 |
|
31 |
- name: Build image
|
32 |
+
working-directory: ./core-model-prediction
|
33 |
run: docker build . --file Dockerfile --tag ${{ secrets.GCP_REPO_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/interview-ai-detector/model-prediction
|
34 |
|
35 |
- name: Push image
|
|
|
64 |
--model=${{ env.MODEL_ID }} \
|
65 |
--display-name=interview-ai-detector-deployment \
|
66 |
--machine-type="n1-standard-4" \
|
67 |
+
--accelerator=count=1,type=nvidia-tesla-t4 \
|
68 |
+
--verbosity="debug"
|
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
.env
|
3 |
+
*.json
|
core-model-prediction/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
__pycache__
|
|
|
|
core-model-prediction/gemma2b_dependencies.py
CHANGED
@@ -4,6 +4,7 @@ from torch.nn.functional import cosine_similarity
|
|
4 |
from collections import Counter
|
5 |
import numpy as np
|
6 |
from device_manager import DeviceManager
|
|
|
7 |
|
8 |
|
9 |
class Gemma2BDependencies:
|
@@ -12,14 +13,21 @@ class Gemma2BDependencies:
|
|
12 |
def __new__(cls):
|
13 |
if cls._instance is None:
|
14 |
cls._instance = super(Gemma2BDependencies, cls).__new__(cls)
|
|
|
15 |
cls._instance.tokenizer = AutoTokenizer.from_pretrained(
|
16 |
-
"google/gemma-2b")
|
17 |
cls._instance.model = AutoModelForCausalLM.from_pretrained(
|
18 |
-
"google/gemma-2b")
|
19 |
cls._instance.device = DeviceManager()
|
20 |
cls._instance.model.to(cls._instance.device)
|
21 |
return cls._instance
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def calculate_perplexity(self, text: str):
|
24 |
inputs = self.tokenizer(text, return_tensors="pt",
|
25 |
truncation=True, max_length=1024)
|
|
|
4 |
from collections import Counter
|
5 |
import numpy as np
|
6 |
from device_manager import DeviceManager
|
7 |
+
from google.cloud import secretmanager
|
8 |
|
9 |
|
10 |
class Gemma2BDependencies:
|
|
|
13 |
def __new__(cls):
|
14 |
if cls._instance is None:
|
15 |
cls._instance = super(Gemma2BDependencies, cls).__new__(cls)
|
16 |
+
token = cls._instance.access_hf_token_secret()
|
17 |
cls._instance.tokenizer = AutoTokenizer.from_pretrained(
|
18 |
+
"google/gemma-2b", token=token)
|
19 |
cls._instance.model = AutoModelForCausalLM.from_pretrained(
|
20 |
+
"google/gemma-2b", token=token)
|
21 |
cls._instance.device = DeviceManager()
|
22 |
cls._instance.model.to(cls._instance.device)
|
23 |
return cls._instance
|
24 |
|
25 |
+
def access_hf_token_secret(self):
|
26 |
+
client = secretmanager.SecretManagerServiceClient()
|
27 |
+
name = "projects/steady-climate-416810/secrets/HF_TOKEN/versions/1"
|
28 |
+
response = client.access_secret_version(request={"name": name})
|
29 |
+
return response.payload.data.decode('UTF-8')
|
30 |
+
|
31 |
def calculate_perplexity(self, text: str):
|
32 |
inputs = self.tokenizer(text, return_tensors="pt",
|
33 |
truncation=True, max_length=1024)
|
core-model-prediction/prediction.py
CHANGED
@@ -4,8 +4,6 @@ from hypothesis import BaseModelHypothesis
|
|
4 |
from random_forest_dependencies import RandomForestDependencies
|
5 |
from random_forest_model import RandomForestModel
|
6 |
from main_model import PredictMainModel
|
7 |
-
import torch.nn as nn
|
8 |
-
import torch
|
9 |
import numpy as np
|
10 |
from typing import List
|
11 |
|
|
|
4 |
from random_forest_dependencies import RandomForestDependencies
|
5 |
from random_forest_model import RandomForestModel
|
6 |
from main_model import PredictMainModel
|
|
|
|
|
7 |
import numpy as np
|
8 |
from typing import List
|
9 |
|
core-model-prediction/requirements.txt
CHANGED
@@ -6,4 +6,5 @@ textstat
|
|
6 |
scikit-learn==1.4.1.post1
|
7 |
transformers
|
8 |
fastapi
|
9 |
-
uvicorn
|
|
|
|
6 |
scikit-learn==1.4.1.post1
|
7 |
transformers
|
8 |
fastapi
|
9 |
+
uvicorn
|
10 |
+
google-cloud-secret-manager
|