Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,37 @@ from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
|
27 |
from langchain.chains import MapReduceDocumentsChain, ReduceDocumentsChain
|
28 |
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
class Sum():
|
32 |
def __init__(self, args):
|
|
|
27 |
from langchain.chains import MapReduceDocumentsChain, ReduceDocumentsChain
|
28 |
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
29 |
|
30 |
+
import whisper
|
31 |
+
from ipex_llm import optimize_model
|
32 |
+
|
33 |
+
def has_intersection(t1, t2):
|
34 |
+
if t1[1] < t2[0] or t2[1] < t1[0]:
|
35 |
+
return False
|
36 |
+
else:
|
37 |
+
return True
|
38 |
+
|
39 |
+
class AudioTranslator():
|
40 |
+
def __init__(self, args):
|
41 |
+
self.model = whisper.load_model(args.whisper_version, download_root='checkpoints')
|
42 |
+
self.model = optimize_model(self.model)
|
43 |
+
|
44 |
+
def __call__(self, video_path):
|
45 |
+
"""
|
46 |
+
input: video_path (str)
|
47 |
+
output: audio_results (list)
|
48 |
+
"""
|
49 |
+
print("Extract the audio results.")
|
50 |
+
audio_results = self.model.transcribe(video_path, task = 'translate')["segments"]
|
51 |
+
print("Finished.")
|
52 |
+
return audio_results
|
53 |
+
|
54 |
+
def match(self, audio_results):
|
55 |
+
transcript = ''
|
56 |
+
for res in audio_results:
|
57 |
+
transcript += res['text'] + ' '
|
58 |
+
# if has_intersection((start, end), (res["start"], res["end"])):
|
59 |
+
# transcript += res['text'] + ' '
|
60 |
+
return transcript
|
61 |
|
62 |
class Sum():
|
63 |
def __init__(self, args):
|