Skip to content

Commit

Permalink
containerize backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Maleehak committed Apr 17, 2024
1 parent dc91422 commit f977d6e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM openjdk:17-jdk-slim

ARG GOOGLE_FILE_PASSWORD

RUN apt-get update && apt-get install -y \
python3 \
wget \
Expand All @@ -13,7 +15,7 @@ RUN wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /us
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'
RUN openssl enc -d -aes-256-cbc -in /app/google-api-credentials.json.enc -out /app/google-api-credentials.json -pbkdf2 -k "${GOOGLE_FILE_PASSWORD}"

WORKDIR /app

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.ServiceAccountCredentials;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,19 +37,10 @@ public class GoogleVertexAiTextSummarizer implements TextSummarizer {
public String generateSummary(String text, int numberOfLines) {
try{

// 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);

CredentialsProvider credentialsProvider = createCredentials();

String endpoint = String.format("%s-aiplatform.googleapis.com:443", vertexAIProperties.getLocation());

PredictionServiceSettings predictionServiceSettings =
PredictionServiceSettings.newBuilder()
.setEndpoint(endpoint)
Expand Down Expand Up @@ -88,10 +81,26 @@ public String generateSummary(String text, int numberOfLines) {

}

private CredentialsProvider createCredentials() {
try{
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);

return FixedCredentialsProvider.create(serviceAccountCredentials);

} catch (IOException e) {
throw new RuntimeException(e);
}

}

private String createPromptString(String text, int numberOfLines){
try{
String prompt = "Provide a short summary in "+ numberOfLines +" numeric bullet points:" + text;
log.info("Prompt: {}", prompt);
VertexAIData vertexAIData = new VertexAIData(prompt);
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(vertexAIData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class YoutubeVideoToTextConverterImpl implements VideoToTextConverter {
public static final String OUTPUT_FILE = "output-";
public static final String DOT = ".";

public static final String MP_4 = "mp4";
public static final String WEB_M = "webm";
public static final String SUBTITLES_FORMAT = "json3";

@Override
Expand All @@ -33,7 +33,7 @@ public String fetchSubtitlesJsonFileFromVideo(String inputVideo) {

try {
String[] command = {
"/opt/homebrew/bin/yt-dlp",
"yt-dlp",
"--skip-download",
"--write-subs",
"--write-auto-subs",
Expand Down Expand Up @@ -68,11 +68,11 @@ public String fetchSubtitlesJsonFileFromVideo(String inputVideo) {
log.error("Failed to download subtitles.");
}

return outputFile + MP_4 + DOT + subtitlesLanguage + DOT + SUBTITLES_FORMAT;
return outputFile + WEB_M + DOT + subtitlesLanguage + DOT + SUBTITLES_FORMAT;
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return outputFile + MP_4 + DOT + subtitlesLanguage + DOT + SUBTITLES_FORMAT;
return outputFile + WEB_M + DOT + subtitlesLanguage + DOT + SUBTITLES_FORMAT;
}

@Override
Expand Down
Binary file added google-api-credentials.json.enc
Binary file not shown.

0 comments on commit f977d6e

Please sign in to comment.