Spaces:
Sleeping
Sleeping
File size: 2,288 Bytes
5dee7eb 57645e8 884ac0c fdefd2f bd826f0 884ac0c fdefd2f 884ac0c fdefd2f 884ac0c fdefd2f 884ac0c fdefd2f 884ac0c fdefd2f 884ac0c fdefd2f 5dee7eb 884ac0c fdefd2f 884ac0c 5dee7eb 884ac0c 5dee7eb 884ac0c fdefd2f 884ac0c fdefd2f 884ac0c 5dee7eb fdefd2f 5dee7eb 884ac0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import os
import gradio as gr
from transformers import pipeline
from datasets import load_dataset
# --- 1. Загрузка датасета клиентских обращений ---
try:
dataset = load_dataset("sberbank-ai/ru_helpdesk", split="train[:100]") # 100 реальных обращений
examples = [d["question"] for d in dataset]
except:
examples = [
"Мой заказ #12345 не пришел",
"Как оформить возврат?",
"Проблема с доступом в личный кабинет"
]
# --- 2. Загрузка локальной модели (не требует API) ---
model = pipeline(
"text-generation",
model="IlyaGusev/saiga_mistral_7b-lora",
device="cpu" # Для GPU укажите device=0
)
# --- 3. Функция генерации ответа ---
def generate_response(message, history):
prompt = f"""Ты оператор поддержки. Ответь клиенту вежливо и по делу.
Диалог:
{history}
Клиент: {message}
Оператор:"""
try:
response = model(
prompt,
max_new_tokens=200,
temperature=0.3,
do_sample=True
)
return response[0]["generated_text"].split("Оператор:")[-1].strip()
except Exception as e:
return f"Ошибка: {str(e)}"
# --- 4. Интерфейс Gradio ---
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("""<h1><center>📞 Поддержка клиентов (Русский)</center></h1>""")
with gr.Row():
with gr.Column():
chatbot = gr.Chatbot(height=350)
msg = gr.Textbox(label="Ваш запрос", placeholder="Опишите проблему...")
gr.Examples(examples, inputs=msg, label="Примеры вопросов")
with gr.Column():
gr.Markdown("**Инструкция:**\n\n1. Укажите номер заказа\n2. Опишите проблему детально\n3. Сохраняйте спокойствие")
gr.Image("https://via.placeholder.com/300x200?text=Support+Logo")
msg.submit(generate_response, [msg, chatbot], [msg, chatbot])
demo.launch()
|