Spaces:
Runtime error

File size: 960 Bytes
8757cbd
c3c8940
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_name = "mistralai/Mistral-7B-Instruct-v0.2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")

def chat_with_doros(user_message, chat_history=[]):
    prompt = f"Ты зовёшься DOROS. Ты менеджер сайта DOROShop. Пользователь сказал: {user_message}"
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    output = model.generate(**inputs, max_new_tokens=200)
    bot_message = tokenizer.decode(output[0], skip_special_tokens=True)
    chat_history.append((user_message, bot_message))
    return chat_history, chat_history

with gr.Blocks() as demo:
    chat = gr.Chatbot()
    msg = gr.Textbox(label="Сообщение")
    msg.submit(chat_with_doros, [msg, chat], [chat, chat])

demo.launch()