Spaces:
Sleeping
Sleeping
text
Browse files
1111.txt
CHANGED
|
@@ -1 +1,27 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openmind import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
from transformers.generation.utils import GenerationConfig
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
def load_model():
|
| 7 |
+
device = 'npu:0'
|
| 8 |
+
model_path = "Baichuan/Baichuan2_7b_chat_pt"
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True).to(device)
|
| 11 |
+
model.generation_config = GenerationConfig.from_pretrained(model_path)
|
| 12 |
+
return model, tokenizer
|
| 13 |
+
|
| 14 |
+
def chat(content, history):
|
| 15 |
+
messages = []
|
| 16 |
+
messages.append({"role": "user", "content": content})
|
| 17 |
+
response = model.chat(tokenizer, messages)
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
model, tokenizer = load_model()
|
| 22 |
+
gr.ChatInterface(chat,
|
| 23 |
+
title="Baichuan2_7B 对话",
|
| 24 |
+
description="Baichuan 2 是百川智能推出的新一代开源大语言模型,采�?2.6 万亿 Tokens 的高质量语料训练,欢迎体验baichuan2_chat_7B模型�?,
|
| 25 |
+
examples=['解释一下“温故而知�?, '请制定一份杭州一日游计划']
|
| 26 |
+
).queue().launch(debug=True) 1
|
| 27 |
+
1111
|