feat: Sentiment model download and upload to vendor (#7526)

This commit is contained in:
Tejaswini Chile
2023-07-18 12:17:50 +05:30
committed by GitHub
parent 3a77e672f8
commit 5b480f563d
3 changed files with 55 additions and 3 deletions

View File

@@ -27,8 +27,11 @@ class Enterprise::SentimentAnalysisJob < ApplicationJob
# Model initializes OnnxRuntime::Model, with given file for inference session and to create the tensor
def model
model_path = ENV.fetch('SENTIMENT_FILE_PATH', nil)
Informers::SentimentAnalysis.new(model_path) if model_path.present?
model = save_and_open_sentiment_file
return if File.empty?(model)
Informers::SentimentAnalysis.new(model)
end
def label_val(sentiment)
@@ -38,4 +41,18 @@ class Enterprise::SentimentAnalysisJob < ApplicationJob
def valid_incoming_message?(message)
!message.incoming? || message.private?
end
# returns the sentiment file from vendor folder else download it to the path from AWS-S3
def save_and_open_sentiment_file
model_path = ENV.fetch('SENTIMENT_FILE_PATH', nil)
sentiment_file = Rails.root.join('vendor/db/sentiment-analysis.onnx')
return sentiment_file if File.exist?(sentiment_file)
source_file = Down.download(model_path) # Download file from AWS-S3
File.rename(source_file, sentiment_file) # Change the file path
sentiment_file
end
end