File size: 3,725 Bytes
8fe64f7
 
 
 
 
 
 
 
 
 
 
 
 
 
fad63af
 
 
 
8fe64f7
 
fad63af
8fe64f7
 
b073205
8fe64f7
 
fad63af
 
8fe64f7
 
fad63af
b073205
8fe64f7
87976b0
 
 
 
 
 
 
43b181d
 
 
ab9ec7c
 
 
87976b0
 
 
43b181d
ab9ec7c
87976b0
b073205
 
 
fad63af
6e20c4b
8fe64f7
 
 
fad63af
 
8fe64f7
 
fad63af
 
8fe64f7
ce51475
 
 
8fe64f7
fad63af
8fe64f7
 
fad63af
ab9ec7c
 
 
 
 
 
 
 
8fe64f7
 
 
fad63af
8fe64f7
 
 
fad63af
8fe64f7
 
ce51475
 
 
 
8fe64f7
 
fad63af
8fe64f7
 
2226010
8fe64f7
 
fad63af
8fe64f7
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import streamlit as st

from dotenv import load_dotenv
from engines import get_engine

import api

# Load environment variables from .env file before importing any other modules
load_dotenv()


def main():
    st.set_page_config(
        page_title='Note Taker',
        page_icon='๐ŸŽ™๏ธ',
        layout='centered',
        initial_sidebar_state='expanded',
    )

    title = '๐ŸŽ™๏ธ Meetings Note Taker ๐ŸŽ™๏ธ'
    st.title(title)
    st.write(
        'Upload an audio file, transcribe it using WhisperX or AssemblyAI, and generate meeting notes using your selected model.'
    )

    openai_api_key = os.environ.get('OPENAI_API_KEY') or st.text_input(
        'Enter your OpenAI API key:', type='password'
    )

    engine_type = os.environ.get('TRANSCRIPTION_ENGINE') or st.selectbox(
        'Select a transcription engine:', ['WhisperX', 'AssemblyAI']
    )
    if engine_type == 'WhisperX':
        device = os.environ.get('PYTORCH_DEVICE') or st.selectbox(
            'Select a PyTorch device:', ['cuda', 'cpu']
        )
        compute_type = os.environ.get('PYTORCH_COMPUTE_TYPE') or st.selectbox(
            'Select a compute type:', ['int8', 'float16']
        )
        batch_size = os.environ.get('PYTORCH_BATCH_SIZE') or st.selectbox(
            'Select a batch size:', [4, 8, 16, 32, 64]
        )
        whisper_model = os.environ.get('WHISPER_MODEL') or st.selectbox(
            'Select a Whisper model:', ['large-v2', 'base']
        )
    else:
        device = None
        compute_type = None
        batch_size = None
        whisper_model = None

    engine_api_key = os.environ.get(
        f'{engine_type.upper()}_API_KEY'
    ) or st.text_input(f'Enter your {engine_type} API key:', type='password')
    openai_model = os.environ.get('OPENAI_MODEL') or st.selectbox(
        'Select a model:', ['gpt-3.5-turbo-16k', 'gpt-4-0613']
    )

    uploaded_audio = st.file_uploader(
        'Upload an audio file',
        type=['aac', 'm4a', 'mp3', 'webm', 'mp4', 'mpga', 'wav', 'mpeg'],
        accept_multiple_files=False,
    )
    language = os.environ.get('AUDIO_LANGUAGE') or st.selectbox(
        'Language code of the audio:', ['en', 'es']
    )
    prompt = os.environ.get('SUMMARIZE_PROMPT') or st.text_area(
        'Enter a custom prompt for the summary:', 'Summarize the following audio transcription with a list of the key points with the speakers in the original language'
    )

    if st.button('Generate Notes'):
        if uploaded_audio:
            if openai_api_key:
                st.markdown('Transcribing the audio...')
                engine = get_engine(
                    engine_type,
                    api_key=engine_api_key,
                    device=device,
                    compute_type=compute_type,
                    batch_size=batch_size,
                    whisper_model=whisper_model,
                )
                transcription = api.transcribe(engine, language, uploaded_audio)

                st.markdown(
                    f'###  Transcription:\n\n<details><summary>Click to view</summary><p><pre><code>{transcription}</code></pre></p></details>',
                    unsafe_allow_html=True,
                )

                st.markdown('Summarizing the transcription...')

                summary = api.summarize_transcript(
                    openai_api_key=openai_api_key,
                    transcript=transcription,
                    openai_model=openai_model,
                    prompt=prompt,
                )

                st.markdown(f'### Summary:')
                st.write(summary)
            else:
                st.error('We need valid OpenAI API keys')


if __name__ == '__main__':
    main()