Spaces:
Sleeping

DOROS / app.py
DORINDESTRES's picture
Update app.py
adc9030 verified
Raw History Blame Contribute Delete
987 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Бесплатная модель
model_name = "tiiuae/falcon-7b-instruct"
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()