Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,34 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
model_name = "ai-forever/ruGPT-3.5-13B" # название модели на Hugging Face
|
4 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
5 |
-
model =
|
6 |
|
|
|
|
|
|
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
# Формируем промпт для модели – просто сам вопрос пользователя.
|
13 |
-
input_ids = tokenizer.encode(user_input, return_tensors='pt').to(model.device)
|
14 |
-
output_ids = model.generate(input_ids, max_new_tokens=100, eos_token_id=tokenizer.eos_token_id)
|
15 |
-
answer = tokenizer.decode(output_ids[0][input_ids.shape[-1]:], skip_special_tokens=True)
|
16 |
-
return answer
|
17 |
-
|
18 |
-
# Создаем интерфейс Gradio с текстовым полем ввода и вывода:
|
19 |
-
demo = gr.Interface(fn=answer_question, inputs="text", outputs="text",
|
20 |
-
title="Помощник банка", description="Задайте вопрос об услугах банка")
|
21 |
-
demo.launch()
|
|
|
1 |
+
# banking_prompting_app.py
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
5 |
+
import torch
|
6 |
+
|
7 |
+
# Используем модель Flan-T5 или Sberbank AI
|
8 |
+
model_name = "sberbank-ai/rugpt3small" # Можно заменить на sberbank-ai/rugpt3small или другую
|
9 |
|
|
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
|
13 |
+
def generate_response(user_query):
|
14 |
+
# Промпт можно адаптировать под нужную задачу (обслуживание клиентов / антифрод)
|
15 |
+
prompt = f"Отвечай как банковский ассистент. Вопрос клиента: {user_query}"
|
16 |
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
18 |
+
with torch.no_grad():
|
19 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
20 |
+
|
21 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
22 |
+
return response
|
23 |
+
|
24 |
+
# Интерфейс Gradio
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=generate_response,
|
27 |
+
inputs=gr.Textbox(lines=4, label="Введите банковский запрос клиента"),
|
28 |
+
outputs=gr.Textbox(lines=6, label="Ответ модели"),
|
29 |
+
title="🤖 Помощник по банковским вопросам",
|
30 |
+
description="Эта система использует LLM и технологии промптинга для обслуживания клиентов в банковской сфере."
|
31 |
+
)
|
32 |
|
33 |
+
if __name__ == "__main__":
|
34 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|