Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -55,10 +55,14 @@ model = BertModel.from_pretrained('bert-base-uncased').to(device)
|
|
55 |
|
56 |
# Function to embed the question using BERT
|
57 |
def embed_question(question, model, tokenizer):
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Function to retrieve the relevant document and generate a response
|
64 |
@spaces.GPU(duration=120)
|
|
|
55 |
|
56 |
# Function to embed the question using BERT
|
57 |
def embed_question(question, model, tokenizer):
|
58 |
+
try:
|
59 |
+
inputs = tokenizer(question, return_tensors='pt').to(device)
|
60 |
+
with torch.no_grad():
|
61 |
+
outputs = model(**inputs)
|
62 |
+
return outputs.last_hidden_state.mean(dim=1).cpu().numpy().astype(np.float32)
|
63 |
+
except Exception as e:
|
64 |
+
logging.error(f"Error embedding question: {e}")
|
65 |
+
raise
|
66 |
|
67 |
# Function to retrieve the relevant document and generate a response
|
68 |
@spaces.GPU(duration=120)
|