1NEYRON1 commited on
Commit
c4aa0f7
·
1 Parent(s): e786d48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -147,17 +147,22 @@ id_to_cat = {0: 'Performance',
147
  137: 'Artificial Intelligence'}
148
 
149
  # Загружаем модель (замените на вашу модель, если нужно)
150
- model_name = 'checkpoint'
151
- try:
152
  tokenizer = AutoTokenizer.from_pretrained('distilbert-base-cased')
153
  model = AutoModelForSequenceClassification.from_pretrained(
154
- model_name,
155
  num_labels=len(id_to_cat),
156
  problem_type="multi_label_classification"
157
  )
 
 
 
 
 
158
  except OSError as e:
159
  st.error(f"Ошибка загрузки модели: {e}. Убедитесь, что модель доступна или укажите другую.")
160
- st.stop() # Остановка выполнения приложения при ошибке
161
 
162
 
163
  def classify_text(title, description):
 
147
  137: 'Artificial Intelligence'}
148
 
149
  # Загружаем модель (замените на вашу модель, если нужно)
150
+ @st.cache_resource
151
+ def load_model():
152
  tokenizer = AutoTokenizer.from_pretrained('distilbert-base-cased')
153
  model = AutoModelForSequenceClassification.from_pretrained(
154
+ 'checkpoint',
155
  num_labels=len(id_to_cat),
156
  problem_type="multi_label_classification"
157
  )
158
+ return model, tokenizer
159
+
160
+ # Load model/tokenizer once and cache it
161
+ try:
162
+ model, tokenizer = load_model()
163
  except OSError as e:
164
  st.error(f"Ошибка загрузки модели: {e}. Убедитесь, что модель доступна или укажите другую.")
165
+ st.stop()
166
 
167
 
168
  def classify_text(title, description):