vivekvar commited on
Commit
afc2936
1 Parent(s): 7bb4a8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -27
app.py CHANGED
@@ -6,11 +6,6 @@ import librosa
6
  from moviepy.editor import VideoFileClip
7
  import os
8
  import tempfile
9
- import logging
10
-
11
- # Set up logging
12
- logging.basicConfig(level=logging.INFO)
13
- logger = logging.getLogger(__name__)
14
 
15
  # Load Whisper base model and processor
16
  whisper_model_name = "openai/whisper-base"
@@ -20,26 +15,8 @@ whisper_model = WhisperForConditionalGeneration.from_pretrained(whisper_model_na
20
  # Load RAG sequence model and tokenizer
21
  rag_model_name = "facebook/rag-sequence-nq"
22
  rag_tokenizer = RagTokenizer.from_pretrained(rag_model_name)
23
-
24
- # Try to load RagRetriever with trust_remote_code=True
25
- try:
26
- rag_retriever = RagRetriever.from_pretrained(
27
- rag_model_name,
28
- index_name="exact",
29
- use_dummy_dataset=True,
30
- dataset_path=local_dataset_path,
31
- trust_remote_code=True
32
- )
33
- logger.info("Successfully loaded RagRetriever with trust_remote_code=True")
34
- except ValueError as e:
35
- logger.error(f"Error loading RagRetriever: {e}")
36
- rag_retriever = None
37
-
38
- if rag_retriever is not None:
39
- rag_model = RagSequenceForGeneration.from_pretrained(rag_model_name, retriever=rag_retriever)
40
- else:
41
- logger.error("RagRetriever is not available, unable to proceed with loading RAG model.")
42
- st.error("RagRetriever is not available, unable to proceed with loading RAG model.")
43
 
44
  def transcribe_audio(audio_path, language="ru"):
45
  speech, rate = librosa.load(audio_path, sr=16000)
@@ -50,8 +27,6 @@ def transcribe_audio(audio_path, language="ru"):
50
  return transcription
51
 
52
  def translate_and_summarize(text):
53
- if rag_retriever is None:
54
- return ["Translation and summarization feature is not available due to RAG retriever loading issue."]
55
  inputs = rag_tokenizer(text, return_tensors="pt")
56
  input_ids = inputs["input_ids"]
57
  attention_mask = inputs["attention_mask"]
 
6
  from moviepy.editor import VideoFileClip
7
  import os
8
  import tempfile
 
 
 
 
 
9
 
10
  # Load Whisper base model and processor
11
  whisper_model_name = "openai/whisper-base"
 
15
  # Load RAG sequence model and tokenizer
16
  rag_model_name = "facebook/rag-sequence-nq"
17
  rag_tokenizer = RagTokenizer.from_pretrained(rag_model_name)
18
+ rag_retriever = RagRetriever.from_pretrained(rag_model_name, index_name="exact", use_dummy_dataset=True, trust_remote_code=True)
19
+ rag_model = RagSequenceForGeneration.from_pretrained(rag_model_name, retriever=rag_retriever)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  def transcribe_audio(audio_path, language="ru"):
22
  speech, rate = librosa.load(audio_path, sr=16000)
 
27
  return transcription
28
 
29
  def translate_and_summarize(text):
 
 
30
  inputs = rag_tokenizer(text, return_tensors="pt")
31
  input_ids = inputs["input_ids"]
32
  attention_mask = inputs["attention_mask"]