-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (34 loc) · 1.36 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
import whisper # noqa: D100
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_ollama import OllamaLLM
import config
def transcribe_audio(audio_file: str) -> str:
"""Transcribe the audio file using Whisper ASR model.
Args:
audio_file (str): Path to the audio file.
Returns:
str: The transcribed text.
"""
print("Loading Whisper ASR model...")
model = whisper.load_model("base")
print("Transcribing audio...")
result = model.transcribe(audio_file)
return result["text"]
if __name__ == "__main__":
audio_file = config.AUDIO_FILEPATH
transcript = transcribe_audio(audio_file)
print("\nTranscript:\n", transcript)
llm = OllamaLLM(model=config.LLM_MODEL)
SUMMARIZER_TEMPLATE = """
You have to summarize and extract action points of the following transcript:
{transcript}
Some background information:
{background_info}
"""
prompt = ChatPromptTemplate.from_template(SUMMARIZER_TEMPLATE)
summary_chain = prompt | llm | StrOutputParser()
background_info = config.BACKGROUND_INFO
print("Elaborating the transcript...")
result = summary_chain.invoke({"transcript": transcript, "background_info": background_info})
print(f"AI BOT reply:\n {result}")