Skip to content

Commit

Permalink
use service account for vertex ai
Browse files Browse the repository at this point in the history
  • Loading branch information
Maleehak committed Apr 17, 2024
1 parent c0f801d commit dc91422
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ RUN apt-get update && apt-get install -y \
RUN wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp && \
chmod a+rx /usr/local/bin/yt-dlp

COPY backend/target/briefme-0.0.1-SNAPSHOT.jar /app/briefme-0.0.1-SNAPSHOT.jar
COPY google-api-credentials.json.enc /app/google-api-credentials.json.enc

RUN openssl enc -d -aes-256-cbc -in /app/google-api-credentials.json.enc -out /app/google-api-credentials.json -pass pass:'It is raining 99'

WORKDIR /app
COPY . /app

COPY backend/target/briefme-0.0.1-SNAPSHOT.jar briefme-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","briefme-0.0.1-SNAPSHOT.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@Slf4j
@Component
public class AudioToTextConverterImpl implements AudioToTextConverter {
public class GoogleAudioToTextConverterImpl implements AudioToTextConverter {

@Value("${google.api.credentials.location}")
private String credentialsPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.example.BriefMe.service.client.TextSummarizer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.ServiceAccountCredentials;
import java.io.FileInputStream;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -21,21 +26,38 @@
@Component
@Slf4j
public class GoogleVertexAiTextSummarizer implements TextSummarizer {
@org.springframework.beans.factory.annotation.Value("${google.api.credentials.location}")
private String credentialsPath;

@Autowired
VertexAIProperties vertexAIProperties;
@Override
public String generateSummary(String text, int numberOfLines) {
try{
String prompt = createPromptString(text, numberOfLines);
String parameters= createParametersString();

// create credentials using google service account json
List<String> scopes = Arrays.asList("https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only");


ServiceAccountCredentials serviceAccountCredentials = (ServiceAccountCredentials) ServiceAccountCredentials
.fromStream(new FileInputStream(credentialsPath))
.createScoped(scopes);

CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(serviceAccountCredentials);


String endpoint = String.format("%s-aiplatform.googleapis.com:443", vertexAIProperties.getLocation());
PredictionServiceSettings predictionServiceSettings =
PredictionServiceSettings.newBuilder()
.setEndpoint(endpoint)
.setCredentialsProvider(credentialsProvider)
.build();

//setup request params
String prompt = createPromptString(text, numberOfLines);
String parameters= createParametersString();

// Initialize client
try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create(predictionServiceSettings)) {
final EndpointName endpointName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Mp4AudioExtractorImpl implements AudioExtractor {
@Override
public String extractAudio(String inputVideoFile) {
try{
FFmpeg ffmpeg = new FFmpeg("/opt/homebrew/bin/ffmpeg");
FFmpeg ffmpeg = new FFmpeg("ffmpeg");
FFprobe ffprobe = new FFprobe();

String outputFile = OUTPUT_FILE + UUID.randomUUID() + DOT + MP_3;
Expand Down

0 comments on commit dc91422

Please sign in to comment.