sksameermujahid commited on
Commit
4ebf2b8
·
verified ·
1 Parent(s): 8c3a8de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -10,7 +10,7 @@ import requests
10
  import cloudinary
11
  import cloudinary.uploader
12
  import cloudinary.api
13
- from transformers import AutoTokenizer, AutoModelForCausalLM
14
  import speech_recognition as sr
15
  from pydub import AudioSegment
16
  from happytransformer import HappyTextToText, TTSettings
@@ -187,13 +187,24 @@ retriever = CustomRagRetriever(index, model_embedding)
187
  # Load tokenizer and LLM model
188
  def load_tokenizer_and_model():
189
  print("Loading tokenizer...")
190
- tokenizer = AutoTokenizer.from_pretrained(model_dir)
191
- print("Tokenizer loaded successfully.")
192
-
193
- print("Loading LLM model...")
194
- model_llm = AutoModelForCausalLM.from_pretrained(model_dir).to(device)
195
- print("LLM model loaded successfully.")
196
- return tokenizer, model_llm
 
 
 
 
 
 
 
 
 
 
 
197
 
198
  tokenizer, model_llm = load_tokenizer_and_model()
199
 
 
10
  import cloudinary
11
  import cloudinary.uploader
12
  import cloudinary.api
13
+ from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig
14
  import speech_recognition as sr
15
  from pydub import AudioSegment
16
  from happytransformer import HappyTextToText, TTSettings
 
187
  # Load tokenizer and LLM model
188
  def load_tokenizer_and_model():
189
  print("Loading tokenizer...")
190
+ try:
191
+ tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
192
+ print("Tokenizer loaded successfully.")
193
+
194
+ print("Loading LLM model...")
195
+ model_config = AutoConfig.from_pretrained(model_dir, trust_remote_code=True)
196
+ model_llm = AutoModelForCausalLM.from_pretrained(
197
+ model_dir,
198
+ config=model_config,
199
+ trust_remote_code=True,
200
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
201
+ device_map="auto"
202
+ ).to(device)
203
+ print("LLM model loaded successfully.")
204
+ return tokenizer, model_llm
205
+ except Exception as e:
206
+ print(f"Error loading model: {str(e)}")
207
+ raise
208
 
209
  tokenizer, model_llm = load_tokenizer_and_model()
210