-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (42 loc) · 1.61 KB
/
main.py
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
### Setup
import os
import logging
from service_utils import *
from app_utils import *
## Load env variables , to be adjusted
load_config_from_yaml("config.yaml")
### $$$ Local imports
import importlib
import service_utils
importlib.reload(service_utils)
from service_utils import *
import app_utils
importlib.reload(app_utils)
from app_utils import *
## Initialize logging
logging.basicConfig(filename='log.log', level=logging.INFO,
format='%(asctime)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
### Set parameters
YOUTUBE_URL = "https://www.youtube.com/watch?v=3j_daNHio4o"
## Data
DATA_FOLDER = 'data'
AUDIO_FOLDER = os.path.join(DATA_FOLDER, "audio")
TEXT_FOLDER = os.path.join(DATA_FOLDER, "text")
## Audio-to-text
AUDIO_TO_TEXT_MODEL_FOLDER = os.environ.get("AUDIO_TO_TEXT_MODEL_FOLDER")
AUDIO_TO_TEXT_MODEL_NAME = os.environ.get("AUDIO_TO_TEXT_MODEL_NAME")
AUDIO_TO_TEXT_MODEL_PATH = os.path.join(AUDIO_TO_TEXT_MODEL_FOLDER, AUDIO_TO_TEXT_MODEL_NAME)
### Download youtube audio
VIDEO_NAME, AUDIO_FILE_PATH = download_youtube_audio(YOUTUBE_URL, AUDIO_FOLDER)
print(f"{VIDEO_NAME} audio size is : {os.path.getsize(AUDIO_FILE_PATH)} bytes.")
### Get audio text transcript
TEXT_FILE_PATH = os.path.join(TEXT_FOLDER, VIDEO_NAME + '.txt')
text = get_audio_text(AUDIO_FILE_PATH, AUDIO_TO_TEXT_MODEL_PATH)
free_gpu_memory()
save_text(TEXT_FILE_PATH, text)
print(f"{VIDEO_NAME} text size is : {os.path.getsize(TEXT_FILE_PATH)} bytes.")
### Retrieve info
text = read_text(TEXT_FILE_PATH)
prompt = generate_prompt(text)
info = get_info(prompt, model = "gpt-4-1106-preview")
display_info(info, VIDEO_NAME)