Spaces:
Sleeping
Sleeping
File size: 2,432 Bytes
57645e8 81433b0 bd826f0 81433b0 fdefd2f 81433b0 e0ba145 81433b0 e0ba145 884ac0c 81433b0 e0ba145 37f0934 884ac0c fdefd2f 37f0934 fdefd2f 5dee7eb 884ac0c e0ba145 884ac0c fdefd2f 37f0934 5dee7eb 37f0934 5dee7eb 81433b0 884ac0c 37f0934 fdefd2f 884ac0c 81433b0 fdefd2f 884ac0c 81433b0 5dee7eb 81433b0 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 62 63 64 |
import gradio as gr
from transformers import pipeline
from datasets import load_dataset
# 1. Загрузка датасета клиентских обращений
try:
# Используем открытый датасет на русском языке
dataset = load_dataset("cursoai/jigsaw-toxic-comments", split="train[:100]")
examples = [d["question"] for d in dataset]
except Exception as e:
print(f"Ошибка загрузки датасета: {e}")
examples = [
"Мой заказ #12345 не прибыл",
"Как вернуть товар?",
"Не приходит код подтверждения",
"Ошибка при оплате картой"
]
# 2. Загрузка облегчённой русскоязычной модели
try:
model = pipeline(
"text-generation",
model="ai-forever/rugpt3small_based_on_gpt2", # Гарантированно рабочая модель
device="cpu"
)
except Exception as e:
raise RuntimeError(f"Ошибка загрузки модели: {str(e)}")
# 3. Функция генерации ответа
def generate_response(message):
prompt = f"""Ты оператор поддержки. Ответь клиенту вежливо.
Клиент: {message}
Оператор:"""
try:
response = model(
prompt,
max_new_tokens=150,
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=300)
msg = gr.Textbox(label="Опишите проблему")
btn = gr.Button("Отправить", variant="primary")
with gr.Column():
gr.Examples(examples, inputs=msg, label="Примеры обращений")
gr.Markdown("**Советы:**\n1. Указывайте номер заказа\n2. Прикладывайте скриншоты")
btn.click(lambda m, c: (m, generate_response(m)), [msg, chatbot], [msg, chatbot])
demo.launch()
|