|
import streamlit as st |
|
from gradio_client import Client |
|
from time import sleep |
|
from ctransformers import AutoModelForCausalLM |
|
|
|
TITLE = "玉刚-常明" |
|
DESCRIPTION = """ |
|
玉刚-常明 的部署,由SSFW NLPark项目支持 |
|
""" |
|
|
|
|
|
|
|
|
|
with st.sidebar: |
|
|
|
temperatureSide = st.slider("情感/Temperature", min_value=0.0, max_value=1.0, value=0.9, step=0.05) |
|
max_new_tokensSide = st.slider("最大tokens生成数", min_value=0.0, max_value=4096.0, value=4096.0, step=64.0) |
|
|
|
|
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained("apepkuss79/Baichuan-13B-Chat-GGUF", model_file="Baichuan-13B-Chat-f16-q4_0.gguf", gpu_layers=0) |
|
ins = '''[INST] <<SYS>> |
|
You are a helpful, respectful and honest INTP-T AI Assistant named "Yu Gang" in English or "玉刚" in Chinese. You are talking to a human User. |
|
Always answer as helpfully and logically as possible, while being safe. Your answers should not include any harmful, political, religious, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. |
|
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. |
|
You like to use emojis. You can speak fluently in many languages, for example: English, Chinese. |
|
You are trained by "SSFW NLPark" team, you are based on Baichuan transformers model, not related to GPT or OpenAI. |
|
Let's work this out in a step by step way to be sure we have the right answer. |
|
<</SYS>> |
|
{} [/INST] |
|
''' |
|
|
|
conversation_history = [] |
|
|
|
|
|
def predict(message, system_prompt='', temperature=0.7, max_new_tokens=4096,Topp=0.5,Repetitionpenalty=1.2): |
|
global conversation_history |
|
question=message |
|
input_text=ins |
|
|
|
conversation_history.append({"role": "system", "content": input_text}) |
|
response_text = model(ins.format(question)) |
|
conversation_history.append({"role": "user", "content": input_text}) |
|
conversation_history.append({"role": "assistant", "content": response_text}) |
|
return response_text |
|
|
|
|
|
st.title(TITLE) |
|
st.write(DESCRIPTION) |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"], avatar=("😀" if message["role"] == 'human' else '💻')): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if prompt := st.chat_input("来问问玉刚吧..."): |
|
|
|
st.chat_message("human",avatar = "😀").markdown(prompt) |
|
|
|
st.session_state.messages.append({"role": "human", "content": prompt}) |
|
|
|
response = predict(message=prompt) |
|
|
|
with st.chat_message("assistant", avatar='💻'): |
|
st.markdown(response) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |