Update app.py
Browse files
app.py
CHANGED
@@ -196,13 +196,20 @@ def create_context(dataframe, filters):
|
|
196 |
|
197 |
|
198 |
# Функция для получения ответа от модели
|
199 |
-
def get_model_response(question, context):
|
200 |
inputs = tokenizer.encode_plus(question, context, return_tensors="pt", max_length=512, truncation=True)
|
201 |
outputs = model(**inputs)
|
202 |
answer_start = torch.argmax(outputs.start_logits)
|
203 |
answer_end = torch.argmax(outputs.end_logits) + 1
|
|
|
|
|
|
|
|
|
|
|
204 |
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(inputs["input_ids"][0][answer_start:answer_end]))
|
205 |
-
return answer
|
|
|
|
|
206 |
|
207 |
|
208 |
# Главная функция для Gradio
|
|
|
196 |
|
197 |
|
198 |
# Функция для получения ответа от модели
|
199 |
+
def get_model_response(question, context=""):
|
200 |
inputs = tokenizer.encode_plus(question, context, return_tensors="pt", max_length=512, truncation=True)
|
201 |
outputs = model(**inputs)
|
202 |
answer_start = torch.argmax(outputs.start_logits)
|
203 |
answer_end = torch.argmax(outputs.end_logits) + 1
|
204 |
+
|
205 |
+
# Если модель не нашла ответа, возвращаем сообщение об ошибке
|
206 |
+
if answer_start >= answer_end:
|
207 |
+
return "Не удалось найти подходящий объект."
|
208 |
+
|
209 |
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(inputs["input_ids"][0][answer_start:answer_end]))
|
210 |
+
return answer.strip() if answer.strip() != "[CLS]" else "Не найдено."
|
211 |
+
|
212 |
+
|
213 |
|
214 |
|
215 |
# Главная функция для Gradio
|