File size: 2,389 Bytes
5f773d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import moviepy.editor as mp
import json
from datetime import datetime, timedelta
from src.aws.resonate_aws_functions import resonate_aws_transcribe
import os

from src.pinecone.resonate_pinecone_functions import PineconeServerless
import time
import uuid
import pandas as pd


def convert_video_to_audio(video_path, audio_path):
    # Convert video file to audio file
    audio_clip = mp.VideoFileClip(video_path).audio
    audio_clip.write_audiofile(audio_path)


def transcript_text_editor_minutes_to_hhmmss(minutes):
    time_delta = timedelta(minutes=minutes)
    hhmmss_format = str(time_delta)
    return hhmmss_format


def load_json_config(json_file_path="./config/config.json"):
    # Use a context manager to ensure the file is properly closed after opening
    with open(json_file_path, "r") as file:
        # Load the JSON data
        data = json.load(file)
    return data


def aws_transcribe(file_name):

    json_config = load_json_config()
    current_timestamp = str.lower(datetime.now().strftime("%Y-%b-%d-%I-%M-%p"))

    json_config["AWS_INPUT_BUCKET"] += f"{str(current_timestamp)}"
    json_config["AWS_OUTPUT_BUCKET"] += f"{str(current_timestamp)}"
    json_config["AWS_TRANSCRIBE_JOB_NAME"] += f"{str(current_timestamp)}"

    print(json_config)

    try:
        rat = resonate_aws_transcribe()
        df = rat.runner(
            file_name=file_name,
            input_bucket=json_config["AWS_INPUT_BUCKET"],
            output_bucket=json_config["AWS_OUTPUT_BUCKET"],
            transcribe_job_name=json_config["AWS_TRANSCRIBE_JOB_NAME"],
            aws_access_key=os.getenv("AWS_ACCESS_KEY"),
            aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
            aws_region_name=json_config["AWS_REGION"],
        )

        return df
    except Exception as e:
        return e


def pinecone_init_upsert(
    df_transcript: pd.DataFrame,
    meeting_title: str,
    meeting_summary: str,
    meeting_uuid: str,
):
    try:

        pinecone = PineconeServerless()
        pinecone.pinecone_upsert(
            df_transcript,
            # meeting_uuid=NULL,
            meeting_uuid=meeting_uuid,
            meeting_video_file=False,
            meeting_title=meeting_title,
            meeting_summary=meeting_summary,
        )
        time.sleep(5)
    except Exception as e:
        print("Error upserting transcript to Pinecone: ", e)