-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscript_processor.py
41 lines (27 loc) · 1.12 KB
/
transcript_processor.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
import sys
from langchain.chains import LLMChain, StuffDocumentsChain
from langchain_community.document_loaders import YoutubeLoader
from langchain_core.prompts import PromptTemplate
from model_helper import ModelHelper
class TranscriptProcessor:
def __init__(self, model):
self.model = model
def process(self, input):
system_prompt = "please summarize "
prompt_template = system_prompt + "{text}"
prompt = PromptTemplate.from_template(prompt_template)
llm_chain = LLMChain(llm=self.model, prompt=prompt)
chain = StuffDocumentsChain(llm_chain=llm_chain, input_key="text")
loader = YoutubeLoader.from_youtube_url(
input,
add_video_info=True,
language=["en", "en-US", "zh", "zh-Hans", "zh-Hant", "zh-TW"],
translation="en",
)
youtube_transcript = loader.load()
return chain.invoke(youtube_transcript)
if __name__ == "__main__":
input = sys.argv[1]
processor = TranscriptProcessor(ModelHelper.get_model("llama3.1"))
response = processor.process(input)
print(response["output_text"])