Spaces:
Runtime error
Runtime error
Commit
·
269a65b
1
Parent(s):
8bbebf1
Update Dockerfile and app.py
Browse files- Dockerfile +1 -1
- app.py +4 -6
Dockerfile
CHANGED
|
@@ -10,7 +10,7 @@ RUN pip3 install --no-cache-dir -r requirements.txt
|
|
| 10 |
|
| 11 |
# === НОВЫЙ БЛОК: Загрузка моделей при сборке ===
|
| 12 |
# Загрузка модели и токенизатора transformers
|
| 13 |
-
RUN python -c "import spacy; spacy.cli.download('
|
| 14 |
RUN python -c "import nltk; nltk.download('punkt_tab', download_dir='/usr/local/share/nltk_data')"
|
| 15 |
RUN python -c "import nltk; nltk.download('stopwords')"
|
| 16 |
|
|
|
|
| 10 |
|
| 11 |
# === НОВЫЙ БЛОК: Загрузка моделей при сборке ===
|
| 12 |
# Загрузка модели и токенизатора transformers
|
| 13 |
+
RUN python -c "import spacy; spacy.cli.download('ru_core_news_sm')"
|
| 14 |
RUN python -c "import nltk; nltk.download('punkt_tab', download_dir='/usr/local/share/nltk_data')"
|
| 15 |
RUN python -c "import nltk; nltk.download('stopwords')"
|
| 16 |
|
app.py
CHANGED
|
@@ -28,7 +28,7 @@ def load_data():
|
|
| 28 |
@st.cache_resource
|
| 29 |
def load_model_and_tokenizer():
|
| 30 |
# Загрузка предобученной модели вопрос-ответа (например, SberQuad)
|
| 31 |
-
model_name = "AlexKay/xlm-roberta-large-qa-multilingual-finedtuned-ru"
|
| 32 |
# замените на нужную модель, например, "bert-base-uncased"
|
| 33 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 34 |
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
|
@@ -44,7 +44,7 @@ def build_vectorizer(_df):
|
|
| 44 |
# === Предобработка текста ===
|
| 45 |
|
| 46 |
# Загрузка Spacy модели
|
| 47 |
-
nlp = spacy.load('ru_core_news_lg'
|
| 48 |
stop_words = set(stopwords.words('russian'))
|
| 49 |
|
| 50 |
cache_dict = {}
|
|
@@ -85,8 +85,6 @@ def preprocess_text(text):
|
|
| 85 |
return ' '.join(tokens)
|
| 86 |
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
# === Основная функция получения ответа ===
|
| 91 |
def get_answer_from_qa_model(user_question, df, vectorizer, tfidf_matrix, model, tokenizer):
|
| 92 |
processed = preprocess_text(user_question)
|
|
@@ -96,7 +94,7 @@ def get_answer_from_qa_model(user_question, df, vectorizer, tfidf_matrix, model,
|
|
| 96 |
|
| 97 |
# Проверка, что similarities не пустой
|
| 98 |
if len(similarities) == 0:
|
| 99 |
-
return "
|
| 100 |
|
| 101 |
best_match_idx = similarities.argmax()
|
| 102 |
best_score = similarities[best_match_idx]
|
|
@@ -104,7 +102,7 @@ def get_answer_from_qa_model(user_question, df, vectorizer, tfidf_matrix, model,
|
|
| 104 |
if best_score > 0.1:
|
| 105 |
# Проверка, что индекс не выходит за границы
|
| 106 |
if best_match_idx >= len(df):
|
| 107 |
-
return "
|
| 108 |
|
| 109 |
context = df.iloc[best_match_idx]['answer']
|
| 110 |
question = user_question
|
|
|
|
| 28 |
@st.cache_resource
|
| 29 |
def load_model_and_tokenizer():
|
| 30 |
# Загрузка предобученной модели вопрос-ответа (например, SberQuad)
|
| 31 |
+
model_name = "DeepPavlov/rubert-base-cased-squad2" #"AlexKay/xlm-roberta-large-qa-multilingual-finedtuned-ru"
|
| 32 |
# замените на нужную модель, например, "bert-base-uncased"
|
| 33 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 34 |
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
|
|
|
| 44 |
# === Предобработка текста ===
|
| 45 |
|
| 46 |
# Загрузка Spacy модели
|
| 47 |
+
nlp = spacy.load('ru_core_news_sm') #'ru_core_news_lg'
|
| 48 |
stop_words = set(stopwords.words('russian'))
|
| 49 |
|
| 50 |
cache_dict = {}
|
|
|
|
| 85 |
return ' '.join(tokens)
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
| 88 |
# === Основная функция получения ответа ===
|
| 89 |
def get_answer_from_qa_model(user_question, df, vectorizer, tfidf_matrix, model, tokenizer):
|
| 90 |
processed = preprocess_text(user_question)
|
|
|
|
| 94 |
|
| 95 |
# Проверка, что similarities не пустой
|
| 96 |
if len(similarities) == 0:
|
| 97 |
+
return "Тема не входит в программу этих классов."
|
| 98 |
|
| 99 |
best_match_idx = similarities.argmax()
|
| 100 |
best_score = similarities[best_match_idx]
|
|
|
|
| 102 |
if best_score > 0.1:
|
| 103 |
# Проверка, что индекс не выходит за границы
|
| 104 |
if best_match_idx >= len(df):
|
| 105 |
+
return "Тема не входит в программу этих классов."
|
| 106 |
|
| 107 |
context = df.iloc[best_match_idx]['answer']
|
| 108 |
question = user_question
|