Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|