SimrusDenuvo commited on
Commit
a4bd38b
·
verified ·
1 Parent(s): e66857b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -6,10 +6,22 @@ from transformers import pipeline
6
  from kaggle.api.kaggle_api_extended import KaggleApi
7
 
8
  # === Подготовка банковского набора данных через Kaggle ===
9
- # Будет скачан dataset PromptCloudHQ/banking-chatbot-dataset, содержащий примеры вопросов и ответов для банковского чат-бота.
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  DATA_DIR = './data'
11
  json_file = None
12
- # Скачиваем при первом запуске
13
  if not os.path.exists(DATA_DIR):
14
  os.makedirs(DATA_DIR)
15
  api = KaggleApi()
@@ -21,7 +33,6 @@ if not os.path.exists(DATA_DIR):
21
  json_file = os.path.join(DATA_DIR, fname)
22
  break
23
  else:
24
- # Если папка есть — ищем файл
25
  for fname in os.listdir(DATA_DIR):
26
  if fname.endswith('.json'):
27
  json_file = os.path.join(DATA_DIR, fname)
@@ -30,22 +41,6 @@ else:
30
  if json_file is None:
31
  raise FileNotFoundError('Не удалось найти JSON-файл с банковскими данными в ./data')
32
 
33
- # Загружаем JSON с примерами
34
- with open(json_file, 'r', encoding='utf-8') as f:
35
- kb = json.load(f)
36
- # Структура: {"intents": [ ... ]}
37
- intents = kb.get('intents')
38
- if intents is None:
39
- raise ValueError('Ожидался ключ "intents" в JSON-файле датасета')
40
-
41
- # Собираем два few-shot примера
42
- examples = []
43
- for intent in intents[:2]:
44
- patterns = intent.get('patterns', [])
45
- responses = intent.get('responses', [])
46
- ex = f"Паттерны: {', '.join(patterns)}\nОтветы: {', '.join(responses)}"
47
- examples.append(ex)
48
-
49
  # === Инициализация трёх бесплатных русскоязычных моделей (GPT-2 based) ===
50
  models = {
51
  'ruDialoGPT-small': pipeline('text-generation', model='t-bank-ai/ruDialoGPT-small', tokenizer='t-bank-ai/ruDialoGPT-small', device=-1),
@@ -108,3 +103,4 @@ with gr.Blocks() as demo:
108
  t3 = gr.Textbox(label='ruGPT3-small Время')
109
  btn.click(format_outputs, inputs=[txt], outputs=[out1, t1, out2, t2, out3, t3])
110
  demo.launch()
 
 
6
  from kaggle.api.kaggle_api_extended import KaggleApi
7
 
8
  # === Подготовка банковского набора данных через Kaggle ===
9
+ # Пишем файл kaggle.json из переменных окружения, чтобы authenticate() нашёл его
10
+ import json
11
+ kaggle_config_dir = os.path.expanduser("~/.config/kaggle")
12
+ os.makedirs(kaggle_config_dir, exist_ok=True)
13
+ kaggle_json = {
14
+ "username": os.getenv("KAGGLE_USERNAME", ""),
15
+ "key": os.getenv("KAGGLE_KEY", "")
16
+ }
17
+ if not kaggle_json["username"] or not kaggle_json["key"]:
18
+ raise ValueError("Не найдены переменные окружения KAGGLE_USERNAME и KAGGLE_KEY")
19
+ with open(os.path.join(kaggle_config_dir, "kaggle.json"), "w") as f:
20
+ json.dump(kaggle_json, f)
21
+
22
+ # Скачиваем при первом запуске
23
  DATA_DIR = './data'
24
  json_file = None
 
25
  if not os.path.exists(DATA_DIR):
26
  os.makedirs(DATA_DIR)
27
  api = KaggleApi()
 
33
  json_file = os.path.join(DATA_DIR, fname)
34
  break
35
  else:
 
36
  for fname in os.listdir(DATA_DIR):
37
  if fname.endswith('.json'):
38
  json_file = os.path.join(DATA_DIR, fname)
 
41
  if json_file is None:
42
  raise FileNotFoundError('Не удалось найти JSON-файл с банковскими данными в ./data')
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # === Инициализация трёх бесплатных русскоязычных моделей (GPT-2 based) ===
45
  models = {
46
  'ruDialoGPT-small': pipeline('text-generation', model='t-bank-ai/ruDialoGPT-small', tokenizer='t-bank-ai/ruDialoGPT-small', device=-1),
 
103
  t3 = gr.Textbox(label='ruGPT3-small Время')
104
  btn.click(format_outputs, inputs=[txt], outputs=[out1, t1, out2, t2, out3, t3])
105
  demo.launch()
106
+